From 8591e35c4ff7e157a1dde3473a0a997676a8b36e Mon Sep 17 00:00:00 2001 From: h4570 Date: Fri, 29 Jul 2022 23:04:31 +0200 Subject: [PATCH] add game template --- ROADMAP.txt | 4 - template/.clang-format | 40 +++++++ template/.dockerignore | 5 + template/.gitattributes | 2 + template/.gitignore | 32 ++++++ template/.vscode/.gitignore | 6 + .../windows-docker/c_cpp_properties.json | 41 +++++++ .../windows-docker/settings.json | 14 +++ .../configurations/windows-docker/tasks.json | 105 ++++++++++++++++++ template/.vscode/extensions.json | 7 ++ template/Dockerfile | 8 ++ template/Makefile | 33 ++++++ template/bin/.gitignore | 4 + template/docker-compose.yml | 16 +++ template/inc/racer_game.hpp | 20 ++++ template/obj/.gitignore | 4 + template/res/.gitignore | 4 + template/run.ps1 | 4 + template/src/main.cpp | 10 ++ template/src/racer_game.cpp | 14 +++ template/windows-pcsx2.ps1 | 12 ++ 21 files changed, 381 insertions(+), 4 deletions(-) create mode 100644 template/.clang-format create mode 100644 template/.dockerignore create mode 100644 template/.gitattributes create mode 100644 template/.gitignore create mode 100644 template/.vscode/.gitignore create mode 100644 template/.vscode/configurations/windows-docker/c_cpp_properties.json create mode 100644 template/.vscode/configurations/windows-docker/settings.json create mode 100644 template/.vscode/configurations/windows-docker/tasks.json create mode 100644 template/.vscode/extensions.json create mode 100644 template/Dockerfile create mode 100644 template/Makefile create mode 100644 template/bin/.gitignore create mode 100644 template/docker-compose.yml create mode 100644 template/inc/racer_game.hpp create mode 100644 template/obj/.gitignore create mode 100644 template/res/.gitignore create mode 100644 template/run.ps1 create mode 100644 template/src/main.cpp create mode 100644 template/src/racer_game.cpp create mode 100644 template/windows-pcsx2.ps1 diff --git a/ROADMAP.txt b/ROADMAP.txt index 49d2153..6894f84 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,8 +1,4 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ - -- [Loaders] DFF loader as static Mesh loader -- [Game] Standalone game template, update intellisense from docker - - [General] Control generated id to avoid duplication. Maybe Just increment from 0? Add interface IIdentificable? - [DMA] Check if all chain transfers have end tag! - [General] Change libs of sample? (remove -lpng, -lz...), probably they are not required diff --git a/template/.clang-format b/template/.clang-format new file mode 100644 index 0000000..ce4cc1b --- /dev/null +++ b/template/.clang-format @@ -0,0 +1,40 @@ +# Use the Google style in this project. +BasedOnStyle: Google + +# Some folks prefer to write "int& foo" while others prefer "int &foo". The +# Google Style Guide only asks for consistency within a project, we chose +# "int& foo" for this project: +DerivePointerAlignment: false +PointerAlignment: Left + +SortIncludes: false + +IncludeBlocks: Merge +IncludeCategories: +# Matches common headers first, but sorts them after project includes +- Regex: '^\"google/cloud/internal/disable_deprecation_warnings.inc\"$' + Priority: -1 +- Regex: '^\"google/cloud/(internal/|grpc_utils/|testing_util/|[^/]+\.h)' + Priority: 1000 +- Regex: '^\"google/cloud/' # project includes should sort first + Priority: 500 +- Regex: '^\"' + Priority: 1500 +- Regex: '^' + Priority: 5000 + +# Format raw string literals with a `pb` or `proto` tag as proto. +RawStringFormats: +- Language: TextProto + Delimiters: + - 'pb' + - 'proto' + BasedOnStyle: Google + +CommentPragmas: '(@copydoc)' \ No newline at end of file diff --git a/template/.dockerignore b/template/.dockerignore new file mode 100644 index 0000000..b63d312 --- /dev/null +++ b/template/.dockerignore @@ -0,0 +1,5 @@ +*.elf +.git/ +.vscode/ +docs/ +tools/ \ No newline at end of file diff --git a/template/.gitattributes b/template/.gitattributes new file mode 100644 index 0000000..9103071 --- /dev/null +++ b/template/.gitattributes @@ -0,0 +1,2 @@ +# Ignore all differences in line endings +* -crlf \ No newline at end of file diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..e5fc9f7 --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,32 @@ +# --- + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.vsm + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +*.erl +*.elf diff --git a/template/.vscode/.gitignore b/template/.vscode/.gitignore new file mode 100644 index 0000000..dae89fb --- /dev/null +++ b/template/.vscode/.gitignore @@ -0,0 +1,6 @@ +*.log + +# Configuration files +/c_cpp_properties.json +/tasks.json +/settings.json diff --git a/template/.vscode/configurations/windows-docker/c_cpp_properties.json b/template/.vscode/configurations/windows-docker/c_cpp_properties.json new file mode 100644 index 0000000..492701d --- /dev/null +++ b/template/.vscode/configurations/windows-docker/c_cpp_properties.json @@ -0,0 +1,41 @@ +{ + "configurations": [ + { + "name": "Docker PS2SDK", + "includePath": [ + "${workspaceFolder}/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/tyra/inc/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ps2sdk/common/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ps2sdk/ee/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ps2sdk/iop/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ps2sdk/ports/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/lib/gcc/mips64r5900el-ps2-elf/11.3.0/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/lib/gcc/mips64r5900el-ps2-elf/11.3.0/include-fixed/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/lib/gcc/mips64r5900el-ps2-elf/11.3.0/install-tools/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/lib/gcc/mips64r5900el-ps2-elf/11.3.0/plugin/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/mips64r5900el-ps2-elf/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/ee/mips64r5900el-ps2-elf/sys-include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/gsKit/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-elf/11.3.0/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-elf/11.3.0/install-tools/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-elf/11.3.0/plugin/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-elf/11.3.0/include-fixed/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-irx/11.3.0/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-irx/11.3.0/install-tools/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-irx/11.3.0/plugin/include/**", + "C:/Users/YOUR-INTELLISENSE-PATH/ps2dev-intellisense/iop/lib/gcc/mipsel-ps2-irx/11.3.0/include-fixed/**" + ], + "defines": [ + "_EE", + "_IOP", + "INTELLISENSE" + ], + "cppStandard": "c++20", + "compilerPath": "", // Should be empty + "intelliSenseMode": "linux-gcc-x86", + "configurationProvider": "ms-vscode.cpptools" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/template/.vscode/configurations/windows-docker/settings.json b/template/.vscode/configurations/windows-docker/settings.json new file mode 100644 index 0000000..f5f4d52 --- /dev/null +++ b/template/.vscode/configurations/windows-docker/settings.json @@ -0,0 +1,14 @@ +{ + "buildDirectory": "./", + "C_Cpp.default.intelliSenseMode": "gcc-x86", + "files.associations": { + "*.vcl": "asm-collection", + "*.i": "asm-collection", + "*.vsm": "asm-collection", + "*.vclpp": "asm-collection", + "*.hpp": "cpp", + "*.cpp": "cpp", + "*.h": "c", + "*.c": "c" + } +} \ No newline at end of file diff --git a/template/.vscode/configurations/windows-docker/tasks.json b/template/.vscode/configurations/windows-docker/tasks.json new file mode 100644 index 0000000..96fa5aa --- /dev/null +++ b/template/.vscode/configurations/windows-docker/tasks.json @@ -0,0 +1,105 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build & run", + "dependsOrder": "sequence", + "dependsOn": [ + "1. Copy source code to docker volume", + "2. Compile via docker container", + "3. Copy binaries to host", + "4. Run PCSX2" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "1. Copy source code to docker volume", + "command": "docker exec -t tyra-game-compiler sh -c 'rsync -ac --delete --exclude \".git\" --exclude \".vscode\" --exclude \"*obj*/**\" --exclude \"*bin*/**\" /host/ /src/'" + }, + { + "type": "shell", + "label": "2. Compile via docker container", + "command": "docker exec -t tyra-game-compiler sh -c 'cd ${config:buildDirectory} && make'", + "problemMatcher": { + "base": "$gcc", + "fileLocation": [ + "autoDetect" + ] + } + }, + { + "type": "shell", + "label": "3. Copy binaries to host", + "command": "docker exec -t tyra-game-compiler sh -c 'rsync -zac --include=\"*/\" --include=\"*bin*/**\" --exclude=\"*\" /src/ /host/'", + }, + { + "type": "shell", + "label": "4. Run PCSX2", + "options": { + "cwd": "${config:buildDirectory}" + }, + "command": "./run.ps1" + }, + { + "type": "shell", + "label": "Cleanup", + "command": "docker exec -t tyra-game-compiler sh -c 'rm -rf /src/*'" + }, + { + "type": "shell", + "label": "Update Tyra", + "command": "docker exec -t tyra-game-compiler sh -c 'rm -rf /tyra && mkdir -p /tyra && git clone https://github.com/h4570/tyra.git /tyra && cd /tyra && git checkout ${input:tyraBranch} && cd engine && make'" + }, + { + "type": "shell", + "label": "Send to PS2", + "command": "docker exec -t tyra-game-compiler sh -c 'cd ${config:buildDirectory}/bin && killall -v ps2client || true && ps2client -h ${input:ps2Ip} reset && ps2client -h ${input:ps2Ip} reset && ps2client -h ${input:ps2Ip} execee host:$(find . -maxdepth 1 -type f -name \"*.elf\")'" + }, + { + "type": "shell", + "label": "Open PS2 output logger", + "command": "docker stop ps2-logs || $true && docker run -t --rm --name=ps2-logs -p ${input:local2Ip}:18194:18194/udp h4570/tyra sh -c 'ps2client -h ${input:ps2Ip} listen'", + "runOptions": { + "instanceLimit": 1 + }, + "presentation": { + "reveal": "always", + "panel": "new" + } + }, + { + "type": "shell", + "label": "Start docker container", + "command": "docker compose up -d" + }, + { + "type": "shell", + "label": "Stop docker container", + "command": "docker compose down" + } + ], + "inputs": [ + { + "id": "ps2Ip", + "description": "PS2link ip address:", + "default": "192.168.1.200", + "type": "promptString" + }, + { + "id": "local2Ip", + "description": "Local ip address:", + "default": "192.168.1.245", + "type": "promptString" + }, + { + "id": "tyraBranch", + "description": "Tyra branch:", + "default": "master", + "type": "promptString" + } + ] +} \ No newline at end of file diff --git a/template/.vscode/extensions.json b/template/.vscode/extensions.json new file mode 100644 index 0000000..b5b5f82 --- /dev/null +++ b/template/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-vscode.cpptools-extension-pack", + "ryzngard.vscode-header-source", + "maziac.asm-code-lens" + ] +} \ No newline at end of file diff --git a/template/Dockerfile b/template/Dockerfile new file mode 100644 index 0000000..09e5223 --- /dev/null +++ b/template/Dockerfile @@ -0,0 +1,8 @@ +# syntax=docker/dockerfile:1 +FROM h4570/tyra + +RUN apt-get update +RUN apt-get install git -y + +WORKDIR /src +CMD ["/bin/bash"] \ No newline at end of file diff --git a/template/Makefile b/template/Makefile new file mode 100644 index 0000000..24c9a97 --- /dev/null +++ b/template/Makefile @@ -0,0 +1,33 @@ +TARGET := racer.elf +ENGINEDIR := /tyra/engine + +#The Directories, Source, Includes, Objects, Binary and Resources +SRCDIR := src +INCDIR := inc +BUILDDIR := obj +TARGETDIR := bin +RESDIR := res +SRCEXT := cpp +VSMEXT := vsm +VCLEXT := vcl +VCLPPEXT := vclpp +DEPEXT := d +OBJEXT := o + +#Flags, Libraries and Includes +CFLAGS := +LIB := -ltyra +LIBDIRS := -L$(ENGINEDIR)/bin +INC := -I$(INCDIR) -I$(ENGINEDIR)/inc +INCDEP := -I$(INCDIR) -I$(ENGINEDIR)/inc + +include /tyra/Makefile.base + +clean-engine: + cd $(ENGINEDIR) && $(MAKE) cleaner + +build-engine: + cd $(ENGINEDIR) && $(MAKE) + +build-release-engine: + cd $(ENGINEDIR) && $(MAKE) release \ No newline at end of file diff --git a/template/bin/.gitignore b/template/bin/.gitignore new file mode 100644 index 0000000..44c5ea8 --- /dev/null +++ b/template/bin/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/template/docker-compose.yml b/template/docker-compose.yml new file mode 100644 index 0000000..56ce57a --- /dev/null +++ b/template/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.9" +volumes: + tyra-game-volume: +services: + compiler: + environment: + TERM: xterm-256color + network_mode: host + build: + context: ./ + dockerfile: Dockerfile + tty: true + container_name: tyra-game-compiler + volumes: + - tyra-game-volume:/src + - ./:/host diff --git a/template/inc/racer_game.hpp b/template/inc/racer_game.hpp new file mode 100644 index 0000000..a8885aa --- /dev/null +++ b/template/inc/racer_game.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace Racer { + +class RacerGame : public Tyra::Game { + public: + RacerGame(Tyra::Engine* engine); + ~RacerGame(); + + void init(); + void loop(); + + private: + Tyra::Engine* engine; +}; + +} // namespace Racer diff --git a/template/obj/.gitignore b/template/obj/.gitignore new file mode 100644 index 0000000..44c5ea8 --- /dev/null +++ b/template/obj/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/template/res/.gitignore b/template/res/.gitignore new file mode 100644 index 0000000..44c5ea8 --- /dev/null +++ b/template/res/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/template/run.ps1 b/template/run.ps1 new file mode 100644 index 0000000..b2f7754 --- /dev/null +++ b/template/run.ps1 @@ -0,0 +1,4 @@ +$ConfigFile = Join-Path $PSScriptRoot './windows-pcsx2.ps1' +. $ConfigFile + +RunPCSX2 diff --git a/template/src/main.cpp b/template/src/main.cpp new file mode 100644 index 0000000..4563a08 --- /dev/null +++ b/template/src/main.cpp @@ -0,0 +1,10 @@ +#include "engine.hpp" +#include "racer_game.hpp" + +int main() { + Tyra::Engine engine; + Racer::RacerGame game(&engine); + engine.run(&game); + SleepThread(); + return 0; +} diff --git a/template/src/racer_game.cpp b/template/src/racer_game.cpp new file mode 100644 index 0000000..a004e61 --- /dev/null +++ b/template/src/racer_game.cpp @@ -0,0 +1,14 @@ +#include "racer_game.hpp" + +namespace Racer { + +using namespace Tyra; + +RacerGame::RacerGame(Engine* t_engine) { engine = t_engine; } +RacerGame::~RacerGame() {} + +void RacerGame::init() { TYRA_LOG("Hello!"); } + +void RacerGame::loop() { TYRA_LOG("Loop!"); } + +} // namespace Racer diff --git a/template/windows-pcsx2.ps1 b/template/windows-pcsx2.ps1 new file mode 100644 index 0000000..98f87fe --- /dev/null +++ b/template/windows-pcsx2.ps1 @@ -0,0 +1,12 @@ +$PCSX2_PATH = "${Env:ProgramFiles(x86)}/PCSX2" +$PCSX2_EXE = 'pcsx2.exe' + +function GetTargetELFName { + return (Select-String -Path './Makefile' -Pattern "[^ ]*.elf").Matches.Value +} + +function RunPCSX2 { + $PCSX2_EXE_WITHOUT_EXT = (Split-Path $PCSX2_EXE -Leaf).Split('.')[0] + Stop-Process -Name $PCSX2_EXE_WITHOUT_EXT -ErrorAction 'SilentlyContinue' + Start-Process -FilePath "$PCSX2_PATH/$PCSX2_EXE" -ArgumentList "--elf=$PWD/bin/$(GetTargetELFName)" +} \ No newline at end of file