diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..760af55 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,25 @@ +Checks: | + bugprone-* + clang-analyzer-* + cppcoreguidelines-* + misc-* + modernize-* + performance-* + readability-* + portability-* + -cppcoreguidelines-avoid-magic-numbers + -readability-magic-numbers + -readability-identifier-length + -modernize-use-nodiscard + -cppcoreguidelines-init-variables + -bugprone-easily-swappable-parameters + -cppcoreguidelines-avoid-non-const-global-variables + -modernize-use-trailing-return-type + -performance-enum-size + -cppcoreguidelines-pro-bounds-constant-array-index + -cppcoreguidelines-non-private-member-variables-in-classes + -cppcoreguidelines-avoid-const-or-ref-data-members + -misc-include-cleaner + -misc-non-private-member-variables-in-classes +WarningsAsErrors: true +HeaderFilterRegex: ".*" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3f322e5..2ee57a9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,16 +6,19 @@ on: - main tags: - v* - -env: - EM_VERSION: "latest" - EM_CACHE_FOLDER: "emsdk-cache" + pull_request: + branches: + - main permissions: contents: read pages: write id-token: write +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + jobs: deploy: name: Deploy @@ -25,21 +28,22 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive + uses: actions/checkout@v4 - name: Setup cache - id: cache-system-libraries - uses: actions/cache@v2 + uses: actions/cache@v4 with: - path: ${{env.EM_CACHE_FOLDER}} - key: ${{env.EM_VERSION}}-${{ runner.os }} + path: "_deps" + key: deps-${{ runner.os }} - - uses: mymindstorm/setup-emsdk@v11 + - uses: mymindstorm/setup-emsdk@v14 with: - version: ${{env.EM_VERSION}} - actions-cache-folder: ${{env.EM_CACHE_FOLDER}} + version: 4.0.6 + actions-cache-folder: "emsdk-cache" + + - name: Download ports + run: | + embuilder build harfbuzz - name: Run CMake run: emcmake cmake -G "Unix Makefiles" . @@ -47,14 +51,15 @@ jobs: - name: Make run: emmake make -j4 - - uses: actions/upload-pages-artifact@v1 + - uses: actions/upload-pages-artifact@v3 + if: github.ref == 'refs/heads/main' with: path: ./build - name: Deploy to GitHub Pages if: github.ref == 'refs/heads/main' id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 - name: Deploy to A.D.S. Games if: startsWith(github.ref, 'refs/tags/v') diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml deleted file mode 100644 index 441f5b8..0000000 --- a/.github/workflows/sonar.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Build -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - env: - SONAR_SCANNER_VERSION: 4.7.0.2747 - SONAR_SERVER_URL: "https://sonarcloud.io" - BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - submodules: "recursive" - - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-gfx-dev - version: 1.0 - - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - - name: Download and set up sonar-scanner - env: - SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip - run: | - mkdir -p $HOME/.sonar - curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH - - - name: Download and set up build-wrapper - env: - BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip - run: | - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ - echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH - - - name: Setup project - run: cmake . - - - name: Run build-wrapper - run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make - - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" diff --git a/.gitignore b/.gitignore index 45d2ab9..088631a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,6 @@ $RECYCLE.BIN/ # Icon must ends with two \r. Icon - # Thumbnails ._* @@ -55,4 +54,5 @@ build.ninja /build .idea Testing/ -compile_commands.json \ No newline at end of file +compile_commands.json +_deps/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ae582e6..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/asw"] - path = lib/asw - url = https://github.com/AdsGames/asw diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index f1672fb..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "configurations": [ - { - "name": "Win32", - "includePath": ["${default}", "${workspaceFolder}/lib/asw/include"], - "defines": ["_DEBUG", "UNICODE", "_UNICODE"], - "compileCommands": "${workspaceFolder}/compile_commands.json", - "configurationProvider": "ms-vscode.cmake-tools" - } - ], - "version": 4 -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1929074..dbc313e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "Build", "type": "shell", - "detail": "Run and build jim farm", + "detail": "Run and build memory", "command": "cmake --build . && cd build && ./Memory", "windows": { "command": "cmake --build . && cd build && Memory.exe" diff --git a/CMakeLists.txt b/CMakeLists.txt index c96aa79..55706a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,80 +5,55 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +include(FetchContent) + project (Memory) # Source code -file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.cpp) -file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.h) +file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS}) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) -add_subdirectory(lib/asw) +FetchContent_Declare( + asw + GIT_REPOSITORY https://github.com/adsgames/asw.git + GIT_TAG v0.5.4 + GIT_SHALLOW TRUE +) +FetchContent_MakeAvailable(asw) -# Find libs -if(NOT EMSCRIPTEN) - find_library(SDL_LIBRARY NAMES SDL2 REQUIRED) - find_library(SDL_MIXER_LIBRARY NAMES SDL2_mixer REQUIRED) - find_library(SDL_IMAGE_LIBRARY NAMES SDL2_image REQUIRED) - find_library(SDL_TTF_LIBRARY NAMES SDL2_ttf REQUIRED) - find_library(SDL_GFX_LIBRARY NAMES SDL2_gfx REQUIRED) - find_library(SDL_MAIN_LIBRARY NAMES SDL2main REQUIRED) -endif(NOT EMSCRIPTEN) +# Link Libs +if(MINGW) + target_link_libraries(${PROJECT_NAME} -lmingw32) +endif(MINGW) +target_link_libraries( + ${PROJECT_NAME} + asw +) -# Link Libs # Emscripten support if(EMSCRIPTEN) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index") set(CMAKE_EXECUTABLE_SUFFIX ".html") - target_compile_options( - ${PROJECT_NAME} - PRIVATE - -sUSE_SDL=2 - -sUSE_SDL_IMAGE=2 - -sUSE_SDL_TTF=2 - -sUSE_SDL_MIXER=2 - -sUSE_SDL_GFX=2 - -sSDL2_IMAGE_FORMATS=["png"] - ) + target_link_libraries( ${PROJECT_NAME} -sWASM=1 - -sUSE_SDL=2 - -sUSE_SDL_IMAGE=2 - -sUSE_SDL_TTF=2 - -sUSE_SDL_MIXER=2 - -sUSE_SDL_GFX=2 - -sSDL2_IMAGE_FORMATS=["png"] - -sDEMANGLE_SUPPORT=1 - -sTOTAL_MEMORY=512MB - asw + -sALLOW_MEMORY_GROWTH=1 + -sMAXIMUM_MEMORY=1gb ) + set_target_properties( ${PROJECT_NAME} PROPERTIES LINK_FLAGS "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets --use-preload-plugins --shell-file ${CMAKE_CURRENT_LIST_DIR}/index.html" ) - -# Run of the mill executable -else(EMSCRIPTEN) - if(MINGW) - target_link_libraries(${PROJECT_NAME} -lmingw32) - endif(MINGW) - target_link_libraries( - ${PROJECT_NAME} - -lm - ${SDL_MAIN_LIBRARY} - ${SDL_LIBRARY} - ${SDL_MIXER_LIBRARY} - ${SDL_IMAGE_LIBRARY} - ${SDL_TTF_LIBRARY} - ${SDL_GFX_LIBRARY} - asw - ) endif(EMSCRIPTEN) -file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_BINARY_DIR}/build/assets/) \ No newline at end of file +file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_BINARY_DIR}/build/assets/) + diff --git a/README.md b/README.md index 9761946..2830f56 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ Match all the cards on the table in four different difficulties. Compete against yourself and others with the high-score tables. -[](https://sonarcloud.io/summary/new_code?id=AdsGames_Memory) -[](https://sonarcloud.io/summary/new_code?id=AdsGames_Memory) +[](https://sonarcloud.io/summary/new_code?id=AdsGames_memory) +[](https://sonarcloud.io/summary/new_code?id=AdsGames_memory) +[](https://sonarcloud.io/summary/new_code?id=AdsGames_memory) ## Demo @@ -11,32 +12,6 @@ Match all the cards on the table in four different difficulties. Compete against ## Setup -### Dependencies - -To pull the submodules, run the following command: - -```bash -git submodule update --init --recursive -``` - -### Windows (MSYS2) - -```bash -pacman -S mingw-w64-i686-gcc-libs mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_mixer mingw-w64-i686-SDL2_image mingw-w64-i686-SDL2_ttf -``` - -### Mac OS - -```bash -brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer -``` - -### Linux - -```bash -sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev -``` - ### Build ```bash diff --git a/index.html b/index.html index 0ad8b76..d944101 100644 --- a/index.html +++ b/index.html @@ -14,20 +14,24 @@ width: 100%; height: 100%; background-color: #000000; + } + + #canvas_wrapper { display: flex; - align-items: center; - justify-content: center; + margin: 0 auto; }
- +