diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..903daa9c --- /dev/null +++ b/.clang-format @@ -0,0 +1,100 @@ +Language: Cpp +ColumnLimit: '80' +ReflowComments: true +AlignAfterOpenBracket: AlwaysBreak +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +EmptyLineBeforeAccessModifier: Always +IndentWrappedFunctionNames: 'false' +AccessModifierOffset: 0 +IndentAccessModifiers: true +BinPackParameters: false +BinPackArguments: false +InsertTrailingCommas: Wrapped +PackConstructorInitializers: CurrentLine +AlwaysBreakTemplateDeclarations: Yes +DerivePointerAlignment: true +LambdaBodyIndentation: Signature +AlignOperands: false +BreakBeforeBraces: Custom + +BraceWrapping: + AfterCaseLabel: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: true + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true + +AlwaysBreakAfterReturnType: None + +TabWidth: '4' +UseTab: Never +IndentPPDirectives: BeforeHash +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: false +AlignArrayOfStructures: 'Left' +Cpp11BracedListStyle: true +PointerAlignment: Right +ReferenceAlignment: Right +SpacesInCStyleCastParentheses: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: 'false' +SpacesInAngles: false +SpacesInParentheses: 'false' +SpacesInSquareBrackets: 'false' +SpacesInContainerLiterals: 'false' +SpaceAfterTemplateKeyword: 'true' +IndentCaseLabels: 'true' +NamespaceIndentation: All +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: None +AllowShortLoopsOnASingleLine: 'false' +AllowShortBlocksOnASingleLine: 'true' +AllowShortCaseLabelsOnASingleLine: 'true' +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 1 +AlignConsecutiveMacros: true +AlignEscapedNewlines: Left +AlignTrailingComments: true +BreakStringLiterals: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +SortIncludes: true +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '<.+>' # System/Standard libs + Priority: 1 + - Regex: '"raylib.h"' # Criterion headers + Priority: 2 + - Regex: '"raylib-cpp.hpp"' # Criterion headers + Priority: 2 + - Regex: '".+"' # Any "my_header.h" + Priority: 3 + +# Sort 'using' declarations +SortUsingDeclarations: true + +BasedOnStyle: LLVM +AlwaysBreakBeforeMultilineStrings: 'true' +ContinuationIndentWidth: '4' +SpaceInEmptyBlock: true +IndentWidth: '4' +PenaltyBreakAssignment: '0' +SpaceBeforeCpp11BracedList: 'true' +SpaceBeforeRangeBasedForLoopColon: 'true' + +# To totally disable format +DisableFormat: 'false' diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..51597535 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,5 @@ +--- +Checks: '-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,portability-*,readability-*,-readability-identifier-length,-modernize-use-trailing-return-type' +WarningsAsErrors: '-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,portability-*,readability-*,-readability-identifier-length,-modernize-use-trailing-return-type' +HeaderFilterRegex: '(src/ECS/)|(src/Client/)|(src/Server/)' +AnalyzeTemporaryDtors: false diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..291b3866 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..62b1129f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# All files are checked into the repo with LF +* text=auto + +# These files are checked out using CRLF locally +*.bat eol=crlf diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..cac7a555 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,4 @@ +contact_links: + - name: Question/s + url: https://github.com/X-R-G-B/R-Bus/discussions/categories/q-a + about: If you have question/s to ask you can find your answer. diff --git a/.github/ISSUE_TEMPLATE/install-failed.yml b/.github/ISSUE_TEMPLATE/install-failed.yml new file mode 100644 index 00000000..ba3c09e9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/install-failed.yml @@ -0,0 +1,28 @@ +name: "Install Failed" +description: "When you can't install or have error when installing" +title: "[FAIL INSTALL] - Title" +labels: [ + "bug" +] +body: + - type: textarea + id: os + attributes: + label: "Operating System" + description: "What operating system do you use" + validations: + required: true + - type: textarea + id: error + attributes: + label: "Errors" + description: "Errors" + validations: + required: true + - type: textarea + id: step + attributes: + label: "Steps" + description: "Steps to reproduce" + validations: + required: true diff --git a/.github/workflows/compil.yml b/.github/workflows/compil.yml new file mode 100644 index 00000000..f56619c8 --- /dev/null +++ b/.github/workflows/compil.yml @@ -0,0 +1,79 @@ +name: Compil + +on: [push, pull_request] + +jobs: + compil-check-job-run: + runs-on: ubuntu-latest + + outputs: + workflows: ${{ steps.filter.outputs.workflows }} + src: ${{ steps.filter.outputs.src }} + cmake: ${{ steps.filter.outputs.cmake }} + combined: ${{ steps.filter.outputs.workflows == 'true' || steps.filter.outputs.src == 'true' || steps.filter.outputs.cmake == 'true' }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check modified files need re run + id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + workflows: + - '.github/workflows/**' + src: + - 'src/**' + cmake: + - 'CMakeLists.txt' + + windows-compil: + runs-on: windows-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined || github.event_name == 'pull_request' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install winget + uses: Cyberboss/install-winget@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: ./scripts/install-deps-windows.ps1 + + - name: Compil + run: ./scripts/compil.ps1 --dry-run + + linux-compil: + runs-on: ubuntu-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined || github.event_name == 'pull_request' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo ./scripts/install-deps-linux.sh + + - name: Compil + run: ./scripts/compil.sh --dry-run + + macos-compil: + runs-on: macos-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined || github.event_name == 'pull_request' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: ./scripts/install-deps-macos.sh + + - name: Compil + run: ./scripts/compil.sh --dry-run diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 00000000..b4f463d3 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,55 @@ +name: Documentation +on: [push] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + contents: write # To push a branch + pages: write # To push to a GitHub Pages site + id-token: write # To update the deployment status + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check modified files need re run + id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + docs: + - 'docs/**' + docs2: + - 'book.toml' + + - name: Install latest mdbook + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || github.ref == 'refs/heads/main' + run: | + tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') + url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" + mkdir mdbook + curl -sSL $url | tar -xz --directory=./mdbook + echo `pwd`/mdbook >> $GITHUB_PATH + + - name: Build Book + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || github.ref == 'refs/heads/main' + run: mdbook build + + - name: Setup Pages + if: github.ref == 'refs/heads/main' + uses: actions/configure-pages@v3 + + - name: Upload artifact + if: github.ref == 'refs/heads/main' + uses: actions/upload-pages-artifact@v2 + with: + # Upload entire repository + path: 'book' + + - name: Deploy to GitHub Pages + if: github.ref == 'refs/heads/main' + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..53cbc384 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,74 @@ +name: Format + +on: [push, pull_request] + +jobs: + # windows-format: + # runs-on: windows-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # + # - name: Install winget + # uses: Cyberboss/install-winget@v1 + # with: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: Install dependencies + # run: ./scripts/install-deps-windows.ps1 + # + # - name: Format + # run: ./scripts/format.ps1 --dry-run + # + # linux-format: + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # + # - name: Install dependencies + # run: sudo ./scripts/install-deps-linux.sh + # + # - name: Format + # run: ./scripts/format.sh --dry-run + # + # macos-format: + # runs-on: macos-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # + # - name: Install dependencies + # run: ./scripts/install-deps-macos.sh + # + # - name: Format + # run: ./scripts/format.sh --dry-run + + auto-format: + runs-on: ubuntu-latest + if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Install dependencies + run: sudo ./scripts/install-deps-linux.sh + + - name: Format + run: ./scripts/format.sh + + - name: Check for modified files + id: git-check + run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT + + - name: Push changes + if: steps.git-check.outputs.modified == 'true' + run: | + git config --global user.name 'Github Actions' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" + git commit -am "FORMAT-AUTO: automatic format on pull request #${{ github.event.number }}" + git push diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index c5ece6a6..8b1b0bf6 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -1,6 +1,6 @@ name: Publish -on: [push, pull_request] +on: [push] env: MIRROR_URL: git@github.com:EpitechPromo2026/B-CPP-500-TLS-5-1-rtype-xavier.mitault.git diff --git a/.github/workflows/release.sh b/.github/workflows/release.sh index 29847301..587497e0 100644 --- a/.github/workflows/release.sh +++ b/.github/workflows/release.sh @@ -1,8 +1,9 @@ #!/bin/bash # Release script run in Github CI +BRANCH="$1" -LAST_TAG=$(git describe --tags --abbrev=0) +LAST_TAG=$(git tag | sort -t '.' --numeric-sort -k1,1 -k2,2 -k3,3 | tail -n 1) LAST_TAG_MAJOR=$(echo "$LAST_TAG" | cut -d'.' -f1) LAST_TAG_MINOR=$(echo "$LAST_TAG" | cut -d'.' -f2) LAST_TAG_PATCH=$(echo "$LAST_TAG" | cut -d'.' -f3) @@ -39,6 +40,6 @@ TAG="$TAG_MAJOR.$TAG_MINOR.$TAG_PATCH" gh release create "$TAG" \ --title "v$TAG" \ --generate-notes \ - --target main + --target "$BRANCH" echo "release_tag=$TAG" >> $GITHUB_OUTPUT diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 596eae53..12f6a2ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,11 @@ name: Release on: push: - branches: [main] + branches: [main, dev] + +env: + BRANCH: "main" + RAYLIB_TAG: "4.5.0" jobs: release-create: @@ -24,77 +28,125 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - export GITHUB_OUTPUT=$GITHUB_OUTPUT - bash ./.github/workflows/release.sh - - build-windows: + if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then + export GITHUB_OUTPUT=$GITHUB_OUTPUT + bash ./.github/workflows/release.sh "${{ env.BRANCH }}" + else + echo "release_tag=0.0.0" >> $GITHUB_OUTPUT + fi + + release-windows: runs-on: windows-latest - needs: release-create + needs: [release-create, raylib-to-tar] steps: - name: Checkout uses: actions/checkout@v4 + - name: Install winget + uses: Cyberboss/install-winget@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: ./scripts/install-deps-windows.ps1 + - name: Build - run: | - echo "RType server" > ./r-type_server.exe - echo "RType client" > ./r-type_client.exe + run: ./scripts/bundle-windows.ps1 - name: Upload To Release + if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} ./r-type_server.exe - gh release upload ${{ needs.release-create.outputs.release }} ./r-type_client.exe + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-windows.zip + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-windows.exe + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-windows.zip + path: ./r-type-windows.zip + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-windows.exe + path: ./r-type-windows.exe - build-linux: + release-linux: runs-on: ubuntu-latest - needs: release-create + needs: [release-create, raylib-to-tar] steps: - name: Checkout uses: actions/checkout@v4 + - name: Install dependencies + run: sudo ./scripts/install-deps-linux.sh + - name: Build - run: | - echo "RType server" > ./r-type_server - echo "RType client" > ./r-type_client + run: ./scripts/bundle-linux.sh - name: Upload To Release + if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} ./r-type_server - gh release upload ${{ needs.release-create.outputs.release }} ./r-type_client + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-linux.tar.gz + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-linux.sh - asio-to-tar: - runs-on: ubuntu-latest - needs: release-create + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-linux.tar.gz + path: ./r-type-linux.tar.gz + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-linux.sh + path: ./r-type-linux.sh + + release-macos: + runs-on: macos-latest + needs: [release-create, raylib-to-tar] steps: - name: Checkout uses: actions/checkout@v4 - - name: Install deps - run: sudo apt-get update && sudo apt-get install -y tar git + - name: Install dependencies + run: ./scripts/install-deps-macos.sh - - name: Get Asio - run: | - git clone https://github.com/chriskohlhoff/asio.git asio-repo - cd asio-repo || exit 14 - git checkout $(git describe --tags --abbrev=0) - cd .. - - - name: To Tar - run: | - cd asio-repo || exit 14 - tar -cvf ../asio.tar asio + - name: Build + run: ./scripts/bundle-macos.sh - name: Upload To Release + if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release upload ${{ needs.release-create.outputs.release }} ./asio.tar + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-macos.zip + gh release upload ${{ needs.release-create.outputs.release }} ./r-type-macos.dmg + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-macos.dmg + path: ./r-type-macos.dmg + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: r-type-macos.zip + path: ./r-type-macos.zip raylib-to-tar: runs-on: ubuntu-latest @@ -111,15 +163,23 @@ jobs: run: | git clone https://github.com/raysan5/raylib.git raylib-repo cd raylib-repo || exit 14 - git checkout 4.5.0 + git checkout ${{ env.RAYLIB_TAG }} cd .. - - name: Zip To Tar + - name: To Tar run: | tar -cvf raylib.tar raylib-repo - name: Upload To Release + if: github.ref == 'refs/heads/main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release upload ${{ needs.release-create.outputs.release }} ./raylib.tar + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: raylib.tar + path: ./raylib.tar diff --git a/.gitignore b/.gitignore index b2399822..6f20a46f 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,16 @@ cmake_* *.dir/ *.sln x64/ + +.cache/* +r-type_client +r-type_server + +r-type-linux.sh +r-type-linux.tar +r-type-windows.zip +r-type-macos.zip + +*~ + +vgcore* diff --git a/CMakeLists.txt b/CMakeLists.txt index ddd0e7e7..d1b43b6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,103 @@ cmake_minimum_required(VERSION 3.15) -set(PROJECT_NAME client) - set(CMAKE_CXX_STANDARD 20) +set(PROJECT_NAME_CLIENT r-type_client) +set(PROJECT_NAME_SERVER r-type_server) +set(PROJECT_NAME r-type) + if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE) + +option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) +option(WITH_PIC "Build with position independent code" ON) + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") project( ${PROJECT_NAME} VERSION 1.0.0 + DESCRIPTION "r-type" LANGUAGES CXX ) +include(GNUInstallDirs) + +# if(MSVC) +# set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") +# else() +# set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +# set(CMAKE_EXE_LINKER_FLAGS "-static") +# endif() + +# ---------------------------------------------------------------------------- + +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets/" DESTINATION "share/${PROJECT_NAME_CLIENT}") + add_executable( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} +) +add_executable( + ${PROJECT_NAME_SERVER} +) + +install(TARGETS ${PROJECT_NAME_CLIENT} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +install(TARGETS ${PROJECT_NAME_SERVER} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) add_subdirectory(deps) +# Clang-Tidy + +find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + +if(CLANG_TIDY_EXE) + if (MSVC) + set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + else() + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + endif() +endif() + +if(MSVC) + target_compile_options( + ${PROJECT_NAME_CLIENT} + PRIVATE + /W4 + ) +else() + target_compile_options( + ${PROJECT_NAME_CLIENT} + PRIVATE + -Wall -Wextra -pedantic + ) +endif() if(MSVC) target_compile_options( - ${PROJECT_NAME} + ${PROJECT_NAME_SERVER} PRIVATE /W4 ) else() target_compile_options( - ${PROJECT_NAME} + ${PROJECT_NAME_SERVER} PRIVATE -Wall -Wextra -pedantic ) @@ -38,16 +107,117 @@ add_subdirectory(src) if (WIN32) add_custom_command( - TARGET ${PROJECT_NAME} POST_BUILD + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME_CLIENT}.exe + ) + add_custom_command( + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME_CLIENT}.exe" + ) + add_custom_command( + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + "${CMAKE_BINARY_DIR}/Release/${PROJECT_NAME_CLIENT}.exe" + ) +else() + add_custom_command( + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME_CLIENT} + ) + add_custom_command( + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME_CLIENT}" + ) +endif() +if (WIN32) + add_custom_command( + TARGET ${PROJECT_NAME_SERVER} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME_SERVER}.exe + ) + add_custom_command( + TARGET ${PROJECT_NAME_SERVER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - $ - ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.exe + $ + "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME_SERVER}.exe" + ) + add_custom_command( + TARGET ${PROJECT_NAME_CLIENT} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + "${CMAKE_BINARY_DIR}/Release/${PROJECT_NAME_SERVER}.exe" ) else() add_custom_command( - TARGET ${PROJECT_NAME} POST_BUILD + TARGET ${PROJECT_NAME_SERVER} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME_SERVER} + ) + add_custom_command( + TARGET ${PROJECT_NAME_SERVER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - $ - ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} + $ + "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME_SERVER}" ) endif() + +# ---------------------------------------------------------------------------- +# CPACK + +set(CPACK_PACKAGE_VENDOR "X-L-R-G-B") + +include(InstallRequiredSystemLibraries) + +set(CPACK_PACKAGE_NAME "R-Type") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}") +set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") + +# NSIS +set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/favicon.ico") +set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/favicon.ico") +set(CPACK_NSIS_PACKAGE_NAME "R-Type") + +set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +if(NOT WIN32) + set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icons/favicon.bmp") +endif() +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "R-Type") +set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME_CLIENT} ${PROJECT_NAME_SERVER}) +set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME_CLIENT} "RType Client" ${PROJECT_NAME_SERVER} "RType Server") + +list(APPEND CPACK_SOURCE_IGNORE_FILES "/\.git/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/CMakeFiles/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/_CPack_Packages/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/bin(ary)?/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/build/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/dist/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/libs?/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/logs?/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/objs?/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/[tT]e?mp/") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/___pycache__") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/\.cache") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/\.gitignore.*") +list(APPEND CPACK_SOURCE_IGNORE_FILES "/CMakeCache.txt") +list(APPEND CPACK_SOURCE_IGNORE_FILES "\.pyc$") +list(APPEND CPACK_SOURCE_IGNORE_FILES "\.swp$") +list(APPEND CPACK_SOURCE_IGNORE_FILES "~$") + + +include(CPack) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 120000 index 00000000..49d1b98f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +docs/CONTRIBUTING.md \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8a83dee1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 X-L-R-G-B + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..8a83dee1 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 X-L-R-G-B + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 120000 index 00000000..0e01b430 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +docs/README.md \ No newline at end of file diff --git a/assets/Audio/Musics/Title.mp3 b/assets/Audio/Musics/Title.mp3 new file mode 100644 index 00000000..61c3aea6 Binary files /dev/null and b/assets/Audio/Musics/Title.mp3 differ diff --git a/assets/Audio/Sounds/error1.ogg b/assets/Audio/Sounds/error1.ogg new file mode 100644 index 00000000..95562066 Binary files /dev/null and b/assets/Audio/Sounds/error1.ogg differ diff --git a/assets/Audio/Sounds/error2.ogg b/assets/Audio/Sounds/error2.ogg new file mode 100644 index 00000000..c1465386 Binary files /dev/null and b/assets/Audio/Sounds/error2.ogg differ diff --git a/assets/Audio/Sounds/explosion.ogg b/assets/Audio/Sounds/explosion.ogg new file mode 100644 index 00000000..019e5366 Binary files /dev/null and b/assets/Audio/Sounds/explosion.ogg differ diff --git a/assets/Audio/Sounds/fire.ogg b/assets/Audio/Sounds/fire.ogg new file mode 100644 index 00000000..2f7a3fd6 Binary files /dev/null and b/assets/Audio/Sounds/fire.ogg differ diff --git a/assets/Audio/Sounds/forceField.ogg b/assets/Audio/Sounds/forceField.ogg new file mode 100644 index 00000000..6b5cd23d Binary files /dev/null and b/assets/Audio/Sounds/forceField.ogg differ diff --git a/assets/Audio/Sounds/glass.ogg b/assets/Audio/Sounds/glass.ogg new file mode 100644 index 00000000..2b0df026 Binary files /dev/null and b/assets/Audio/Sounds/glass.ogg differ diff --git a/assets/Audio/Sounds/glitch.ogg b/assets/Audio/Sounds/glitch.ogg new file mode 100644 index 00000000..8e4b42d6 Binary files /dev/null and b/assets/Audio/Sounds/glitch.ogg differ diff --git a/assets/Audio/Sounds/impact.ogg b/assets/Audio/Sounds/impact.ogg new file mode 100644 index 00000000..4e2c4f8f Binary files /dev/null and b/assets/Audio/Sounds/impact.ogg differ diff --git a/assets/Audio/Sounds/laser.ogg b/assets/Audio/Sounds/laser.ogg new file mode 100644 index 00000000..e491fb87 Binary files /dev/null and b/assets/Audio/Sounds/laser.ogg differ diff --git a/assets/Audio/Sounds/laser2.ogg b/assets/Audio/Sounds/laser2.ogg new file mode 100644 index 00000000..1fe6edff Binary files /dev/null and b/assets/Audio/Sounds/laser2.ogg differ diff --git a/assets/Audio/Sounds/lowExplosion.ogg b/assets/Audio/Sounds/lowExplosion.ogg new file mode 100644 index 00000000..a59f1786 Binary files /dev/null and b/assets/Audio/Sounds/lowExplosion.ogg differ diff --git a/assets/Audio/Sounds/no.ogg b/assets/Audio/Sounds/no.ogg new file mode 100644 index 00000000..a71bd6fb Binary files /dev/null and b/assets/Audio/Sounds/no.ogg differ diff --git a/assets/Audio/Sounds/question.ogg b/assets/Audio/Sounds/question.ogg new file mode 100644 index 00000000..12697e52 Binary files /dev/null and b/assets/Audio/Sounds/question.ogg differ diff --git a/assets/Audio/Sounds/select.ogg b/assets/Audio/Sounds/select.ogg new file mode 100644 index 00000000..97334e62 Binary files /dev/null and b/assets/Audio/Sounds/select.ogg differ diff --git a/assets/Audio/Sounds/select2.ogg b/assets/Audio/Sounds/select2.ogg new file mode 100644 index 00000000..9d1f5873 Binary files /dev/null and b/assets/Audio/Sounds/select2.ogg differ diff --git a/assets/Audio/Sounds/slime1.ogg b/assets/Audio/Sounds/slime1.ogg new file mode 100644 index 00000000..ede0ce74 Binary files /dev/null and b/assets/Audio/Sounds/slime1.ogg differ diff --git a/assets/Audio/Sounds/slime2.ogg b/assets/Audio/Sounds/slime2.ogg new file mode 100644 index 00000000..c7efa956 Binary files /dev/null and b/assets/Audio/Sounds/slime2.ogg differ diff --git a/assets/Audio/Sounds/spaceEngine.ogg b/assets/Audio/Sounds/spaceEngine.ogg new file mode 100644 index 00000000..2c98998e Binary files /dev/null and b/assets/Audio/Sounds/spaceEngine.ogg differ diff --git a/assets/Audio/Sounds/spaceEngine2.ogg b/assets/Audio/Sounds/spaceEngine2.ogg new file mode 100644 index 00000000..7171fd88 Binary files /dev/null and b/assets/Audio/Sounds/spaceEngine2.ogg differ diff --git a/assets/Audio/Sounds/spaceEngine3.ogg b/assets/Audio/Sounds/spaceEngine3.ogg new file mode 100644 index 00000000..c88c68cb Binary files /dev/null and b/assets/Audio/Sounds/spaceEngine3.ogg differ diff --git a/assets/Audio/Sounds/start.ogg b/assets/Audio/Sounds/start.ogg new file mode 100644 index 00000000..78f119c6 Binary files /dev/null and b/assets/Audio/Sounds/start.ogg differ diff --git a/assets/Audio/Sounds/switch.ogg b/assets/Audio/Sounds/switch.ogg new file mode 100644 index 00000000..856a60d3 Binary files /dev/null and b/assets/Audio/Sounds/switch.ogg differ diff --git a/assets/Audio/Sounds/tick.ogg b/assets/Audio/Sounds/tick.ogg new file mode 100644 index 00000000..e5827a01 Binary files /dev/null and b/assets/Audio/Sounds/tick.ogg differ diff --git a/assets/Audio/Sounds/yes.ogg b/assets/Audio/Sounds/yes.ogg new file mode 100644 index 00000000..562ddb32 Binary files /dev/null and b/assets/Audio/Sounds/yes.ogg differ diff --git a/assets/Fonts/soliden/SolidenTrial-Black.otf b/assets/Fonts/soliden/SolidenTrial-Black.otf new file mode 100644 index 00000000..8e8073b4 Binary files /dev/null and b/assets/Fonts/soliden/SolidenTrial-Black.otf differ diff --git a/assets/R-TypeSheet/r-typesheet1.gif b/assets/R-TypeSheet/r-typesheet1.gif new file mode 100644 index 00000000..78c173a1 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet1.gif differ diff --git a/assets/R-TypeSheet/r-typesheet10.gif b/assets/R-TypeSheet/r-typesheet10.gif new file mode 100644 index 00000000..72dada8b Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet10.gif differ diff --git a/assets/R-TypeSheet/r-typesheet11.gif b/assets/R-TypeSheet/r-typesheet11.gif new file mode 100644 index 00000000..3f323f64 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet11.gif differ diff --git a/assets/R-TypeSheet/r-typesheet12.gif b/assets/R-TypeSheet/r-typesheet12.gif new file mode 100644 index 00000000..05002944 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet12.gif differ diff --git a/assets/R-TypeSheet/r-typesheet13.gif b/assets/R-TypeSheet/r-typesheet13.gif new file mode 100644 index 00000000..f2f8d0bc Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet13.gif differ diff --git a/assets/R-TypeSheet/r-typesheet14.gif b/assets/R-TypeSheet/r-typesheet14.gif new file mode 100644 index 00000000..0ebe1d3a Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet14.gif differ diff --git a/assets/R-TypeSheet/r-typesheet16.gif b/assets/R-TypeSheet/r-typesheet16.gif new file mode 100644 index 00000000..05178f66 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet16.gif differ diff --git a/assets/R-TypeSheet/r-typesheet17.gif b/assets/R-TypeSheet/r-typesheet17.gif new file mode 100644 index 00000000..8394c8d4 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet17.gif differ diff --git a/assets/R-TypeSheet/r-typesheet18.gif b/assets/R-TypeSheet/r-typesheet18.gif new file mode 100644 index 00000000..83934d37 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet18.gif differ diff --git a/assets/R-TypeSheet/r-typesheet19.gif b/assets/R-TypeSheet/r-typesheet19.gif new file mode 100644 index 00000000..e9943e8e Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet19.gif differ diff --git a/assets/R-TypeSheet/r-typesheet2.gif b/assets/R-TypeSheet/r-typesheet2.gif new file mode 100644 index 00000000..1c72b41e Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet2.gif differ diff --git a/assets/R-TypeSheet/r-typesheet20.gif b/assets/R-TypeSheet/r-typesheet20.gif new file mode 100644 index 00000000..32a6e4b2 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet20.gif differ diff --git a/assets/R-TypeSheet/r-typesheet21.gif b/assets/R-TypeSheet/r-typesheet21.gif new file mode 100644 index 00000000..8be267f7 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet21.gif differ diff --git a/assets/R-TypeSheet/r-typesheet22.gif b/assets/R-TypeSheet/r-typesheet22.gif new file mode 100644 index 00000000..73b15dd9 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet22.gif differ diff --git a/assets/R-TypeSheet/r-typesheet23.gif b/assets/R-TypeSheet/r-typesheet23.gif new file mode 100644 index 00000000..61c9468f Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet23.gif differ diff --git a/assets/R-TypeSheet/r-typesheet24.gif b/assets/R-TypeSheet/r-typesheet24.gif new file mode 100644 index 00000000..94beb68c Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet24.gif differ diff --git a/assets/R-TypeSheet/r-typesheet25.gif b/assets/R-TypeSheet/r-typesheet25.gif new file mode 100644 index 00000000..173b940d Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet25.gif differ diff --git a/assets/R-TypeSheet/r-typesheet26.gif b/assets/R-TypeSheet/r-typesheet26.gif new file mode 100644 index 00000000..33bef572 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet26.gif differ diff --git a/assets/R-TypeSheet/r-typesheet27.gif b/assets/R-TypeSheet/r-typesheet27.gif new file mode 100644 index 00000000..2463107b Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet27.gif differ diff --git a/assets/R-TypeSheet/r-typesheet28.gif b/assets/R-TypeSheet/r-typesheet28.gif new file mode 100644 index 00000000..aaa50e28 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet28.gif differ diff --git a/assets/R-TypeSheet/r-typesheet29.gif b/assets/R-TypeSheet/r-typesheet29.gif new file mode 100644 index 00000000..4b2cb6b6 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet29.gif differ diff --git a/assets/R-TypeSheet/r-typesheet3.gif b/assets/R-TypeSheet/r-typesheet3.gif new file mode 100644 index 00000000..778bcde3 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet3.gif differ diff --git a/assets/R-TypeSheet/r-typesheet30.gif b/assets/R-TypeSheet/r-typesheet30.gif new file mode 100644 index 00000000..99ccd2bd Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet30.gif differ diff --git a/assets/R-TypeSheet/r-typesheet30a.gif b/assets/R-TypeSheet/r-typesheet30a.gif new file mode 100644 index 00000000..ee875bab Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet30a.gif differ diff --git a/assets/R-TypeSheet/r-typesheet31.gif b/assets/R-TypeSheet/r-typesheet31.gif new file mode 100644 index 00000000..9f6bd75c Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet31.gif differ diff --git a/assets/R-TypeSheet/r-typesheet32.gif b/assets/R-TypeSheet/r-typesheet32.gif new file mode 100644 index 00000000..60b0ae7f Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet32.gif differ diff --git a/assets/R-TypeSheet/r-typesheet33.gif b/assets/R-TypeSheet/r-typesheet33.gif new file mode 100644 index 00000000..07db51f6 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet33.gif differ diff --git a/assets/R-TypeSheet/r-typesheet34.gif b/assets/R-TypeSheet/r-typesheet34.gif new file mode 100644 index 00000000..c57a9079 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet34.gif differ diff --git a/assets/R-TypeSheet/r-typesheet35.gif b/assets/R-TypeSheet/r-typesheet35.gif new file mode 100644 index 00000000..b424add5 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet35.gif differ diff --git a/assets/R-TypeSheet/r-typesheet36.gif b/assets/R-TypeSheet/r-typesheet36.gif new file mode 100644 index 00000000..224fef63 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet36.gif differ diff --git a/assets/R-TypeSheet/r-typesheet37.gif b/assets/R-TypeSheet/r-typesheet37.gif new file mode 100644 index 00000000..31e56113 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet37.gif differ diff --git a/assets/R-TypeSheet/r-typesheet38.gif b/assets/R-TypeSheet/r-typesheet38.gif new file mode 100644 index 00000000..e219b481 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet38.gif differ diff --git a/assets/R-TypeSheet/r-typesheet39.gif b/assets/R-TypeSheet/r-typesheet39.gif new file mode 100644 index 00000000..5add93d5 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet39.gif differ diff --git a/assets/R-TypeSheet/r-typesheet40.gif b/assets/R-TypeSheet/r-typesheet40.gif new file mode 100644 index 00000000..db98342a Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet40.gif differ diff --git a/assets/R-TypeSheet/r-typesheet41.gif b/assets/R-TypeSheet/r-typesheet41.gif new file mode 100644 index 00000000..86dd4c32 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet41.gif differ diff --git a/assets/R-TypeSheet/r-typesheet42.gif b/assets/R-TypeSheet/r-typesheet42.gif new file mode 100644 index 00000000..258571b1 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet42.gif differ diff --git a/assets/R-TypeSheet/r-typesheet43.gif b/assets/R-TypeSheet/r-typesheet43.gif new file mode 100644 index 00000000..3049560d Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet43.gif differ diff --git a/assets/R-TypeSheet/r-typesheet44.gif b/assets/R-TypeSheet/r-typesheet44.gif new file mode 100644 index 00000000..53b36977 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet44.gif differ diff --git a/assets/R-TypeSheet/r-typesheet5.gif b/assets/R-TypeSheet/r-typesheet5.gif new file mode 100644 index 00000000..4e2ea5c4 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet5.gif differ diff --git a/assets/R-TypeSheet/r-typesheet7.gif b/assets/R-TypeSheet/r-typesheet7.gif new file mode 100644 index 00000000..9d5fa76a Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet7.gif differ diff --git a/assets/R-TypeSheet/r-typesheet8.gif b/assets/R-TypeSheet/r-typesheet8.gif new file mode 100644 index 00000000..2ad7cf6e Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet8.gif differ diff --git a/assets/R-TypeSheet/r-typesheet9.gif b/assets/R-TypeSheet/r-typesheet9.gif new file mode 100644 index 00000000..8bb41c57 Binary files /dev/null and b/assets/R-TypeSheet/r-typesheet9.gif differ diff --git a/assets/icons/favicon.bmp b/assets/icons/favicon.bmp new file mode 100644 index 00000000..7cb6a510 Binary files /dev/null and b/assets/icons/favicon.bmp differ diff --git a/assets/icons/favicon.ico b/assets/icons/favicon.ico new file mode 100644 index 00000000..cdd861e0 Binary files /dev/null and b/assets/icons/favicon.ico differ diff --git a/book.toml b/book.toml new file mode 100644 index 00000000..f7a46709 --- /dev/null +++ b/book.toml @@ -0,0 +1,23 @@ +[book] +title = "R-Bus (RType like game)" +authors = ["@Saverio976", "@TTENSHII", "@guillaumeAbel", "@KitetsuK", "@romainpanno"] +description = "Documentation of R-Bus" +src = "docs" + +[build] +build-dir = "book" +create-missing = false +use-default-preprocessors = true + +[output.html] +git-repository-url = "https://github.com/X-R-G-B/R-Bus" +edit-url-template = "https://github.com/X-R-G-B/R-Bus/edit/dev/{path}" + +[output.html.search] +enable = true +use-boolean-and = true +limit-results = 15 + +[output.html.print] +enable = true +page-break = true diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 512e89fe..cb2a6b9a 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.15) add_subdirectory(raylib) -add_subdirectory(asio) +add_subdirectory(boost) diff --git a/deps/asio/CMakeLists.txt b/deps/asio/CMakeLists.txt deleted file mode 100644 index 8df663eb..00000000 --- a/deps/asio/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -# -- Fetch asio -include(FetchContent) -FetchContent_Declare( - asio - URL "https://github.com/X-R-G-B/R-Bus/releases/latest/download/asio.tar" - DOWNLOAD_EXTRACT_TIMESTAMP TRUE -) - -FetchContent_GetProperties(asio) - -if(NOT asio_POPULATED) - FetchContent_Populate(asio) - - target_include_directories(${PROJECT_NAME} PRIVATE ${asio_SOURCE_DIR}/include) - - find_package(Threads) - target_link_libraries(${PROJECT_NAME} INTERFACE Threads::Threads) -endif() diff --git a/deps/boost/CMakeLists.txt b/deps/boost/CMakeLists.txt new file mode 100644 index 00000000..5dd075f5 --- /dev/null +++ b/deps/boost/CMakeLists.txt @@ -0,0 +1,72 @@ +cmake_minimum_required(VERSION 3.15) + +# -- Fetch Boost +include(FetchContent) +FetchContent_Declare( + Boost + URL "https://github.com/boostorg/boost/releases/download/boost-1.83.0/boost-1.83.0.tar.xz" + DOWNLOAD_EXTRACT_TIMESTAMP ON +) + +set(BOOST_RUNTIME_LINK static) +set(BOOST_INCLUDE_LIBRARIES + asio + assert + align + array + + bind + + coroutine + config + context + core + chrono + + date_time + + exception + + function + + move + + system + smart_ptr + + throw_exception + type_traits + + utility +) +FetchContent_MakeAvailable(Boost) + +find_package(Threads REQUIRED) +target_link_libraries( + ${PROJECT_NAME_CLIENT} + PRIVATE + Threads::Threads +) + +foreach(lib ${BOOST_INCLUDE_LIBRARIES}) + target_link_libraries( + ${PROJECT_NAME_CLIENT} + PRIVATE + Boost::${lib} + ) + target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + Boost::${lib} + ) + target_link_libraries( + ${PROJECT_NAME_SERVER} + PRIVATE + Boost::${lib} + ) + target_include_directories( + ${PROJECT_NAME_SERVER} + PRIVATE + Boost::${lib} + ) +endforeach() diff --git a/deps/raylib/CMakeLists.txt b/deps/raylib/CMakeLists.txt index 9d215c92..fd2aeb97 100644 --- a/deps/raylib/CMakeLists.txt +++ b/deps/raylib/CMakeLists.txt @@ -4,22 +4,15 @@ include(FetchContent) FetchContent_Declare( raylib + CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_CONFIGURATION_TYPES=\"Release;Release\"" "-DCONFIG=Release" URL "https://github.com/X-R-G-B/R-Bus/releases/latest/download/raylib.tar" DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) -FetchContent_GetProperties(raylib) +FetchContent_MakeAvailable(raylib) -if(NOT raylib_POPULATED) - FetchContent_Populate(raylib) - add_subdirectory( - ${raylib_SOURCE_DIR} - ${raylib_BINARY_DIR} - ) - - target_link_libraries( - ${PROJECT_NAME} - PRIVATE - raylib - ) -endif() +target_link_libraries( + ${PROJECT_NAME_CLIENT} + PRIVATE + raylib +) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 00000000..c6e1a32b --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,68 @@ +[fork]: https://github.com/X-R-G-B/R-Bus/fork +[pr]: https://github.com/X-R-G-B/R-Bus/compare/ +[doc-codeQL]: https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/about-codeql-code-scanning-in-your-ci-system + +# CONTRIBUTING + +Here is the instructions if you want to contribute to the project + +## Submitting a pull request + +1. [Fork][fork] and clone the repository +2. Create a new branch: See '[creating a branch](#creating-a-branch)' +3. Make your change, add tests, and make sure the tests still pass +4. Make sure that the code is codeQL compliant +5. Make sure that you had documentation to the new added code (obviously compliant with our doc) +6. Push to your fork and [submit a pull request][pr] with correct labels added if necessary +7. Wait for your pull request to be reviewed and merged. + +Here are a few things you can do that will increase the likelihood of your pull request being accepted: + +- The security of your code is analysed by [codeQL][doc-codeQL] the CI might fail if it's not secure. +- The style of your code must respect the clang-format style. + Normally we have the .clang-format if you want for your IDE. + If you don't want to use the .clang-format intergration in your IDE, you can still + launch the script format.sh (Linux and MacOs) or format.ps1 (Windows), this will format automaticlly your code. +**/!\ Warning ! If your code is not clang format compliant your CI will fail and your pr will be refused.** +- Write tests. +- Keep your change as focused as possible. + If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. +- Write a commit message that respect the commit norm that we have, see '[Commit message norm](#commit-message-norm)'. + + +## Commit message norm +1. Define your context. +- CICD +- CLIENT-GAME +- DOCUMENTATION +- POC +- NETWORK +- SERVER +2. Followed by ":" + "action verb" +- : Add +- : Fix +- : Update +- etc ... +3. Explain what your commit introduce +- new feature for client-game +- bug inside network +- documentation for CLIENT-GAME +- etc... +4. Just after your commit message put a newline to indicate semver +- PATCH (If your commit introduce a bug fix) +- MINOR (If your commit introduce a new feature) +- MAJOR (If your commit introduce a new feature and the older version doesn't work anymore) + +__/!\ Warning ! If your commit message doesn't respect those rules your pr might not be accepted__ + + +## Creating a branch +If you need to contribute to our project, you will need to create a branch to submit a pull request. +Basicly, you must indicate what is the context of your branch followed by a '/'. +For exemple : +- feature/BRANCH-NAME +- doc/BRANCH-NAME +- refactor/BRANCH-NAME +- etc... + +That's all you need to do to create a valid branch. \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..50be7b39 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,24 @@ +# R-Bus + + +``` +R-Type[a] is a horizontally scrolling shooter arcade video game developed +and released by Irem in 1987 and the first game in the R-Type series. +The player controls a star ship, the R-9 "Arrowhead", in its efforts to +destroy the Bydo, a powerful alien race bent on wiping out all of mankind. +The R-9 can acquire a glowing orbicular device called a "Force", +protecting it from enemy fire and providing additional firepower. +The arcade version was distributed by Nintendo in North America; +it is the last arcade title Nintendo distributed. +``` +[wikipedia](https://en.wikipedia.org/wiki/R-Type) + +## Gameplay + +- Horizontally scrolling shooter + +- Single player / Multi player + +- 2D + +*if you are on github repo, you can see the mdbook here: [https://x-r-g-b.github.io/R-Bus/](https://x-r-g-b.github.io/R-Bus/)* diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md new file mode 100644 index 00000000..13c26c2f --- /dev/null +++ b/docs/SUMMARY.md @@ -0,0 +1,43 @@ +# Summary + +[README](README.md) + +[Screenshots](screenshots.md) + +# User Guide + +- [Installation](user-guide/installation/README.md) + - [From packaged binary](user-guide/installation/packaged-binary/README.md) + - [GNU/Linux](user-guide/installation/packaged-binary/gnu-linux.md) + - [MacOs](user-guide/installation/packaged-binary/macos.md) + - [Windows](user-guide/installation/packaged-binary/windows.md) + - [From source](user-guide/installation/source/README.md) + - [GNU/Linux](user-guide/installation/source/gnu-linux.md) + - [MacOs](user-guide/installation/source/macos.md) + - [Windows](user-guide/installation/source/windows.md) + +- [Usage](user-guide/usage.md) + +- [Troubleshooting](user-guide/troubleshooting.md) + +# Developer Guide + +- [CONTRIBUTING](CONTRIBUTING.md) + +- [CICD](developer-guide/CICD.md) + +- [Common logic](developer-guide/common-logic.md) + +- [Network](developer-guide/network/README.md) + - [RFC](developer-guide/network/rfc.md) + +- [ECS](developer-guide/ecs/README.md) + - [UML](developer-guide/ecs/uml.md) + +- [Server](developer-guide/server/README.md) + +- [Client](developer-guide/client/README.md) + +----------- + +[Contributors](contributors.md) diff --git a/docs/contributors.md b/docs/contributors.md new file mode 100644 index 00000000..7dbcf649 --- /dev/null +++ b/docs/contributors.md @@ -0,0 +1,9 @@ +# Contributors + +Thanks to this amazing contributors that made this project possible! + +- [@Saverio976](https://github.com/Saverio976) +- [@TTENSHII](https://github.com/TTENSHII) +- [@guillaumeAbel](https://github.com/guillaumeAbel) +- [@KitetsuK](https://github.com/KitetsuK) +- [@romainpanno](https://github.com/romainpanno) diff --git a/docs/developer-guide/CICD.md b/docs/developer-guide/CICD.md new file mode 100644 index 00000000..7db3c47d --- /dev/null +++ b/docs/developer-guide/CICD.md @@ -0,0 +1,21 @@ +# CICD + +## Compilation test + +When you modify the `src` directory, the workflow will run + +## Documentation + +When you modify the `docs` directory or `book.tml`, the workflow will run + +## Format + +The code is automatically formatted by the workflow when your create a pull request. + +If it can't be automatically formated, please use clang-format with the script `./scripts/format.sh` or `./scripts/format.ps1` + +## Release + +On the main branch, and the dev branch, the workflow will run + +In dev branch it don't push the packaged binary or the source code to a release but in the workflow artifact diff --git a/docs/developer-guide/client/README.md b/docs/developer-guide/client/README.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/developer-guide/common-logic.md b/docs/developer-guide/common-logic.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/developer-guide/ecs/README.md b/docs/developer-guide/ecs/README.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/developer-guide/ecs/uml.md b/docs/developer-guide/ecs/uml.md new file mode 100644 index 00000000..1fa9e25e --- /dev/null +++ b/docs/developer-guide/ecs/uml.md @@ -0,0 +1 @@ +![UML](./uml.png) diff --git a/docs/developer-guide/ecs/uml.png b/docs/developer-guide/ecs/uml.png new file mode 100644 index 00000000..ce077931 Binary files /dev/null and b/docs/developer-guide/ecs/uml.png differ diff --git a/docs/developer-guide/network/README.md b/docs/developer-guide/network/README.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/developer-guide/network/rfc.md b/docs/developer-guide/network/rfc.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/developer-guide/server/README.md b/docs/developer-guide/server/README.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/screenshots.md b/docs/screenshots.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/user-guide/installation/README.md b/docs/user-guide/installation/README.md new file mode 100644 index 00000000..b8099966 --- /dev/null +++ b/docs/user-guide/installation/README.md @@ -0,0 +1,10 @@ +# Installation + +There are two ways to install R-Bus: +- From packaged binary +- From source + +*Prefer the packaged binary if you want to find yoursel downloading some dependencies and compiling R-Bus.* +*Prefer the packaged binary if you are not a nerd* + +Else, go ahead and install R-Bus from source. diff --git a/docs/user-guide/installation/packaged-binary/README.md b/docs/user-guide/installation/packaged-binary/README.md new file mode 100644 index 00000000..edc15d84 --- /dev/null +++ b/docs/user-guide/installation/packaged-binary/README.md @@ -0,0 +1,5 @@ +# Packaged binary + +Now, let's install R-Bus from packaged binary. + +Please select the right page for your operating system diff --git a/docs/user-guide/installation/packaged-binary/gnu-linux.md b/docs/user-guide/installation/packaged-binary/gnu-linux.md new file mode 100644 index 00000000..81da2573 --- /dev/null +++ b/docs/user-guide/installation/packaged-binary/gnu-linux.md @@ -0,0 +1,12 @@ +# GNU/Linux + +```bash +curl -Lo 'r-type-linux.sh' 'https://github.com/X-R-G-B/R-Bus/releases/latest/download/r-type-linux.sh' +# The following line will Accepts the license, extract the packaged binary + its dependencies +yes y | bash 'r-type-linux.sh' +cd R-Type-Linux || echo "Failed to cd to R-Type-Linux, please open an issue: 'https://github.com/X-R-G-B/R-Bus/issues/new?assignees=&labels=bug&projects=&template=install-failed.yml&title=%5BFAIL+INSTALL%5D+-+Title'" +# your binaries are in ./bin/ +ls ./bin/ +``` + +:warnings: When you want to move this binaries, please move all the folder R-Type-Linux diff --git a/docs/user-guide/installation/packaged-binary/macos.md b/docs/user-guide/installation/packaged-binary/macos.md new file mode 100644 index 00000000..e4284b1f --- /dev/null +++ b/docs/user-guide/installation/packaged-binary/macos.md @@ -0,0 +1,3 @@ +# MacOs + +Not available now diff --git a/docs/user-guide/installation/packaged-binary/windows.md b/docs/user-guide/installation/packaged-binary/windows.md new file mode 100644 index 00000000..15ffe309 --- /dev/null +++ b/docs/user-guide/installation/packaged-binary/windows.md @@ -0,0 +1,3 @@ +# Windows + +Download https://github.com/X-R-G-B/R-Bus/releases/latest/download/r-type-windows.exe and run it diff --git a/docs/user-guide/installation/source/README.md b/docs/user-guide/installation/source/README.md new file mode 100644 index 00000000..11b9f337 --- /dev/null +++ b/docs/user-guide/installation/source/README.md @@ -0,0 +1,5 @@ +# Source + +Now, let's install R-Bus from source. + +Please select the right page for your operating system diff --git a/docs/user-guide/installation/source/gnu-linux.md b/docs/user-guide/installation/source/gnu-linux.md new file mode 100644 index 00000000..5f9bd3e0 --- /dev/null +++ b/docs/user-guide/installation/source/gnu-linux.md @@ -0,0 +1,29 @@ +# GNU/Linux + +- You need to have cmake, and a c++ compiler + +*hint: you can use https://github.com/aminya/setup-cpp to install it* + +- Git clone the project or download the .zip + +`git clone -b main https://github.com/X-R-G-B/R-Bus.git R-Bus-main` + +**OR** + +`wget https://github.com/X-R-G-B/R-Bus/archive/main.zip && unzip R-Bus-main.zip` + +- Change directory + +`cd R-Bus-main || "Failed to cd to R-Type-Linux, please open an issue: 'https://github.com/X-R-G-B/R-Bus/issues/new?assignees=&labels=bug&projects=&template=install-failed.yml&title=%5BFAIL+INSTALL%5D+-+Title'"` + +- Install dependencies + +`sudo ./scripts/install-deps-linux.sh` + +- Build the project + +`./scripts/compil.sh` + +Well Done you have your binaries! + +Now, you can run it but dont move it anywhere diff --git a/docs/user-guide/installation/source/macos.md b/docs/user-guide/installation/source/macos.md new file mode 100644 index 00000000..f423f39e --- /dev/null +++ b/docs/user-guide/installation/source/macos.md @@ -0,0 +1,29 @@ +# MacOs + +- You need to have cmake, and a c++ compiler + +*hint: you can use https://github.com/aminya/setup-cpp to install it* + +- Git clone the project or download the .zip + +`git clone -b main https://github.com/X-R-G-B/R-Bus.git R-Bus-main` + +**OR** + +`wget https://github.com/X-R-G-B/R-Bus/archive/main.zip && unzip R-Bus-main.zip` + +- Change directory + +`cd R-Bus-main || "Failed to cd to R-Type-Linux, please open an issue: 'https://github.com/X-R-G-B/R-Bus/issues/new?assignees=&labels=bug&projects=&template=install-failed.yml&title=%5BFAIL+INSTALL%5D+-+Title'"` + +- Install dependencies + +`./scripts/install-deps-macos.sh` + +- Build the project + +`./scripts/compil.sh` + +Well Done you have your binaries! + +Now, you can run it but dont move it anywhere diff --git a/docs/user-guide/installation/source/windows.md b/docs/user-guide/installation/source/windows.md new file mode 100644 index 00000000..f7a8fab0 --- /dev/null +++ b/docs/user-guide/installation/source/windows.md @@ -0,0 +1,29 @@ +# Windows + +- You need to have cmake, and a c++ compiler + +*hint: you can use https://github.com/aminya/setup-cpp to install it* + +- Git clone the project or download the .zip + +`git clone -b main https://github.com/X-R-G-B/R-Bus.git R-Bus-main` + +**OR** + +`wget https://github.com/X-R-G-B/R-Bus/archive/main.zip && unzip R-Bus-main.zip` + +- Change directory + +`cd R-Bus-main || "Failed to cd to R-Type-Linux, please open an issue: 'https://github.com/X-R-G-B/R-Bus/issues/new?assignees=&labels=bug&projects=&template=install-failed.yml&title=%5BFAIL+INSTALL%5D+-+Title'"` + +- Install dependencies + +`./scripts/install-deps-windows.ps1` + +- Build the project + +`./scripts/compil.ps1` + +Well Done you have your binaries! + +Now, you can run it but dont move it anywhere diff --git a/docs/user-guide/troubleshooting.md b/docs/user-guide/troubleshooting.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/user-guide/usage.md b/docs/user-guide/usage.md new file mode 100644 index 00000000..e69de29b diff --git a/scripts/bundle-linux.sh b/scripts/bundle-linux.sh new file mode 100755 index 00000000..26f06479 --- /dev/null +++ b/scripts/bundle-linux.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Run cpack + +set -ex + +rm -rf build + +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + +cmake --build build + +cd build || exit 14 + +cpack --config CPackConfig.cmake -G STGZ + +mv R-Type-Linux.sh ../r-type-linux.sh + +cpack --config CPackSourceConfig.cmake -G TGZ + +mv R-Type-Linux.tar.gz ../r-type-linux.tar.gz diff --git a/scripts/bundle-macos.sh b/scripts/bundle-macos.sh new file mode 100755 index 00000000..58792505 --- /dev/null +++ b/scripts/bundle-macos.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Run cpack + +set -ex + +rm -rf build + +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + +cmake --build build + +cd build || exit 14 + +cpack --config CPackConfig.cmake -G DragNDrop || (cat "./_CPack_Packages/Darwin/DragNDrop/PreinstallOutput.log" && exit 1) + +cp R-Type-Darwin.dmg ../r-type-macos.dmg + +cpack --config CPackSourceConfig.cmake -G ZIP + +cp R-Type-Darwin.zip ../r-type-macos.zip diff --git a/scripts/bundle-windows.ps1 b/scripts/bundle-windows.ps1 new file mode 100644 index 00000000..bcdb8e1f --- /dev/null +++ b/scripts/bundle-windows.ps1 @@ -0,0 +1,26 @@ +#!/bin/pwsh +# Run cpack + +$ErrorActionPreference = "SilentlyContinue" + +rm -Recurse build + +cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release" + +cmake --build build --config Release + +cd build + +cpack --config CPackConfig.cmake -G NSIS + +if ($LASTEXITCODE -ne 0) { + type _CPack_Packages/win64/NSIS/NSISOutput.log +} + +Copy-Item R-Type-Windows.exe ../r-type-windows.exe + +cpack --config CPackSourceConfig.cmake -G ZIP + +Copy-Item R-Type-Windows.zip ../r-type-windows.zip + +cd .. diff --git a/scripts/compil.ps1 b/scripts/compil.ps1 new file mode 100644 index 00000000..ef539cf0 --- /dev/null +++ b/scripts/compil.ps1 @@ -0,0 +1,8 @@ +#!/bin/pwsh +# Compil using cmake + +$ErrorActionPreference = 'Stop' + +cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +cmake --build build -- /m diff --git a/scripts/compil.sh b/scripts/compil.sh new file mode 100755 index 00000000..1c4b872b --- /dev/null +++ b/scripts/compil.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Compil using cmake + +set -ex + +cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +cmake --build build diff --git a/scripts/format.ps1 b/scripts/format.ps1 new file mode 100644 index 00000000..64ec520f --- /dev/null +++ b/scripts/format.ps1 @@ -0,0 +1,12 @@ +#!/bin/pwsh +# Format c++ files and exit with error if files are not formatted + +$argClangFormat = @() + +if ($args.Count -gt 0 -and $args[0] -eq '--dry-run') { + $argClangFormat = @('--dry-run', '--Werror') +} + +$files = Get-Childitem -Path src -Include *.cpp,*.hpp -Recurse -ErrorAction SilentlyContinue + +clang-format --style=file $argClangFormat -i $files diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 00000000..10c2d53c --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Format c++ files and exit with error if files are not formatted + +set -ex + +ARGS= + +if [ "$1" == "--dry-run" ]; then + ARGS="--dry-run --Werror" +fi + +find src/ \( -name '*.cpp' -o -name '*.hpp' \) -print0 | xargs -0 clang-format --style=file $ARGS -i diff --git a/scripts/install-deps-linux.sh b/scripts/install-deps-linux.sh new file mode 100755 index 00000000..4b67ebe7 --- /dev/null +++ b/scripts/install-deps-linux.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Install deps + +if command -v apt-get 2>/dev/null; then + apt-get install -y g++ cmake clang-tidy clang-format xorg-dev +elif command -v pacman 2>/dev/null; then + pacman -S g++ cmake clang +elif command -v dnf 2>/dev/null; then + dnf install -y libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel cmake clang-tools-extra gcc-c++ make cmake +else + echo "Unsupported package manager" + exit 12 +fi diff --git a/scripts/install-deps-macos.sh b/scripts/install-deps-macos.sh new file mode 100755 index 00000000..bf165ec8 --- /dev/null +++ b/scripts/install-deps-macos.sh @@ -0,0 +1,7 @@ +#!/bin/zsh +# Install dependencies + +brew install cmake +brew install llvm +ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy" +ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format" diff --git a/scripts/install-deps-windows.ps1 b/scripts/install-deps-windows.ps1 new file mode 100644 index 00000000..39aae57f --- /dev/null +++ b/scripts/install-deps-windows.ps1 @@ -0,0 +1,12 @@ +#!/bin/pwsh +# Install deps + +winget list -e LLVM +if ($LASTEXITCODE -ne 0) { + winget install --accept-package-agreements --accept-source-agreements LLVM -e +} + +winget list -e CMake +if ($LASTEXITCODE -ne 0) { + winget install --accept-package-agreements --accept-source-agreements CMake -e +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 719b017c..5dfcfc72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,15 +1,21 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/main_client.cpp +) + +target_sources( + ${PROJECT_NAME_SERVER} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/main_server.cpp ) add_subdirectory(Client) diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt index b48864d6..27261af6 100644 --- a/src/Client/CMakeLists.txt +++ b/src/Client/CMakeLists.txt @@ -1,15 +1,17 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/SceneManager.cpp ) add_subdirectory(Systems) +add_subdirectory(Raylib) +add_subdirectory(EventManager) diff --git a/src/ECS/EventManager/CMakeLists.txt b/src/Client/EventManager/CMakeLists.txt similarity index 78% rename from src/ECS/EventManager/CMakeLists.txt rename to src/Client/EventManager/CMakeLists.txt index 414dfcaa..31cf717b 100644 --- a/src/ECS/EventManager/CMakeLists.txt +++ b/src/Client/EventManager/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/EventManager.cpp ) diff --git a/src/ECS/EventManager/EventManager.cpp b/src/Client/EventManager/EventManager.cpp similarity index 51% rename from src/ECS/EventManager/EventManager.cpp rename to src/Client/EventManager/EventManager.cpp index 9d8e0b58..c72736f3 100644 --- a/src/ECS/EventManager/EventManager.cpp +++ b/src/Client/EventManager/EventManager.cpp @@ -5,11 +5,13 @@ ** EventManager implementation */ -#include "raylib.h" #include "EventManager.hpp" +#include #include "Events.hpp" +// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) EventManager EventManager::instance = EventManager(); +// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) EventManager &EventManager::getInstance() { @@ -20,18 +22,18 @@ void EventManager::updateEvents() { _activeEvents.clear(); for (auto event : Events::events) { - if (IsKeyDown(event)) { + if (Raylib::isKeyDown(event)) { _activeEvents.push_back(event); } } } -bool EventManager::checkEvent(int event) +bool EventManager::checkEvent(Raylib::KeyboardKey event) { - for (auto activeEvent : _activeEvents) { - if (activeEvent == event) { - return true; - } - } - return false; + return std::any_of( + _activeEvents.begin(), + _activeEvents.end(), + [event](Raylib::KeyboardKey e) { + return e == event; + }); } diff --git a/src/Client/EventManager/EventManager.hpp b/src/Client/EventManager/EventManager.hpp new file mode 100644 index 00000000..d524486b --- /dev/null +++ b/src/Client/EventManager/EventManager.hpp @@ -0,0 +1,26 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** EventManager +*/ + +#pragma once + +#include +#include "Raylib.hpp" + +class EventManager { + public: + static EventManager &getInstance(); + void updateEvents(); + bool checkEvent(Raylib::KeyboardKey event); + + private: + EventManager() = default; + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + static EventManager instance; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + std::vector _activeEvents; +}; diff --git a/src/Client/EventManager/Events.hpp b/src/Client/EventManager/Events.hpp new file mode 100644 index 00000000..41fa1a6f --- /dev/null +++ b/src/Client/EventManager/Events.hpp @@ -0,0 +1,21 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Events +*/ + +#pragma once + +#include +#include +#include "Raylib.hpp" + +namespace Events { + static const auto events = { + Raylib::KeyboardKey::KB_LEFT, + Raylib::KeyboardKey::KB_RIGHT, + Raylib::KeyboardKey::KB_UP, + Raylib::KeyboardKey::KB_DOWN, + }; +} diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp new file mode 100644 index 00000000..fe09c2a1 --- /dev/null +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -0,0 +1,190 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Audio +*/ + +#include "Audio.hpp" + +namespace Raylib { + + // Audio device management functions + + void initAudioDevice() + { + InitAudioDevice(); + } + + void closeAudioDevice() + { + CloseAudioDevice(); + } + + bool isAudioDeviceReady() + { + return IsAudioDeviceReady(); + } + + void setMasterVolume(float volume) + { + SetMasterVolume(volume); + } + + // Sounds + Sound::Sound(const std::string& fileName, float volume) + : _sound(LoadSound(fileName.c_str())), + _path(fileName) + { + SetSoundVolume(_sound, volume); + } + + void Sound::unload() + { + UnloadSound(_sound); + } + + void Sound::play() const + { + PlaySound(_sound); + } + + void Sound::stop() const + { + StopSound(_sound); + } + + void Sound::pause() const + { + PauseSound(_sound); + } + + void Sound::resume() const + { + ResumeSound(_sound); + } + + bool Sound::isPlaying() const + { + return IsSoundPlaying(_sound); + } + + void Sound::setVolume(float volume) const + { + SetSoundVolume(_sound, volume); + } + + void Sound::setPitch(float pitch) const + { + SetSoundPitch(_sound, pitch); + } + + void Sound::setPan(float pan) const + { + SetSoundPitch(_sound, pan); + } + + bool Sound::NeedToPlay() const + { + return _needToPlay; + } + + void Sound::setNeedToPlay(bool needToPlay) + { + _needToPlay = needToPlay; + } + + std::string Sound::getPath() const + { + return _path; + } + + // Music + + Music::Music(const std::string& fileName, float volume) + : _music(LoadMusicStream(fileName.c_str())), + _path(fileName) + { + SetMusicVolume(_music, volume); + } + + void Music::unload() + { + UnloadMusicStream(_music); + } + + bool Music::isReady() const + { + return IsMusicStreamPlaying(_music); + } + + void Music::play() const + { + PlayMusicStream(_music); + } + + bool Music::isPlaying() const + { + return IsMusicStreamPlaying(_music); + } + + void Music::update() const + { + UpdateMusicStream(_music); + } + + void Music::stop() const + { + StopMusicStream(_music); + } + + void Music::pause() const + { + PauseMusicStream(_music); + } + + void Music::resume() const + { + ResumeMusicStream(_music); + } + + void Music::setVolume(float volume) const + { + SetMusicVolume(_music, volume); + } + + void Music::setPitch(float pitch) const + { + SetMusicPitch(_music, pitch); + } + + void Music::setPan(float pan) const + { + SetMusicPitch(_music, pan); + } + + float Music::getTimeLength() const + { + return GetMusicTimeLength(_music); + } + + float Music::getTimePlayed() const + { + return GetMusicTimePlayed(_music); + } + + bool Music::NeedToPlay() const + { + return _needToPlay; + } + + void Music::setNeedToPlay(bool needToPlay) + { + _needToPlay = needToPlay; + } + + std::string Music::getPath() const + { + return _path; + } +} // namespace Raylib diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp new file mode 100644 index 00000000..b9f3e63c --- /dev/null +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -0,0 +1,68 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Audio +*/ + +#pragma once + +#include +#include "raylib.h" + +namespace Raylib { + // Audio device management functions + void initAudioDevice(); + void closeAudioDevice(); + bool isAudioDeviceReady(); + void setMasterVolume(float volume); + + // Sounds + class Sound { + public: + Sound(const std::string& fileName, float volume = 0.5f); + void unload(); + void play() const; + void stop() const; + void pause() const; + void resume() const; + bool isPlaying() const; + void setVolume(float volume) const; + void setPitch(float pitch) const; + void setPan(float pan) const; + bool NeedToPlay() const; + void setNeedToPlay(bool needToPlay); + std::string getPath() const; + + private: + ::Sound _sound; + bool _needToPlay {false}; + std::string _path; + }; + + class Music { + public: + Music(const std::string& fileName, float volume = 0.5f); + void unload(); + bool isReady() const; + void play() const; + bool isPlaying() const; + void update() const; + void stop() const; + void pause() const; + void resume() const; + void setVolume(float volume) const; + void setPitch(float pitch) const; + void setPan(float pan) const; + float getTimeLength() const; + float getTimePlayed() const; + bool NeedToPlay() const; + void setNeedToPlay(bool needToPlay); + std::string getPath() const; + + private: + ::Music _music; + bool _needToPlay {false}; + std::string _path; + }; +} // namespace Raylib diff --git a/src/Client/Raylib/Audio/CMakeLists.txt b/src/Client/Raylib/Audio/CMakeLists.txt new file mode 100644 index 00000000..e44afae6 --- /dev/null +++ b/src/Client/Raylib/Audio/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Audio.cpp +) diff --git a/src/Client/Raylib/CMakeLists.txt b/src/Client/Raylib/CMakeLists.txt new file mode 100644 index 00000000..32dfbde8 --- /dev/null +++ b/src/Client/Raylib/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(Geometry) +add_subdirectory(Graphics) +add_subdirectory(Audio) +add_subdirectory(Events) diff --git a/src/Client/Raylib/Events/CMakeLists.txt b/src/Client/Raylib/Events/CMakeLists.txt new file mode 100644 index 00000000..fc156dfc --- /dev/null +++ b/src/Client/Raylib/Events/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/Client/Raylib/Events/Inputs.hpp b/src/Client/Raylib/Events/Inputs.hpp new file mode 100644 index 00000000..6aafe81f --- /dev/null +++ b/src/Client/Raylib/Events/Inputs.hpp @@ -0,0 +1,114 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Inputs +*/ + +#pragma once +#include "raylib.h" + +namespace Raylib { + + enum class KeyboardKey : int { + KB_NULL = KEY_NULL, + KB_APOSTROPHE = KEY_APOSTROPHE, + KB_COMMA = KEY_COMMA, + KB_MINUS = KEY_MINUS, + KB_PERIOD = KEY_PERIOD, + KB_SLASH = KEY_SLASH, + KB_ZERO = KEY_ZERO, + KB_ONE = KEY_ONE, + KB_TWO = KEY_TWO, + KB_THREE = KEY_THREE, + KB_FOUR = KEY_FOUR, + KB_FIVE = KEY_FIVE, + KB_SIX = KEY_SIX, + KB_SEVEN = KEY_SEVEN, + KB_EIGHT = KEY_EIGHT, + KB_NINE = KEY_NINE, + KB_SEMICOLON = KEY_SEMICOLON, + KB_EQUAL = KEY_EQUAL, + KB_A = KEY_A, + KB_B = KEY_B, + KB_C = KEY_C, + KB_D = KEY_D, + KB_E = KEY_E, + KB_F = KEY_F, + KB_G = KEY_G, + KB_H = KEY_H, + KB_I = KEY_I, + KB_J = KEY_J, + KB_K = KEY_K, + KB_L = KEY_L, + KB_M = KEY_M, + KB_N = KEY_N, + KB_O = KEY_O, + KB_P = KEY_P, + KB_Q = KEY_Q, + KB_R = KEY_R, + KB_S = KEY_S, + KB_T = KEY_T, + KB_U = KEY_U, + KB_V = KEY_V, + KB_W = KEY_W, + KB_X = KEY_X, + KB_Y = KEY_Y, + KB_Z = KEY_Z, + KB_LEFT_BRACKET = KEY_LEFT_BRACKET, + KB_BACKSLASH = KEY_BACKSLASH, + KB_RIGHT_BRACKET = KEY_RIGHT_BRACKET, + KB_GRAVE = KEY_GRAVE, + KB_SPACE = KEY_SPACE, + KB_ESCAPE = KEY_ESCAPE, + KB_ENTER = KEY_ENTER, + KB_TAB = KEY_TAB, + KB_BACKSPACE = KEY_BACKSPACE, + KB_INSERT = KEY_INSERT, + KB_DELETE = KEY_DELETE, + KB_RIGHT = KEY_RIGHT, + KB_LEFT = KEY_LEFT, + KB_DOWN = KEY_DOWN, + KB_UP = KEY_UP, + KB_PAGE_UP = KEY_PAGE_UP, + KB_PAGE_DOWN = KEY_PAGE_DOWN, + KB_HOME = KEY_HOME, + KB_END = KEY_END, + KB_CAPS_LOCK = KEY_CAPS_LOCK, + KB_SCROLL_LOCK = KEY_SCROLL_LOCK, + KB_NUM_LOCK = KEY_NUM_LOCK, + KB_PRINT_SCREEN = KEY_PRINT_SCREEN, + KB_PAUSE = KEY_PAUSE, + KB_F1 = KEY_F1, + KB_F2 = KEY_F2, + KB_F3 = KEY_F3, + KB_F4 = KEY_F4, + KB_F5 = KEY_F5, + KB_F6 = KEY_F6, + KB_F7 = KEY_F7, + KB_F8 = KEY_F8, + KB_F9 = KEY_F9, + KB_F10 = KEY_F10, + KB_F11 = KEY_F11, + KB_F12 = KEY_F12, + KB_LEFT_SHIFT = KEY_LEFT_SHIFT, + KB_LEFT_CONTROL = KEY_LEFT_CONTROL, + KB_LEFT_ALT = KEY_LEFT_ALT, + KB_LEFT_SUPER = KEY_LEFT_SUPER, + KB_RIGHT_SHIFT = KEY_RIGHT_SHIFT, + KB_RIGHT_CONTROL = KEY_RIGHT_CONTROL, + KB_RIGHT_ALT = KEY_RIGHT_ALT, + KB_RIGHT_SUPER = KEY_RIGHT_SUPER, + KB_MENU = KEY_MENU, + }; + + enum class MouseButton : int { + MOUSE_BTN_LEFT = MOUSE_BUTTON_LEFT, + MOUSE_BTN_RIGHT = MOUSE_BUTTON_RIGHT, + MOUSE_BTN_MIDDLE = MOUSE_BUTTON_LEFT, + MOUSE_BTN_SIDE = MOUSE_BUTTON_SIDE, + MOUSE_BTN_EXTRA = MOUSE_BUTTON_EXTRA, + MOUSE_BTN_FORWARD = MOUSE_BUTTON_FORWARD, + MOUSE_BTN_BACK = MOUSE_BUTTON_BACK, + }; +} // namespace Raylib diff --git a/src/Client/Raylib/Geometry/CMakeLists.txt b/src/Client/Raylib/Geometry/CMakeLists.txt new file mode 100644 index 00000000..38cca0b5 --- /dev/null +++ b/src/Client/Raylib/Geometry/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Geometry.cpp +) diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp new file mode 100644 index 00000000..80f891a5 --- /dev/null +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -0,0 +1,43 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Geometry +*/ + +#include "Geometry.hpp" + +namespace Raylib { + + Vector2::Vector2(float x, float y) : x(x), y(y) + { + } + + Vector3::Vector3(float x, float y, float z) : x(x), y(y), z(z) + { + } + + Vector4::Vector4(float x, float y, float z, float w) + : x(x), + y(y), + z(z), + w(w) + { + } + + Rectangle::Rectangle(float x, float y, float width, float height) + : x(x), + y(y), + width(width), + height(height) + { + } + + Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + : r(r), + g(g), + b(b), + a(a) + { + } +} // namespace Raylib diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp new file mode 100644 index 00000000..6212ed6a --- /dev/null +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -0,0 +1,77 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Geometry +*/ + +#pragma once + +#include +#include "raylib.h" + +namespace Raylib { + + struct Vector2 { + Vector2(float x, float y); + float x; + float y; + }; + + struct Vector3 { + Vector3(float x, float y, float z); + float x; + float y; + float z; + }; + + struct Vector4 { + Vector4(float x, float y, float z, float w); + float x; + float y; + float z; + float w; + }; + + struct Rectangle { + Rectangle(float x, float y, float width, float height); + float x; + float y; + float width; + float height; + }; + + struct Color { + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + }; + + // COLOR CONSTANTS + static const Color DarkGray = static_cast(DARKGRAY); + static const Color Yellow = static_cast(YELLOW); + static const Color Gold = static_cast(GOLD); + static const Color Orange = static_cast(ORANGE); + static const Color Pink = static_cast(PINK); + static const Color Red = static_cast(RED); + static const Color Maroon = static_cast(MAROON); + static const Color Green = static_cast(GREEN); + static const Color Lime = static_cast(LIME); + static const Color DarkGreen = static_cast(DARKGREEN); + static const Color SkyBlue = static_cast(SKYBLUE); + static const Color Blue = static_cast(BLUE); + static const Color DarkBlue = static_cast(DARKBLUE); + static const Color Purple = static_cast(PURPLE); + static const Color Violet = static_cast(VIOLET); + static const Color DarkPurple = static_cast(DARKPURPLE); + static const Color Beige = static_cast(BEIGE); + static const Color Brown = static_cast(BROWN); + static const Color DarkBrown = static_cast(DARKBROWN); + static const Color White = static_cast(WHITE); + static const Color Black = static_cast(BLACK); + static const Color Blank = static_cast(BLANK); + static const Color Magenta = static_cast(MAGENTA); + static const Color RayWhite = static_cast(RAYWHITE); +} // namespace Raylib diff --git a/src/Client/Raylib/Graphics/CMakeLists.txt b/src/Client/Raylib/Graphics/CMakeLists.txt new file mode 100644 index 00000000..e4c897ab --- /dev/null +++ b/src/Client/Raylib/Graphics/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Graphics.cpp +) diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp new file mode 100644 index 00000000..1e09d9c5 --- /dev/null +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -0,0 +1,704 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Graphics +*/ + +#include "Graphics.hpp" +#include "Inputs.hpp" + +namespace Raylib { + + // Window-related functions + + void initWindow(int width, int height, const std::string &title) + { + InitWindow(width, height, title.c_str()); + } + + bool windowShouldClose() + { + return WindowShouldClose(); + } + + void closeWindow() + { + CloseWindow(); + } + + bool isWindowReady() + { + return IsWindowReady(); + } + + bool isWindowFullscreen() + { + return IsWindowFullscreen(); + } + + bool isWindowHidden() + { + return IsWindowHidden(); + } + + bool isWindowMinimized() + { + return IsWindowMinimized(); + } + + bool isWindowMaximized() + { + return IsWindowMaximized(); + } + + bool isWindowFocused() + { + return IsWindowFocused(); + } + + void setConfigFlags(ConfigFlags flags) + { + SetConfigFlags(static_cast(flags)); + } + + bool isWindowResized() + { + return IsWindowResized(); + } + + bool isWindowState(ConfigFlags flag) + { + return IsWindowState(static_cast(flag)); + } + + void setWindowState(ConfigFlags flags) + { + SetWindowState(static_cast(flags)); + } + + void clearWindowState(ConfigFlags flags) + { + ClearWindowState(static_cast(flags)); + } + + void toggleFullscreen() + { + ToggleFullscreen(); + } + + void maximizeWindow() + { + MaximizeWindow(); + } + + void minimizeWindow() + { + MinimizeWindow(); + } + + void setWindowTitle(const std::string &title) + { + SetWindowTitle(title.c_str()); + } + + int getScreenWidth() + { + return GetScreenWidth(); + } + + int getScreenHeight() + { + return GetScreenHeight(); + } + + int getRenderWidth() + { + return GetRenderWidth(); + } + + int getRenderHeight() + { + return GetRenderHeight(); + } + + int getMonitorWidth(int monitor) + { + return GetMonitorWidth(monitor); + } + + int getMonitorHeight(int monitor) + { + return GetMonitorHeight(monitor); + } + + int getMonitorRefreshRate(int monitor) + { + return GetMonitorRefreshRate(monitor); + } + + int getCurrentMonitor() + { + return GetCurrentMonitor(); + } + + void setClipboardText(const std::string &text) + { + SetClipboardText(text.c_str()); + } + + std::string getClipboardText() + { + return GetClipboardText(); + } + + void setWindowIcon(Image icon) + { + ::Image image; + + image.data = icon.getData(); + image.width = icon.getWidth(); + image.height = icon.getHeight(); + image.mipmaps = icon.getMipmaps(); + image.format = icon.getFormat(); + SetWindowIcon(image); + } + + // Cursor-related functions + + void showCursor() + { + ShowCursor(); + } + + void hideCursor() + { + HideCursor(); + } + + bool isCursorHidden() + { + return IsCursorHidden(); + } + + void enableCursor() + { + EnableCursor(); + } + + void disableCursor() + { + DisableCursor(); + } + + bool isCursorOnScreen() + { + return IsCursorOnScreen(); + } + + // Drawing-related functions + + void clearBackground(Raylib::Color color) + { + ClearBackground({color.r, color.g, color.b, color.a}); + } + + void beginDrawing() + { + BeginDrawing(); + } + + void endDrawing() + { + EndDrawing(); + } + + // Timing-related functions + + void setTargetFPS(int fps) + { + SetTargetFPS(fps); + } + + int getFPS() + { + return GetFPS(); + } + + float getFrameTime() + { + return GetFrameTime(); + } + + double getTime() + { + return GetTime(); + } + + // Misc. functions + + void takeScreenshot(const std::string &fileName) + { + TakeScreenshot(fileName.c_str()); + } + + // Input-related functions: keyboard + + bool isKeyPressed(KeyboardKey key) + { + return IsKeyPressed(static_cast(key)); + } + + bool isKeyDown(KeyboardKey key) + { + return IsKeyDown(static_cast(key)); + } + + bool isKeyReleased(KeyboardKey key) + { + return IsKeyReleased(static_cast(key)); + } + + bool isKeyUp(KeyboardKey key) + { + return IsKeyUp(static_cast(key)); + } + + void setExitKey(KeyboardKey key) + { + SetExitKey(static_cast(key)); + } + + int getKeyPressed() + { + return GetKeyPressed(); + } + + int getCharPressed() + { + return GetCharPressed(); + } + + // Input-related functions: mouse + + bool isMouseButtonPressed(MouseButton button) + { + return IsMouseButtonPressed(static_cast(button)); + } + + bool isMouseButtonDown(MouseButton button) + { + return IsMouseButtonDown(static_cast(button)); + } + + bool isMouseButtonReleased(MouseButton button) + { + return IsMouseButtonReleased(static_cast(button)); + } + + bool isMouseButtonUp(MouseButton button) + { + return IsMouseButtonUp(static_cast(button)); + } + + Vector2 getMousePosition() + { + ::Vector2 position = GetMousePosition(); + return Vector2 {position.x, position.y}; + } + + int getMouseX() + { + return GetMouseX(); + } + + int getMouseY() + { + return GetMouseY(); + } + + void setMousePosition(int x, int y) + { + SetMousePosition(x, y); + } + + Vector2 getMouseDelta() + { + ::Vector2 delta = GetMouseDelta(); + return Vector2 {delta.x, delta.y}; + } + + void setMouseOffset(int offsetX, int offsetY) + { + SetMouseOffset(offsetX, offsetY); + } + + void setMouseScale(float scaleX, float scaleY) + { + SetMouseScale(scaleX, scaleY); + } + + float getMouseWheelMove() + { + return GetMouseWheelMove(); + } + + Vector2 getMouseWheelMoveV() + { + ::Vector2 move = GetMouseWheelMoveV(); + return Vector2 {move.x, move.y}; + } + + void setMouseCursor(int cursor) + { + SetMouseCursor(cursor); + } + + // Shapes-related functions + void drawPixel(int posX, int posY, Color color) + { + ::Color c = {color.r, color.g, color.b, color.a}; + + DrawPixel(posX, posY, c); + } + + void drawCircle(int centerX, int centerY, float radius, Color color) + { + ::Color c = {color.r, color.g, color.b, color.a}; + + DrawCircle(centerX, centerY, radius, c); + } + + void drawRectangle(int posX, int posY, int width, int height, Color color) + { + ::Color c = {color.r, color.g, color.b, color.a}; + + DrawRectangle(posX, posY, width, height, c); + } + + Image::Image(const std::string &fileName) + : _image(LoadImage(fileName.c_str())) + { + if (!isImageReady()) { + const ::Color badTexture = {255, 16, 240, 255}; + static constexpr int badImageSize = 50; + _image = GenImageColor(badImageSize, badImageSize, badTexture); + } + } + + Image::Image(int width, int height, Color color) + : _image( + GenImageColor(width, height, {color.r, color.g, color.b, color.a})) + { + } + + Image::~Image() + { + if (isImageReady()) { + unloadImage(); + } + } + + bool Image::isImageReady() + { + return IsImageReady(_image); + } + + void Image::unloadImage() + { + if (isImageReady()) { + UnloadImage(_image); + } + } + + int Image::getWidth() const + { + return _image.width; + } + + int Image::getHeight() const + { + return _image.height; + } + + int Image::getMipmaps() const + { + return _image.mipmaps; + } + + int Image::getFormat() const + { + return _image.format; + } + + void *Image::getData() const + { + return _image.data; + } + + // Texture functions + + Sprite::Sprite(const std::string &fileName, float width, float height) + : _texture(LoadTexture(fileName.c_str())), + _width(width), + _height(height) + { + if (!IsTextureReady(_texture)) { + static const ::Color badTexture = {255, 16, 240, 255}; + static constexpr int badImageSize = 50; + _texture = LoadTextureFromImage( + GenImageColor(badImageSize, badImageSize, badTexture)); + } + } + + Sprite::Sprite(Image image, float width, float height) + : _texture({0, 0, 0, 0}), + _width(width), + _height(height) + { + loadTextureFromImage(image); + } + + void Sprite::loadTextureFromImage(Image image) + { + ::Image img; + img.data = image.getData(); + img.width = image.getWidth(); + img.height = image.getHeight(); + img.mipmaps = image.getMipmaps(); + img.format = image.getFormat(); + _texture = LoadTextureFromImage(img); + } + + void Sprite::unloadSprite() + { + UnloadTexture(_texture); + } + + unsigned int Sprite::getId() const + { + return _texture.id; + } + + float Sprite::getWidth() const + { + return _width; + } + + float Sprite::getHeight() const + { + return _height; + } + + int Sprite::getTextureWidth() const + { + return _texture.width; + } + + int Sprite::getTextureHeight() const + { + return _texture.height; + } + + int Sprite::getMipmaps() const + { + return _texture.mipmaps; + } + + int Sprite::getFormat() const + { + return _texture.format; + } + + // Texture drawing functions + + void Sprite::draw(int posX, int posY, Color tint) + { + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTexture(_texture, posX, posY, tnt); + } + + void Sprite::drawV(Vector2 position, Color tint) + { + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTextureV(_texture, pos, tnt); + } + + void + Sprite::drawEx(Vector2 position, float rotation, float scale, Color tint) + { + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTextureEx(_texture, pos, rotation, scale, tnt); + } + + void Sprite::drawRec(Rectangle source, Vector2 position, Color tint) + { + ::Rectangle src = {source.x, source.y, source.width, source.height}; + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTextureRec(_texture, src, pos, tnt); + } + + void Sprite::drawPro( + Rectangle source, + Rectangle dest, + Vector2 origin, + float rotation, + Color tint) + { + ::Rectangle src = {source.x, source.y, source.width, source.height}; + ::Rectangle dst = {dest.x, dest.y, dest.width, dest.height}; + ::Vector2 org = {origin.x, origin.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTexturePro(_texture, src, dst, org, rotation, tnt); + } + + // Color/pixel related functions + Color fade(Color color, float alpha) + { + ::Color c = {color.r, color.g, color.b, color.a}; + ::Color f = Fade(c, alpha); + return Color {f.r, f.g, f.b, f.a}; + } + + int colorToInt(Color color) + { + ::Color c = {color.r, color.g, color.b, color.a}; + return ColorToInt(c); + } + + Vector4 colorNormalize(Color color) + { + ::Color c = {color.r, color.g, color.b, color.a}; + ::Vector4 v = ColorNormalize(c); + return Vector4 {v.x, v.y, v.z, v.w}; + } + + Color colorFromNormalized(Vector4 normalized) + { + ::Vector4 v = {normalized.x, normalized.y, normalized.z, normalized.w}; + ::Color c = ColorFromNormalized(v); + return Color {c.r, c.g, c.b, c.a}; + } + + Color getColor(unsigned int hexValue) + { + ::Color c = GetColor(hexValue); + return Color {c.r, c.g, c.b, c.a}; + } + + // Text functions + void + drawText(std::string text, int posX, int posY, int fontSize, Color color) + { + ::Color textColor = {color.r, color.g, color.b, color.a}; + + DrawText(text.c_str(), posX, posY, fontSize, textColor); + } + + void drawFPS(int posX, int posY) + { + DrawFPS(posX, posY); + } + + int measureText(const std::string text, int fontSize) + { + return MeasureText(text.c_str(), fontSize); + } + + Text::Text(std::string text, Vector2 position, float fontSize, Color color) + : _text(std::move(text)), + _position(position), + _fontSize(fontSize), + _color(color), + _pixelPosition(position), + _currentFontSize(fontSize) + { + } + + void Text::draw() + { + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + + DrawText( + _text.c_str(), + static_cast(_pixelPosition.x), + static_cast(_pixelPosition.y), + static_cast(_currentFontSize), + textColor); + } + + void Text::drawEx(float spacing) + { + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + + DrawTextEx( + GetFontDefault(), + _text.c_str(), + pos, + _currentFontSize, + spacing, + textColor); + } + + void Text::drawPro(Vector2 origin, float rotation, float spacing) + { + ::Vector2 textOrigin = {origin.x, origin.y}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + + DrawTextPro( + GetFontDefault(), + _text.c_str(), + pos, + textOrigin, + rotation, + _currentFontSize, + spacing, + textColor); + } + + float Text::x() const + { + return _position.x; + } + + float Text::y() const + { + return _position.y; + } + + float Text::getFontSize() const + { + return _fontSize; + } + + void Text::setFontSize(float fontSize) + { + _fontSize = fontSize; + } + + Vector2 Text::getPosition() const + { + return _position; + } + + void Text::setPixelPosition(Vector2 position) + { + _pixelPosition = position; + } + + void Text::setCurrentFontSize(float fontSize) + { + _currentFontSize = fontSize; + } + +} // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp new file mode 100644 index 00000000..f5b1a17f --- /dev/null +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -0,0 +1,217 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Graphics +*/ + +#pragma once + +#include +#include "raylib.h" +#include "Geometry.hpp" +#include "Inputs.hpp" + +namespace Raylib { + + enum class ConfigFlags { + VSYNC_HINT = FLAG_VSYNC_HINT, + FULLSCREEN_MODE = FLAG_FULLSCREEN_MODE, + WINDOW_RESIZABLE = FLAG_WINDOW_RESIZABLE, + WINDOW_UNDECORATED = FLAG_WINDOW_UNDECORATED, + WINDOW_HIDDEN = FLAG_WINDOW_HIDDEN, + WINDOW_MINIMIZED = FLAG_WINDOW_MINIMIZED, + WINDOW_MAXIMIZED = FLAG_WINDOW_MAXIMIZED, + WINDOW_UNFOCUSED = FLAG_WINDOW_UNFOCUSED, + WINDOW_TOPMOST = FLAG_WINDOW_TOPMOST, + WINDOW_ALWAYS_RUN = FLAG_WINDOW_ALWAYS_RUN, + WINDOW_TRANSPARENT = FLAG_WINDOW_TRANSPARENT, + WINDOW_HIGHDPI = FLAG_WINDOW_HIGHDPI, + WINDOW_MOUSE_PASSTHROUGH = FLAG_WINDOW_MOUSE_PASSTHROUGH, + MSAA_4X_HINT = FLAG_MSAA_4X_HINT, + INTERLACED_HINT = FLAG_INTERLACED_HINT, + }; + + // Window-related functions + void initWindow(int width, int height, const std::string &title); + bool windowShouldClose(); + void closeWindow(); + bool isWindowReady(); + bool isWindowFullscreen(); + bool isWindowHidden(); + bool isWindowMinimized(); + bool isWindowMaximized(); + bool isWindowFocused(); + void setConfigFlags(ConfigFlags flags); + bool isWindowResized(); + bool isWindowState(ConfigFlags flag); + void setWindowState(ConfigFlags flag); + void clearWindowState(ConfigFlags flags); + void toggleFullscreen(); + void maximizeWindow(); + void minimizeWindow(); + void setWindowTitle(const std::string &title); + int getScreenWidth(); + int getScreenHeight(); + int getRenderWidth(); + int getRenderHeight(); + int getMonitorWidth(int monitor); + int getMonitorHeight(int monitor); + int getMonitorRefreshRate(int monitor); + int getCurrentMonitor(); + void setClipboardText(const std::string &text); + std::string getClipboardText(); + void setWindowIcon(Image image); + + // Cursor-related functions + void showCursor(); + void hideCursor(); + bool isCursorHidden(); + void enableCursor(); + void disableCursor(); + bool isCursorOnScreen(); + + // Drawing-related functions + void clearBackground(Raylib::Color color); + void beginDrawing(); + void endDrawing(); + + // Timing-related functions + void setTargetFPS(int fps); + int getFPS(); + float getFrameTime(); + double getTime(); + + // Misc. functions + void takeScreenshot(const std::string &fileName); + + // Input-related functions: keyboard + bool isKeyPressed(KeyboardKey key); + bool isKeyDown(KeyboardKey key); + bool isKeyReleased(KeyboardKey key); + bool isKeyUp(KeyboardKey key); + void setExitKey(KeyboardKey key); + int getKeyPressed(); + int getCharPressed(); + + // Input-related functions: mouse + bool isMouseButtonPressed(MouseButton button); + bool isMouseButtonDown(MouseButton button); + bool isMouseButtonReleased(MouseButton button); + bool isMouseButtonUp(MouseButton button); + int getMouseX(); + int getMouseY(); + Vector2 getMousePosition(); + Vector2 getMouseDelta(); + void setMousePosition(int x, int y); + void setMouseOffset(int offsetX, int offsetY); + void setMouseScale(float scaleX, float scaleY); + float getMouseWheelMove(); + Vector2 getMouseWheelMoveV(); + void setMouseCursor(int cursor); + + // Shapes-related functions + void drawPixel(int posX, int posY, Color color); + void drawCircle(int centerX, int centerY, float radius, Color color); + void drawRectangle(int posX, int posY, int width, int height, Color color); + + // Color/pixel related functions + Color fade(Color color, float alpha); + int colorToInt(Color color); + Vector4 colorNormalize(Color color); + Color colorFromNormalized(Vector4 normalized); + Color getColor(unsigned int hexValue); + + // Graphic classes + + class Image { + public: + Image(const std::string &fileName); + Image(int width, int height, Color color); + ~Image(); + bool isImageReady(); + void unloadImage(); + int getWidth() const; + int getHeight() const; + int getMipmaps() const; + int getFormat() const; + void *getData() const; + + private: + ::Image _image; + }; + + class Sprite { + public: + Sprite(const std::string &fileName, float width, float height); + Sprite(Image image, float width, float height); + unsigned int getId() const; + float getWidth() const; + float getHeight() const; + int getTextureWidth() const; + int getTextureHeight() const; + int getMipmaps() const; + int getFormat() const; + void unloadSprite(); + + // draw texture functions + + void draw(int posX, int posY, Color tint); + void drawV(Raylib::Vector2 position, Color tint); + void drawEx( + Raylib::Vector2 position, + float rotation, + float scale, + Color tint); + void drawRec( + Raylib::Rectangle source, + Raylib::Vector2 position, + Color tint); + void drawPro( + Rectangle source, + Rectangle dest, + Vector2 origin, + float rotation, + Color tint); + + private: + void loadTextureFromImage(Image image); + ::Texture2D _texture; + // width and height in percentage of the screen + float _width; + float _height; + }; + + // Text functions and classes + + class Text { + public: + Text( + std::string text, + Vector2 position = {0, 0}, + float fontSize = 5.0F, + Color color = BLACK); + void draw(); + void drawEx(float spacing); + void drawPro(Vector2 origin, float rotation, float spacing); + + float x() const; + float y() const; + float getFontSize() const; + void setFontSize(float fontSize); + Vector2 getPosition() const; + void setPixelPosition(Vector2 position); + void setCurrentFontSize(float fontSize); + + private: + std::string _text; + float _fontSize; + float _currentFontSize; + Color _color; + Vector2 _position; + Vector2 _pixelPosition; + }; + + void drawFPS(int posX, int posY); + +} // namespace Raylib diff --git a/src/Client/Raylib/Raylib.hpp b/src/Client/Raylib/Raylib.hpp new file mode 100644 index 00000000..acc6bb80 --- /dev/null +++ b/src/Client/Raylib/Raylib.hpp @@ -0,0 +1,13 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Raylib +*/ + +#pragma once + +#include "Audio.hpp" +#include "Geometry.hpp" +#include "Graphics.hpp" +#include "Inputs.hpp" diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp new file mode 100644 index 00000000..9e73f6ec --- /dev/null +++ b/src/Client/SceneManager.cpp @@ -0,0 +1,102 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SceneManager implementation +*/ + +#include "SceneManager.hpp" +#include +#include "ClientSystems.hpp" +#include "Raylib.hpp" +#include "Registry.hpp" +#include "SystemManagersDirector.hpp" + +#include "CustomTypes.hpp" + +constexpr int screenWidth = 1920; +constexpr int screenHeight = 1080; + +// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) +bool SceneManager::_init = false; +SceneManager SceneManager::_instance = SceneManager(); +// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + +static void initRaylib() +{ + Raylib::initWindow(screenWidth, screenHeight, "R-Bus"); + Raylib::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE); + Raylib::setTargetFPS( + Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor())); + Raylib::initAudioDevice(); +} + +static void initSystemManagers() +{ + auto &director = Systems::SystemManagersDirector::getInstance(); + + for (auto systems : Systems::getSystemsGroups()) { + director.addSystemManager(systems); + } + initRaylib(); +} + +SceneManager &SceneManager::getInstance() +{ + if (!_init) { + _init = true; + initSystemManagers(); + } + return _instance; +} + +SceneManager::SceneManager() : _currentScene(Scene::MENU), _stop(false) +{ +} + +static void destroyRaylib() +{ + Raylib::closeAudioDevice(); + Raylib::closeWindow(); +} + +int SceneManager::run() +{ + auto &director = Systems::SystemManagersDirector::getInstance(); + + try { + Registry::getInstance().initCustomSparseArrays( + _scenesCustomIndexes.at(_currentScene)); + while (!_stop && !Raylib::windowShouldClose()) { + Raylib::beginDrawing(); + Raylib::clearBackground(Raylib::DarkGray); + auto scene = _scenes.at(_currentScene); + for (auto &systemManager : scene) { + director.getSystemManager(systemManager).updateSystems(); + } + Raylib::endDrawing(); + } + destroyRaylib(); + } catch (std::exception &e) { + std::cout << e.what() << std::endl; + return ReturnValue::ERROR; + } + return ReturnValue::OK; +} + +void SceneManager::changeScene(Scene scene) +{ + _currentScene = scene; + Registry::getInstance().clear(_scenesCustomIndexes.at(_currentScene)); + Systems::SystemManagersDirector::getInstance().resetChanges(); +} + +Scene SceneManager::getCurrentScene() const +{ + return _currentScene; +} + +void SceneManager::stop() +{ + _stop = true; +} diff --git a/src/Client/SceneManager.hpp b/src/Client/SceneManager.hpp new file mode 100644 index 00000000..133352f2 --- /dev/null +++ b/src/Client/SceneManager.hpp @@ -0,0 +1,50 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SceneManager +*/ + +#pragma once + +#include +#include +#include +#include +#include + +enum CustomIndex { BULLET, PLAYER, ENNEMY }; + +enum ReturnValue { OK = 0, ERROR = 84 }; + +enum Scene { MENU, MAIN_GAME, SCENE_MAX }; + +enum SystemManagers { GAME, EVENTS, DISPLAY }; + +class SceneManager { + public: + static SceneManager &getInstance(); + int run(); + void changeScene(Scene scene); + Scene getCurrentScene() const; + void stop(); + + private: + SceneManager(); + + Scene _currentScene; + bool _stop; + const std::array, 2> _scenes = { + std::vector {EVENTS, GAME, DISPLAY}, + std::vector {EVENTS, GAME, DISPLAY} + }; + const std::array, 2> _scenesCustomIndexes = { + std::vector {PLAYER }, + std::vector { PLAYER, BULLET, ENNEMY} + }; + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + static bool _init; + static SceneManager _instance; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) +}; diff --git a/src/Client/Systems/CMakeLists.txt b/src/Client/Systems/CMakeLists.txt index c4e93bfa..d5d25423 100644 --- a/src/Client/Systems/CMakeLists.txt +++ b/src/Client/Systems/CMakeLists.txt @@ -1,15 +1,16 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ClientSystems.cpp ) -add_subdirectory(Managers) +add_subdirectory(Graphic) +add_subdirectory(Events) diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 52dbdd36..115584f4 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -2,39 +2,18 @@ ** EPITECH PROJECT, 2023 ** R-Bus ** File description: -** Systems implementation +** ClientSystems */ -#include -#include "raylib.h" #include "ClientSystems.hpp" -#include "Registry.hpp" -#include "CustomTypes.hpp" -void GraphicSystems::pixelRenderer(std::size_t) -{ - Registry::components arrPixel = Registry::getInstance().getComponents(); - for (auto begin = arrPixel.begin(); begin != arrPixel.end(); begin++) { - for (int i = 0; i < 50; i++) { - for (int j = 0; j < 50 ; j++) { - DrawPixel(begin->x + i, begin->y + j, PURPLE); - } - } +namespace Systems { + std::array>, 3> + getSystemsGroups() + { + return { + getECSSystems(), + EventsSystems::getEventSystems(), + GraphicSystems::getGraphicsSystems()}; } -} - -void EventsSystems::playerMovement(std::size_t) -{ - Registry::components arrPixel = Registry::getInstance().getComponents(); - - for (auto &pixel : arrPixel) { - if (IsKeyDown(KEY_RIGHT)) - pixel.x += 1; - if (IsKeyDown(KEY_LEFT)) - pixel.x -= 1; - if (IsKeyDown(KEY_UP)) - pixel.y -= 1; - if (IsKeyDown(KEY_DOWN)) - pixel.y += 1; - } -} +} // namespace Systems diff --git a/src/Client/Systems/ClientSystems.hpp b/src/Client/Systems/ClientSystems.hpp index 0f4980eb..aeca2770 100644 --- a/src/Client/Systems/ClientSystems.hpp +++ b/src/Client/Systems/ClientSystems.hpp @@ -2,15 +2,17 @@ ** EPITECH PROJECT, 2023 ** R-Bus ** File description: -** Systems +** ClientSystems */ #pragma once -namespace GraphicSystems { - void pixelRenderer(std::size_t); -} +#include +#include "EventsSystems.hpp" +#include "GraphicSystems.hpp" +#include "Systems.hpp" -namespace EventsSystems { - void playerMovement(std::size_t); -} +namespace Systems { + std::array>, 3> + getSystemsGroups(); +} // namespace Systems diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp new file mode 100644 index 00000000..8bfe60c5 --- /dev/null +++ b/src/Client/Systems/CustomTypes.hpp @@ -0,0 +1,36 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Custom Types +*/ + +#pragma once + +#include + +namespace Types { + + struct Rect { + float x; + float y; + float width; + float height; + }; + + struct Position { + float x; + float y; + }; + + struct RectangleShape { + float width; + float height; + }; + + struct CollisionRect { + float width; + float height; + }; + +} // namespace Types diff --git a/src/Client/Systems/Events/CMakeLists.txt b/src/Client/Systems/Events/CMakeLists.txt new file mode 100644 index 00000000..c5f363c5 --- /dev/null +++ b/src/Client/Systems/Events/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/EventsSystems.cpp +) diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp new file mode 100644 index 00000000..c663d127 --- /dev/null +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -0,0 +1,62 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** EventsSystems implementation +*/ + +#include "EventsSystems.hpp" +#include "CustomTypes.hpp" +#include "Raylib.hpp" +#include "Registry.hpp" +#include "SceneManager.hpp" + +namespace Systems { + void EventsSystems::playerMovement( + std::size_t /*unused*/, + std::size_t /*unused*/) + { + Registry::components arrPosition = + Registry::getInstance().getComponents(); + + SparseArray &playerId = + Registry::getInstance().getCustomSparseArray( + CustomIndex::PLAYER); + + for (std::optional id : playerId) { + if (id.has_value() && arrPosition[id.value()].has_value()) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) { + arrPosition[id.value()].value().x += 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) { + arrPosition[id.value()].value().x -= 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) { + arrPosition[id.value()].value().y -= 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) { + arrPosition[id.value()].value().y += 1; + } + } + } + } + + void + EventsSystems::changeScene(std::size_t /*unused*/, std::size_t /*unused*/) + { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_J)) { + SceneManager &sceneManager = SceneManager::getInstance(); + if (sceneManager.getCurrentScene() == MAIN_GAME) { + sceneManager.changeScene(MENU); + } else { + sceneManager.changeScene(MAIN_GAME); + } + } + } + + std::vector> + EventsSystems::getEventSystems() + { + return {playerMovement, changeScene}; + } +} // namespace Systems diff --git a/src/Client/Systems/Events/EventsSystems.hpp b/src/Client/Systems/Events/EventsSystems.hpp new file mode 100644 index 00000000..fd2edf2f --- /dev/null +++ b/src/Client/Systems/Events/EventsSystems.hpp @@ -0,0 +1,21 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** EventsSystems +*/ + +#pragma once + +#include +#include +#include + +namespace Systems { + namespace EventsSystems { + void playerMovement(std::size_t /*unused*/, std::size_t /*unused*/); + void changeScene(std::size_t /*unused*/, std::size_t /*unused*/); + std::vector> + getEventSystems(); + } // namespace EventsSystems +} // namespace Systems diff --git a/src/Client/Systems/Graphic/CMakeLists.txt b/src/Client/Systems/Graphic/CMakeLists.txt new file mode 100644 index 00000000..9aa72ba0 --- /dev/null +++ b/src/Client/Systems/Graphic/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/GraphicSystems.cpp +) diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp new file mode 100644 index 00000000..17d511ab --- /dev/null +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -0,0 +1,258 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** GraphicSystems +*/ + +#include "GraphicSystems.hpp" +#include "CustomTypes.hpp" +#include "Raylib.hpp" +#include "Registry.hpp" + +namespace Systems { + void + GraphicSystems::rectRenderer(std::size_t /*unused*/, std::size_t /*unused*/) + { + Registry::components arrPosition = + Registry::getInstance().getComponents(); + Registry::components arrRect = + Registry::getInstance().getComponents(); + + const float denominator = 100.0; + + auto positionIt = arrPosition.begin(); + auto rectIt = arrRect.begin(); + + while (positionIt != arrPosition.end() && rectIt != arrRect.end()) { + if (positionIt->has_value() && rectIt->has_value()) { + Types::Position &position = positionIt->value(); + Types::RectangleShape &rectangle = rectIt->value(); + + float x = + (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = + (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; + + float width = (rectangle.width + * static_cast(Raylib::getScreenWidth())) + / denominator; + float height = (rectangle.height + * static_cast(Raylib::getScreenHeight())) + / denominator; + + DrawRectangle( + static_cast(x), + static_cast(y), + static_cast(width), + static_cast(height), + PURPLE); + } + positionIt++; + rectIt++; + } + } + + static void + drawSpriteWithoutRect(Types::Position &position, Raylib::Sprite &sprite) + { + float scale = 1.0F; + float rotation = 0; + const Raylib::Color tint = Raylib::White; + Raylib::Vector2 spritePos = {0, 0}; + const float denominator = 100.0; + + float x = (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; + + scale = + (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) + / denominator / static_cast(sprite.getTextureWidth()); + spritePos = {x, y}; + + sprite.drawEx(spritePos, rotation, scale, tint); + } + + static void drawSpriteWithRect( + Types::Position &position, + Raylib::Sprite &sprite, + Types::Rect &rect) + { + Raylib::Vector2 origin = {0, 0}; + float rotation = 0; + const Raylib::Color tint = Raylib::White; + const float denominator = 100.0; + + float x = (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; + + float width = + (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) + / denominator; + float height = + (sprite.getHeight() * static_cast(Raylib::getScreenHeight())) + / denominator; + + sprite.drawPro( + Raylib::Rectangle(rect.x, rect.y, rect.width, rect.height), + Raylib::Rectangle(x, y, width, height), + origin, + rotation, + tint); + } + + void GraphicSystems::spriteRenderer( + std::size_t /*unused*/, + std::size_t /*unused*/) + { + Registry::components arrSprite = + Registry::getInstance().getComponents(); + Registry::components arrRect = + Registry::getInstance().getComponents(); + Registry::components arrPosition = + Registry::getInstance().getComponents(); + + auto positionIt = arrPosition.begin(); + auto spriteIt = arrSprite.begin(); + auto rectIt = arrRect.begin(); + + while (positionIt != arrPosition.end() && spriteIt != arrSprite.end()) { + if (positionIt->has_value() && spriteIt->has_value() + && rectIt->has_value()) { + drawSpriteWithRect( + positionIt->value(), + spriteIt->value(), + rectIt->value()); + } else if (positionIt->has_value() && spriteIt->has_value()) { + drawSpriteWithoutRect(positionIt->value(), spriteIt->value()); + } + positionIt++; + spriteIt++; + rectIt++; + } + } + + void GraphicSystems::soundEffectPlayer( + std::size_t /*unused*/, + std::size_t /*unused*/) + { + Registry::components arrSoundEffect = + Registry::getInstance().getComponents(); + + for (auto &soundEffect : arrSoundEffect) { + if (!soundEffect.has_value()) { + continue; + } + if (soundEffect.value().NeedToPlay()) { + soundEffect.value().play(); + soundEffect.value().setNeedToPlay(false); + } + } + } + + void + GraphicSystems::musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/) + { + Registry::components arrMusics = + Registry::getInstance().getComponents(); + + for (auto &music : arrMusics) { + if (!music.has_value()) { + continue; + } + if (music.value().NeedToPlay()) { + music.value().play(); + music.value().setNeedToPlay(false); + } + if (music.value().isPlaying()) { + music.value().update(); + } + } + } + + static void drawTextResponsive(Raylib::Text &text) + { + const float denominator = 100.0; + + float x = + (text.x() * static_cast(GetScreenWidth())) / denominator; + float y = + (text.y() * static_cast(GetScreenHeight())) / denominator; + float fsz = (text.getFontSize() * static_cast(GetScreenWidth())) + / denominator; + + text.setPixelPosition({x, y}); + text.setCurrentFontSize(fsz); + text.draw(); + } + + void + GraphicSystems::textRenderer(std::size_t /*unused*/, std::size_t /*unused*/) + { + Registry::components arrText = + Registry::getInstance().getComponents(); + + auto textIt = arrText.begin(); + + while (textIt != arrText.end()) { + if (textIt->has_value()) { + drawTextResponsive(textIt->value()); + } + textIt++; + } + } + + const std::string musicPath = "assets/Audio/Musics/Title.mp3"; + const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; + const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; + const Types::Rect spriteRect = {2, 2, 48, 48}; + const Types::CollisionRect collisionRect = {46, 46}; + const Raylib::Vector2 textPos = {20, 50}; + + void GraphicSystems::playSoundWithKey( + std::size_t /*unused*/, + std::size_t /*unused*/) + { + Registry::components arrMusics = + Registry::getInstance().getComponents(); + Registry::components arrSounds = + Registry::getInstance().getComponents(); + + for (auto &music : arrMusics) { + if (!music.has_value()) { + continue; + } + if (music.value().getPath() == musicPath + && Raylib::isKeyPressed(Raylib::KeyboardKey::KB_SPACE)) { + music.value().setNeedToPlay(true); + } + } + for (auto &sound : arrSounds) { + if (!sound.has_value()) { + continue; + } + if (sound.value().getPath() == soundPath + && Raylib::isKeyPressed(Raylib::KeyboardKey::KB_ENTER)) { + sound.value().setNeedToPlay(true); + } + } + } + + std::vector> + GraphicSystems::getGraphicsSystems() + { + return { + rectRenderer, + spriteRenderer, + textRenderer, + musicPlayer, + soundEffectPlayer, + playSoundWithKey}; + } +} // namespace Systems diff --git a/src/Client/Systems/Graphic/GraphicSystems.hpp b/src/Client/Systems/Graphic/GraphicSystems.hpp new file mode 100644 index 00000000..8e08dfad --- /dev/null +++ b/src/Client/Systems/Graphic/GraphicSystems.hpp @@ -0,0 +1,25 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** GraphicSystems +*/ + +#pragma once + +#include +#include +#include + +namespace Systems { + namespace GraphicSystems { + void rectRenderer(std::size_t /*unused*/, std::size_t /*unused*/); + void spriteRenderer(std::size_t /*unused*/, std::size_t /*unused*/); + void textRenderer(std::size_t /*unused*/, std::size_t /*unused*/); + void soundEffectPlayer(std::size_t /*unused*/, std::size_t /*unused*/); + void musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/); + void playSoundWithKey(std::size_t, std::size_t); + std::vector> + getGraphicsSystems(); + } // namespace GraphicSystems +} // namespace Systems diff --git a/src/Client/Systems/Managers/CMakeLists.txt b/src/Client/Systems/Managers/CMakeLists.txt deleted file mode 100644 index 2815cd3b..00000000 --- a/src/Client/Systems/Managers/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -target_include_directories( - ${PROJECT_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_sources( - ${PROJECT_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/GraphicManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/SystemEventsManager.cpp -) diff --git a/src/Client/Systems/Managers/GraphicManager.cpp b/src/Client/Systems/Managers/GraphicManager.cpp deleted file mode 100644 index 4bfa942c..00000000 --- a/src/Client/Systems/Managers/GraphicManager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** GraphicManager -*/ - -#include -#include "raylib.h" -#include "GraphicManager.hpp" -#include "CustomTypes.hpp" -#include "ClientSystems.hpp" - -namespace Systems { - GraphicManager GraphicManager::_instance = GraphicManager(); - - GraphicManager::GraphicManager() - { - const int screenWidth = 800; - const int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "Poc ECS"); - SetTargetFPS(60); - - addSystem(GraphicSystems::pixelRenderer); - } - - GraphicManager::~GraphicManager() - { - CloseWindow(); - } - - GraphicManager &GraphicManager::getInstance() - { - return _instance; - } - - void GraphicManager::updateSystems() - { - BeginDrawing(); - ClearBackground(RAYWHITE); - ASystemManager::updateSystems(); - EndDrawing(); - } - - void GraphicManager::addSystem(std::function sys) - { - ASystemManager::addSystem(sys); - } - - void GraphicManager::removeSystem(std::size_t id) - { - ASystemManager::removeSystem(id); - } -} diff --git a/src/Client/Systems/Managers/GraphicManager.hpp b/src/Client/Systems/Managers/GraphicManager.hpp deleted file mode 100644 index 06ed57df..00000000 --- a/src/Client/Systems/Managers/GraphicManager.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** GraphicManager -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class GraphicManager : public ASystemManager { - public: - static GraphicManager &getInstance(); - void updateSystems(); - void addSystem(std::function); - void removeSystem(std::size_t); - private: - GraphicManager(); - ~GraphicManager(); - static GraphicManager _instance; - }; -} diff --git a/src/Client/Systems/Managers/SystemEventsManager.cpp b/src/Client/Systems/Managers/SystemEventsManager.cpp deleted file mode 100644 index 8a4f7ce9..00000000 --- a/src/Client/Systems/Managers/SystemEventsManager.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** SystemEventsManager -*/ - -#include -#include "SystemEventsManager.hpp" -#include "CustomTypes.hpp" -#include "ClientSystems.hpp" - -namespace Systems { - SystemEventsManager SystemEventsManager::_instance = SystemEventsManager(); - - SystemEventsManager::SystemEventsManager() - { - addSystem(EventsSystems::playerMovement); - } - - SystemEventsManager &SystemEventsManager::getInstance() - { - return _instance; - } - - void SystemEventsManager::updateSystems() - { - ASystemManager::updateSystems(); - } - - void SystemEventsManager::addSystem(std::function sys) - { - ASystemManager::addSystem(sys); - } - - void SystemEventsManager::removeSystem(std::size_t id) - { - ASystemManager::removeSystem(id); - } -} diff --git a/src/Client/Systems/Managers/SystemEventsManager.hpp b/src/Client/Systems/Managers/SystemEventsManager.hpp deleted file mode 100644 index f510360b..00000000 --- a/src/Client/Systems/Managers/SystemEventsManager.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** SystemEventsManager -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class SystemEventsManager : public ASystemManager { - public: - static SystemEventsManager &getInstance(); - void updateSystems(); - void addSystem(std::function); - void removeSystem(std::size_t); - private: - SystemEventsManager(); - static SystemEventsManager _instance; - }; -} diff --git a/src/ECS/CMakeLists.txt b/src/ECS/CMakeLists.txt index 8bdb7f9f..e0d65fbe 100644 --- a/src/ECS/CMakeLists.txt +++ b/src/ECS/CMakeLists.txt @@ -1,16 +1,15 @@ cmake_minimum_required(VERSION 3.15) -add_subdirectory(EventManager) add_subdirectory(Systems) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Registry.cpp ) diff --git a/src/ECS/CustomTypes.hpp b/src/ECS/CustomTypes.hpp deleted file mode 100644 index 2ce48422..00000000 --- a/src/ECS/CustomTypes.hpp +++ /dev/null @@ -1,11 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** Custom Types -*/ - -struct Pixel { - int x; - int y; -}; diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp new file mode 100644 index 00000000..7c15c4a5 --- /dev/null +++ b/src/ECS/ECSCustomTypes.hpp @@ -0,0 +1,29 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Custom Types +*/ + +#pragma once + +// all values are in percentage of the screen + +namespace Types { + + struct CollisionRect { + float width; + float height; + }; + + struct RectangleShape { + float width; + float height; + }; + + struct Position { + float x; + float y; + }; + +} // namespace Types diff --git a/src/ECS/EventManager/EventManager.hpp b/src/ECS/EventManager/EventManager.hpp deleted file mode 100644 index b2880cec..00000000 --- a/src/ECS/EventManager/EventManager.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** EventManager -*/ - -#pragma once - -#include - -class EventManager { - public: - static EventManager &getInstance(); - void updateEvents(); - bool checkEvent(int event); - private: - EventManager() = default; - - static EventManager instance; - std::list _activeEvents; -}; diff --git a/src/ECS/EventManager/Events.hpp b/src/ECS/EventManager/Events.hpp deleted file mode 100644 index e34c6a13..00000000 --- a/src/ECS/EventManager/Events.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** Events -*/ - -#pragma once - -#include -#include -#include "raylib.h" - -namespace Events { - static const std::array events = { - KEY_LEFT, - KEY_RIGHT, - KEY_UP, - KEY_DOWN - }; -} diff --git a/src/ECS/Registry.cpp b/src/ECS/Registry.cpp index 83682db2..6eb34ba5 100644 --- a/src/ECS/Registry.cpp +++ b/src/ECS/Registry.cpp @@ -6,10 +6,66 @@ */ #include "Registry.hpp" +#include +// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) Registry Registry::_instance = Registry(); +// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) -Registry &Registry::getInstance() { +Registry &Registry::getInstance() +{ return _instance; } +void Registry::addEntity() +{ + for (auto function : _addComponentPlaceFunctions) { + function(*this); + } + _entitiesNb++; +} + +void Registry::removeEntity(std::size_t id) +{ + for (auto function : _removeComponentFunctions) { + function(*this, id); + } +} + +void Registry::clear(std::vector indexes) +{ + _data.clear(); + _addComponentPlaceFunctions.clear(); + _removeComponentFunctions.clear(); + _entitiesNb = 0; + _customSparseArrays.clear(); + initCustomSparseArrays(indexes); +} + +std::size_t Registry::getEntitiesNb() const +{ + return (_entitiesNb); +} + +void Registry::initCustomSparseArrays(std::vector indexes) +{ + for (auto index : indexes) { + addCustomSparseIndex(static_cast(index)); + } +} + +Registry::Registry() : _entitiesNb(0), _maxCustomId(0) +{ +} + +void Registry::addCustomSparseIndex(std::size_t id) +{ + if (_customSparseArrays.find(id) != _customSparseArrays.end()) { + throw std::runtime_error( + "addCustomSparseIndex: id" + std::to_string(id) + " already exist"); + }; + _customSparseArrays[id] = SparseArray(); + if (id > _maxCustomId) { + _maxCustomId = id; + } +} diff --git a/src/ECS/Registry.hpp b/src/ECS/Registry.hpp index c3c94726..176e64b7 100644 --- a/src/ECS/Registry.hpp +++ b/src/ECS/Registry.hpp @@ -8,15 +8,18 @@ #pragma once #include -#include +#include +#include +#include +#include #include +#include #include -#include -#include +#include +#include "SceneManager.hpp" #include "SparseArray.hpp" class Registry { - public: template using components = SparseArray &; @@ -24,35 +27,107 @@ class Registry { static Registry &getInstance(); template - components registerComponent() + components getComponents() { - if (_data.find(typeid(Component)) == _data.end()) { - _data[typeid(Component)] = SparseArray(); - } + checkAddSparseArray(); return castReturn(); } + void addEntity(); + + void removeEntity(std::size_t /*id*/); + + void clear(std::vector); + template - components getComponents() + components getCustomSparseArray(std::size_t id) { - return castReturn(); + if (_customSparseArrays.find(id) == _customSparseArrays.end()) { + throw std::runtime_error( + "getCustomSparseArray ID not in :" + std::to_string(id)); + } + try { + components castedComponent = + std::any_cast>( + _customSparseArrays[id]); + + return castedComponent; + } catch (const std::bad_any_cast &e) { + throw std::runtime_error("Bad cast: " + std::string(e.what())); + } } template - components const &getComponents() const + std::size_t addCustomSparseArray() { - return castReturn(); + _maxCustomId++; + std::size_t id = _maxCustomId; + + _customSparseArrays[id] = SparseArray(); + return (id); } + + std::size_t getEntitiesNb() const; + + void initCustomSparseArrays(std::vector indexes); + + Registry &operator=(const Registry &) = delete; + Registry(const Registry &) = delete; + void operator=(const Registry &&) = delete; + Registry(Registry &&) = delete; + private: - Registry() = default; + Registry(); + + template + void checkAddSparseArray() + { + if (_data.find(typeid(Component)) == _data.end()) { + _data[typeid(Component)] = SparseArray(); + _addComponentPlaceFunctions.push_back( + &Registry::addComponentPlace); + _removeComponentFunctions.push_back( + &Registry::removeComponent); + components componentArray = castReturn(); + for (std::size_t i = 0; i < _entitiesNb; i++) { + componentArray.add(); + } + } + } - template + template + void addComponentPlace() + { + castReturn().add(); + } + + template + void removeComponent(std::size_t id) + { + castReturn().erase(id); + } + + template components castReturn() { - return std::any_cast>(_data[typeid(Component)]); + return std::any_cast>( + _data[typeid(Component)]); } + void addCustomSparseIndex(std::size_t id); + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) static Registry _instance; - Registry& operator=(const Registry&) = delete; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + + std::vector> + _addComponentPlaceFunctions; + std::vector> + _removeComponentFunctions; std::unordered_map _data; + + std::unordered_map _customSparseArrays; + std::size_t _maxCustomId; + + std::size_t _entitiesNb; }; diff --git a/src/ECS/SparseArray.hpp b/src/ECS/SparseArray.hpp index 54d28e12..fa368e21 100644 --- a/src/ECS/SparseArray.hpp +++ b/src/ECS/SparseArray.hpp @@ -8,35 +8,45 @@ #pragma once #include -#include +#include +#include template class SparseArray { public: - void add(Component component) + void add() { - _components.push_back(component); - }; - void erase(int id) + _components.push_back(std::nullopt); + } + void erase(std::size_t id) { auto it = _components.begin(); std::advance(it, id); _components.erase(it); }; - Component &operator[](size_t idx) + std::optional &operator[](size_t idx) { return _components[idx]; } - std::list::iterator begin() + typename std::vector>::iterator begin() { return _components.begin(); } - std::list::iterator end() + typename std::vector>::iterator end() { return _components.end(); } + std::optional &back() + { + return _components.back(); + } + std::size_t size() + { + return _components.size(); + } + private: - std::list _components; + std::vector> _components; }; diff --git a/src/ECS/Systems/CMakeLists.txt b/src/ECS/Systems/CMakeLists.txt index 2c7ca509..1e6e8037 100644 --- a/src/ECS/Systems/CMakeLists.txt +++ b/src/ECS/Systems/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Systems.cpp diff --git a/src/ECS/Systems/Managers/ASystemManager.cpp b/src/ECS/Systems/Managers/ASystemManager.cpp deleted file mode 100644 index 6b7b235d..00000000 --- a/src/ECS/Systems/Managers/ASystemManager.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager implementation -*/ - -#include "ASystemManager.hpp" - -namespace Systems { - void ASystemManager::updateSystems() - { - std::size_t i = 0; - - for (auto &system : _systems) { - system(i); - i++; - } - } - - void ASystemManager::addSystem(std::function sys) - { - _systems.push_back(sys); - } - - void ASystemManager::removeSystem(std::size_t id) - { - auto it = _systems.begin(); - std::advance(it, id); - _systems.erase(it); - } -} diff --git a/src/ECS/Systems/Managers/ASystemManager.hpp b/src/ECS/Systems/Managers/ASystemManager.hpp deleted file mode 100644 index afc92a83..00000000 --- a/src/ECS/Systems/Managers/ASystemManager.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager -*/ - - -#pragma once - -#include -#include -#include -#include - -namespace Systems { - class ASystemManager { - protected: - ASystemManager() = default; - - void updateSystems(); - - void addSystem(std::function); - - void removeSystem(std::size_t); - - std::list> _systems; - }; -} diff --git a/src/ECS/Systems/Managers/CMakeLists.txt b/src/ECS/Systems/Managers/CMakeLists.txt index b5c98302..c594fa4b 100644 --- a/src/ECS/Systems/Managers/CMakeLists.txt +++ b/src/ECS/Systems/Managers/CMakeLists.txt @@ -1,15 +1,15 @@ cmake_minimum_required(VERSION 3.15) target_include_directories( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) target_sources( - ${PROJECT_NAME} + ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/ASystemManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/GameManager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SystemManagersDirector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager.cpp ) diff --git a/src/ECS/Systems/Managers/GameManager.cpp b/src/ECS/Systems/Managers/GameManager.cpp deleted file mode 100644 index 87fecdb4..00000000 --- a/src/ECS/Systems/Managers/GameManager.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager implementation -*/ - -#include "GameManager.hpp" -#include "Systems.hpp" - -namespace Systems { - GameManager GameManager::_instance = GameManager(); - - GameManager::GameManager() - { - addSystem(Systems::collision); - } - - GameManager &GameManager::getInstance() - { - return _instance; - } - - void GameManager::updateSystems() - { - ASystemManager::updateSystems(); - } - - void GameManager::addSystem(std::function sys) - { - ASystemManager::addSystem(sys); - } - - void GameManager::removeSystem(std::size_t id) - { - ASystemManager::removeSystem(id); - } -} diff --git a/src/ECS/Systems/Managers/GameManager.hpp b/src/ECS/Systems/Managers/GameManager.hpp deleted file mode 100644 index 7976a7e4..00000000 --- a/src/ECS/Systems/Managers/GameManager.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager implementation -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class GameManager : public ASystemManager { - public: - static GameManager &getInstance(); - void updateSystems(); - void addSystem(std::function); - void removeSystem(std::size_t); - private: - GameManager(); - static GameManager _instance; - }; -} diff --git a/src/ECS/Systems/Managers/SystemManager.cpp b/src/ECS/Systems/Managers/SystemManager.cpp new file mode 100644 index 00000000..7c12f9b1 --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManager.cpp @@ -0,0 +1,75 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManager implementation +*/ + +#include "SystemManager.hpp" + +namespace Systems { + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + std::size_t SystemManager::_managerNb = 0; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + + SystemManager::SystemManager() : _id(_managerNb), _modified(false) + { + _managerNb += 1; + } + + SystemManager::SystemManager( + std::vector> systems) + : _id(_managerNb), + _originalSystems(std::move(systems)), + _modified(false) + { + _managerNb += 1; + } + + void SystemManager::updateSystems() + { + std::size_t i = 0; + + for (auto &system : getSystems()) { + system(_id, i); + i++; + } + } + + void + SystemManager::addSystem(std::function sys) + { + setModifiedSystems(); + _modifiedSystems.push_back(sys); + } + + void SystemManager::removeSystem(std::size_t id) + { + setModifiedSystems(); + auto it = _modifiedSystems.begin(); + std::advance(it, id); + _modifiedSystems.erase(it); + } + + void SystemManager::resetChanges() + { + _modified = false; + _modifiedSystems.clear(); + } + + std::vector> & + SystemManager::getSystems() + { + if (_modified) { + return _modifiedSystems; + } + return _originalSystems; + } + + void SystemManager::setModifiedSystems() + { + _modified = true; + _modifiedSystems = _originalSystems; + } +} // namespace Systems diff --git a/src/ECS/Systems/Managers/SystemManager.hpp b/src/ECS/Systems/Managers/SystemManager.hpp new file mode 100644 index 00000000..5cbc0969 --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManager.hpp @@ -0,0 +1,42 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManager +*/ + +#pragma once + +#include +#include + +namespace Systems { + class SystemManager { + public: + SystemManager(); + SystemManager( + std::vector> + systems); + void updateSystems(); + void addSystem( + std::function /*sys*/); + void removeSystem(std::size_t /*id*/); + void resetChanges(); + + private: + std::vector>& + getSystems(); + void setModifiedSystems(); + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + static std::size_t _managerNb; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + + std::size_t _id; + std::vector> + _originalSystems; + std::vector> + _modifiedSystems; + bool _modified; + }; +} // namespace Systems diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.cpp b/src/ECS/Systems/Managers/SystemManagersDirector.cpp new file mode 100644 index 00000000..d16fad01 --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManagersDirector.cpp @@ -0,0 +1,54 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManagersDirector implementation +*/ + +#include "SystemManagersDirector.hpp" +#include "Systems.hpp" + +namespace Systems { + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + SystemManagersDirector SystemManagersDirector::_instance = + SystemManagersDirector(); + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + + SystemManagersDirector &SystemManagersDirector::getInstance() + { + return _instance; + } + + SystemManager &SystemManagersDirector::getSystemManager(std::size_t id) + { + return _systemManagers[id]; + } + + std::size_t SystemManagersDirector::addSystemManager() + { + _systemManagers.emplace_back(); + return _systemManagers.size() - 1; + } + + std::size_t SystemManagersDirector::addSystemManager( + std::vector> systems) + { + _systemManagers.emplace_back(systems); + return _systemManagers.size() - 1; + } + + void SystemManagersDirector::removeSystemManager(std::size_t id) + { + auto it = _systemManagers.begin(); + std::advance(it, id); + _systemManagers.erase(it); + } + + void SystemManagersDirector::resetChanges() + { + for (auto &manager : _systemManagers) { + manager.resetChanges(); + } + } +} // namespace Systems diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.hpp b/src/ECS/Systems/Managers/SystemManagersDirector.hpp new file mode 100644 index 00000000..bf521b5a --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManagersDirector.hpp @@ -0,0 +1,33 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManagersDirector +*/ + +#pragma once + +#include +#include "SystemManager.hpp" + +namespace Systems { + class SystemManagersDirector { + public: + static SystemManagersDirector &getInstance(); + SystemManager &getSystemManager(std::size_t); + std::size_t addSystemManager(); + std::size_t addSystemManager( + std::vector>); + void removeSystemManager(std::size_t); + void resetChanges(); + + private: + std::vector _systemManagers; + + SystemManagersDirector() = default; + + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + static SystemManagersDirector _instance; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + }; +} // namespace Systems diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index ccd67345..3196e88a 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -5,24 +5,102 @@ ** Systems implementation */ -#include -#include "Registry.hpp" +#include "Systems.hpp" +#include #include "CustomTypes.hpp" +#include "Raylib.hpp" +#include "Registry.hpp" +#include "SystemManagersDirector.hpp" namespace Systems { - void collision(std::size_t) + void windowCollision(std::size_t /*unused*/, std::size_t /*unused*/) { - Registry::components arrPixel = Registry::getInstance().getComponents(); + Registry::components arrPosition = + Registry::getInstance().getComponents(); + Registry::components arrCollisionRect = + Registry::getInstance().getComponents(); + + SparseArray &playerId = + Registry::getInstance().getCustomSparseArray( + CustomIndex::PLAYER); - for (auto begin = arrPixel.begin(); begin != arrPixel.end(); begin++) { - if (begin->x < 0) - begin->x = 0; - if (begin->x > 750) - begin->x = 750; - if (begin->y < 0) - begin->y = 0; - if (begin->y > 400) - begin->y = 400; + const float maxPercent = 100.0F; + for (std::optional id : playerId) { + if (id.has_value() && arrPosition[id.value()].has_value() + && arrCollisionRect[id.value()].has_value()) { + if (arrPosition[id.value()].value().x < 0) { + arrPosition[id.value()].value().x = 0; + } + if (arrPosition[id.value()].value().y < 0) { + arrPosition[id.value()].value().y = 0; + } + if (arrPosition[id.value()].value().x + + arrCollisionRect[id.value()].value().width + > maxPercent) { + arrPosition[id.value()].value().x = + maxPercent - arrCollisionRect[id.value()].value().width; + } + if (arrPosition[id.value()].value().y + + arrCollisionRect[id.value()].value().height + > maxPercent) { + arrPosition[id.value()].value().y = maxPercent + - arrCollisionRect[id.value()].value().height; + } + } } } -} + + const std::string musicPath = "assets/Audio/Musics/Title.mp3"; + const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; + const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; + const Types::Rect spriteRect = {2, 2, 48, 48}; + const Types::CollisionRect collisionRect = {46, 46}; + const Raylib::Vector2 textPos = {20, 50}; + constexpr int playerData = 10; + constexpr float musicVolume = 0.02F; + constexpr float soundVolume = 0.1F; + constexpr float fontScale = 2.0F; + const float playerWidth = 50.0F; + const float playerHeight = 50.0F; + + void init(std::size_t managerId, std::size_t systemId) + { + Registry::getInstance().addEntity(); + Registry::getInstance().getComponents().back() = { + playerData, + playerData}; + Registry::getInstance().getComponents().back() = { + playerPath, + playerWidth, + playerHeight}; + Registry::getInstance().getComponents().back() = + spriteRect; + Registry::getInstance().getComponents().back() = + collisionRect; + SparseArray &playerId = + Registry::getInstance().getCustomSparseArray( + CustomIndex::PLAYER); + playerId.add(); + playerId.back() = std::optional( + Registry::getInstance().getEntitiesNb() - 1); + Registry::getInstance().getComponents().back() = { + musicPath, + musicVolume}; + Registry::getInstance().getComponents().back() = { + soundPath, + soundVolume}; + Registry::getInstance().getComponents().back() = { + "Press space to play music, enter to play sound", + textPos, + fontScale, + Raylib::DarkBlue}; + SystemManagersDirector::getInstance() + .getSystemManager(managerId) + .removeSystem(systemId); + } + + std::vector> getECSSystems() + { + return {windowCollision, init}; + } +} // namespace Systems diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index ff57aade..336614d2 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -7,6 +7,12 @@ #pragma once +#include +#include +#include + namespace Systems { - void collision(std::size_t); -} + void windowCollision(std::size_t, std::size_t); + void init(std::size_t, std::size_t); + std::vector> getECSSystems(); +} // namespace Systems diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 7a5204a8..00000000 --- a/src/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** main -*/ - -#include -#include "GameManager.hpp" -#include "GraphicManager.hpp" -#include "SystemEventsManager.hpp" -#include "CustomTypes.hpp" -#include "Registry.hpp" - -int main() -{ - Systems::GameManager &gameManager = Systems::GameManager::getInstance(); - Systems::GraphicManager &graphicManager = Systems::GraphicManager::getInstance(); - Systems::SystemEventsManager &systemEventsManager = Systems::SystemEventsManager::getInstance(); - - Registry::components arrPixel = Registry::getInstance().registerComponent(); - arrPixel.add({20, 20}); - - while (1) { - systemEventsManager.updateSystems(); - gameManager.updateSystems(); - graphicManager.updateSystems(); - } -} diff --git a/src/main_client.cpp b/src/main_client.cpp new file mode 100644 index 00000000..161985de --- /dev/null +++ b/src/main_client.cpp @@ -0,0 +1,17 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** main +*/ + +#include "SceneManager.hpp" + +int main() +{ + SceneManager &sceneManager = SceneManager::getInstance(); + + int res = sceneManager.run(); + + return res; +} diff --git a/src/main_server.cpp b/src/main_server.cpp new file mode 100644 index 00000000..38b35454 --- /dev/null +++ b/src/main_server.cpp @@ -0,0 +1,6 @@ +#include "boost/asio.hpp" + +int main() +{ + return 0; +}