diff --git a/.github/scripts/build-ctest-review.js b/.github/scripts/build-ctest-review.js new file mode 100644 index 0000000..9065629 --- /dev/null +++ b/.github/scripts/build-ctest-review.js @@ -0,0 +1,28 @@ +module.exports = async ({github, context, pull_number, status, log}) => { + const reviews = await github.rest.pulls.listReviews({ + pull_number: pull_number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + console.log(reviews); + + for (let review of reviews.data) { + if (review.user.login === 'github-actions' && review.state === 'COMMENTED') { + await github.rest.pulls.dismissReview({ + pull_number: pull_number, + owner: context.repo.owner, + repo: context.repo.repo, + review_id: review.id + }); + } + } + + await github.rest.pulls.createReview({ + pull_number: pull_number, + owner: context.repo.owner, + repo: context.repo.repo, + body: (status === 'success' ? '😍 Tests passed!' : '😨 Tests failed!') + '\n\n```\n' + log.replaceAll('%%%', "\n") + '\n```', + event: (status === 'success' ? 'COMMENT' : 'REQUEST_CHANGES') + }); +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10d9b2f..017603d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,12 @@ on: SSH_KEY: required: false description: SSH private key for pushing version changes + SONAR_TOKEN: + required: false + description: SonarCloud token for code analysis + SONAR_HOST_URL: + required: false + description: SonarCloud host URL inputs: cmake-preset: required: true @@ -38,15 +44,32 @@ on: required: false type: string default: main + enable-sonar: + required: false + type: boolean + default: false + enable-tests: + required: false + type: boolean + default: true + notify-tests: + required: false + type: boolean + default: false jobs: build: name: MSVC / Windows 2022 runs-on: windows-2022 + permissions: + pull-requests: write + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output steps: - uses: actions/checkout@v4 with: submodules: recursive + fetch-depth: 0 - uses: TheMrMilchmann/setup-msvc-dev@v3 with: arch: x86 @@ -86,8 +109,59 @@ jobs: } - name: CMake Configure run: cmake --preset ${{ inputs.cmake-preset }} - - name: Ninja Build - run: ninja -C out/build/${{ inputs.cmake-preset }} -j 20 + - name: CMake Build + if: ${{ inputs.enable-sonar == false }} + run: | + cmake --build out/build/${{ inputs.cmake-preset }} --target zbassmusic_vdf -j 16 + - name: Install Sonar + if: ${{ inputs.enable-sonar == true }} + run: | + Invoke-WebRequest https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip -OutFile build-wrapper-win-x86.zip + Expand-Archive build-wrapper-win-x86.zip -Destination . + Invoke-WebRequest https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.0.0.4432-windows.zip -OutFile sonar-scanner-cli-6.0.0.4432-windows.zip + Expand-Archive sonar-scanner-cli-6.0.0.4432-windows.zip -Destination . + - name: CMake Build (Sonar Wrapper) + if: ${{ inputs.enable-sonar == true }} + run: | + ./build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build out/build/${{ inputs.cmake-preset }} --target zbassmusic_vdf -j 16 + - name: Sonar Scanner + if: ${{ inputs.enable-sonar == true }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + run: | + ./sonar-scanner-6.0.0.4432-windows/bin/sonar-scanner.bat --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" + - name: CTest + id: tests + if: ${{ inputs.enable-tests == true }} + run: | + $status = $false; + cmake --build out/build/${{ inputs.cmake-preset }} --target tests -j 16 + if (ctest --test-dir out/build/${{ inputs.cmake-preset }}/tests -j 16) { + echo "tests=success" >> $env:GITHUB_OUTPUT + $status = $true; + } else { + echo "tests=failed" >> $env:GITHUB_OUTPUT + } + $testsLog = (Get-Content -Path out/build/${{ inputs.cmake-preset }}/tests/Testing/Temporary/LastTest.log) -join "%%%" + echo "tests_log=${testsLog}" >> $env:GITHUB_OUTPUT + cat out/build/${{ inputs.cmake-preset }}/tests/Testing/Temporary/LastTest.log + if (-not $status) { + exit -1 + } + - name: CTest Result PR + if: ${{ inputs.enable-tests == true && inputs.notify-tests == true && github.event_name == 'pull_request' }} + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const pull_number = ${{ github.event.number }}; + const status = '${{ steps.tests.outputs.tests }}'; + const log = '${{ steps.tests.outputs.tests_log }}'; + require('./.github/scripts/build-ctest-review.js')({ + github, context, pull_number, status, log + }); - name: CMake Install run: cmake --install out/build/${{ inputs.cmake-preset }} --prefix out/install/${{ inputs.cmake-preset }} - name: Archive DLL diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index ec604f7..43232be 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -5,7 +5,7 @@ on: pull_request: branches: [ "main", "dev" ] push: - branches: [ "main", "dev", "gh_actions" ] + branches: [ "main", "dev", "feature/*", "bugfix/*" ] paths-ignore: - 'README.md' - 'docs/**' @@ -14,11 +14,16 @@ jobs: build-debug: name: Build Debug uses: ./.github/workflows/build.yml + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} with: cmake-preset: x86-debug upload-artifact-dll: debug-dll upload-artifact-dll-pdb: debug-dll-pdb upload-artifact-vdf: debug-vdf + enable-sonar: true + notify-tests: true build-release: name: Build Release @@ -29,9 +34,9 @@ jobs: upload-artifact-vdf: release-vdf build-release-pdb: - name: Build Release (Debug Symbols) + name: Build RelWithDebInfo uses: ./.github/workflows/build.yml with: - cmake-preset: x86-release-pdb - upload-artifact-dll-pdb: release-dll-pdb - upload-artifact-vdf: release-vdf-pdb \ No newline at end of file + cmake-preset: x86-relwithdebinfo + upload-artifact-dll-pdb: relwithdebinfo-dll + upload-artifact-vdf: relwithdebinfo-vdf \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 89b83cb..df353ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,13 +19,13 @@ jobs: project-version: ${{ github.ref_name }} push-version-commit: true - build-release-pdb: - name: Build Release (Debug Symbols) + build-relwithdebinfo: + name: Build RelWithDebInfo uses: ./.github/workflows/build.yml with: - cmake-preset: x86-release-pdb - upload-artifact-dll-pdb: release-dll-pdb - upload-artifact-vdf: release-vdf-pdb + cmake-preset: x86-relwithdebinfo + upload-artifact-dll-pdb: relwithdebinfo-dll + upload-artifact-vdf: relwithdebinfo-vdf project-version: ${{ github.ref_name }} publish: @@ -33,7 +33,7 @@ jobs: runs-on: windows-2022 needs: - build-release - - build-release-pdb + - build-relwithdebinfo steps: - name: Download Release DLL uses: actions/download-artifact@v4 @@ -48,13 +48,13 @@ jobs: - name: Download Release DLL PDB uses: actions/download-artifact@v4 with: - name: release-dll-pdb - path: out/build/x86-release-pdb/ + name: relwithdebinfo-dll + path: out/build/x86-relwithdebinfo/ - name: Download Release DLL VDF uses: actions/download-artifact@v4 with: - name: release-vdf-pdb - path: out/install/x86-release-pdb/ + name: relwithdebinfo-vdf + path: out/install/x86-relwithdebinfo/ - name: Prepare Release Files id: prepare-release shell: powershell @@ -63,9 +63,9 @@ jobs: run: | $tag = $env:GITHUB_REF -replace '^refs/tags/', '' Compress-Archive out/install/x86-release/bin/* zBassMusic-${tag}.zip - Compress-Archive out/build/x86-release-pdb/* zBassMusic-${tag}-pdb.zip + Compress-Archive out/build/x86-relwithdebinfo/* zBassMusic-${tag}-relwithdebinfo.zip Copy-Item out/install/x86-release/zBassMusic.vdf zBassMusic-${tag}.vdf - Copy-Item out/install/x86-release-pdb/zBassMusic.vdf zBassMusic-${tag}-pdb.vdf + Copy-Item out/install/x86-relwithdebinfo/zBassMusic.vdf zBassMusic-${tag}-relwithdebinfo.vdf $prerelease = if (-not ($tag -match '^v?(\d+\.\d+\.\d+)$')) { 'true' } else { 'false' } echo "prerelease=${prerelease}" >> $env:GITHUB_OUTPUT - name: Release diff --git a/.gitignore b/.gitignore index 978e155..c6e1187 100644 --- a/.gitignore +++ b/.gitignore @@ -414,4 +414,5 @@ out # Idea .idea -!docs/**/release \ No newline at end of file +!docs/**/release +.scannerwork \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index d0ae6ad..bc4f4c7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,6 +3,3 @@ url = https://gitlab.com/union-framework/union-api.git [submodule ".\\dependencies\\union-api"] url = https://gitlab.com/union-framework/union-api.git -[submodule "dependencies/gothic-api"] - path = dependencies/gothic-api - url = https://gitlab.com/union-framework/gothic-api diff --git a/CMakeLists.txt b/CMakeLists.txt index 90dffb2..b1f3aef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,39 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.25..3.29.5) set(PROJECT_VERSION "0.1.3") set(PROJECT_VERSION_CMAKE "0.3.2") -project(zBassMusic VERSION ${PROJECT_VERSION_CMAKE}) +set(VCPKG_TARGET_ARCHITECTURE "x86") +set(VCPKG_PLATFORM_TOOLSET "v143") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +project(zBassMusic VERSION "${PROJECT_VERSION_CMAKE}" LANGUAGES CXX) option(BUILD_VDF "Build .VDF file with plugin" ON) +option(BUILD_TESTS "Build tests" ON) -set(UNION_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/union-api") -set(GOTHIC_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/gothic-api") set(BASS_DIR "${CMAKE_SOURCE_DIR}/dependencies/bass") set(VDF_DIR "${CMAKE_SOURCE_DIR}/vdf") set(GOTHIC_USERAPI_DIR "${CMAKE_SOURCE_DIR}/gothic-userapi") set(CMAKE_CXX_STANDARD 23) -if (${CMAKE_BUILD_RELEASE_PDB}) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") -endif () +set(CMAKE_CXX_FLAGS_DEBUG "${CMAE_CXX_FLAGS_DEBUG} /Zc:__cplusplus") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAE_CXX_FLAGS_RELEASE} /Zc:__cplusplus") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAE_CXX_FLAGS_RELWITHDEBINFO} /Zc:__cplusplus") + +include(FetchContent) +set(BUILD_UNION_API_STATIC OFF CACHE INTERNAL "Disable static build of UnionAPI") +FetchContent_Declare( + UnionAPI + URL https://github.com/piotrmacha/union-api.cmake/releases/latest/download/UnionAPI-v143-windows-2022.zip) +FetchContent_MakeAvailable(UnionAPI) +FetchContent_GetProperties(UnionAPI SOURCE_DIR UnionAPI_SOURCE_DIR) +set(CMAKE_FIND_PACKAGE_REDIRECTS_DIR ${UnionAPI_SOURCE_DIR}) +set(UnionAPI_DIR ${UnionAPI_SOURCE_DIR}/lib/cmake/UnionAPI) +find_package(UnionAPI CONFIG REQUIRED) -include(cmake/union-api.cmake) -include(cmake/gothic-api.cmake) +find_package(spdlog CONFIG REQUIRED) include(cmake/bass.cmake) -add_library(plugin SHARED) -set_target_properties(plugin PROPERTIES +add_library(zbassmusic SHARED) +set_target_properties(zbassmusic PROPERTIES OUTPUT_NAME "zBassMusic" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}") @@ -35,16 +46,36 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${CMAKE_CURRENT_BINA configure_file("${CMAKE_SOURCE_DIR}/vdf/script.vdfs.in" "${CMAKE_BINARY_DIR}/script.vdfs") configure_file("${CMAKE_SOURCE_DIR}/src/BuildInfo.h.in" "${CMAKE_BINARY_DIR}/src/BuildInfo.h" @ONLY) -file(GLOB_RECURSE PLUGIN_SOURCES "src/**.cpp" "${UNION_API_DIR}/union-api/Union/Memory.cpp") -target_sources(plugin PRIVATE ${PLUGIN_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/version.rc") +add_library(zbassmusic_gothicapi STATIC) +target_compile_options(zbassmusic_gothicapi PRIVATE /W1 /wd4530 /wd4005) +target_compile_definitions(zbassmusic_gothicapi PRIVATE __G1 __G1A __G2 __G2A) +target_link_libraries(zbassmusic_gothicapi PRIVATE UnionAPI::GothicAPI) + +file(GLOB_RECURSE ZBASSMUSIC_SOURCES "src/**.cpp") +target_sources(zbassmusic PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/version.rc" ${ZBASSMUSIC_SOURCES}) +target_compile_options(zbassmusic PRIVATE /W4 /WX /wd4530 /wd4005) +target_compile_definitions(zbassmusic PRIVATE __G1 __G1A __G2 __G2A) +target_include_directories(zbassmusic PRIVATE "src/" "${CMAKE_BINARY_DIR}/src/" "gothic-userapi" + "${CMAKE_BINARY_DIR}/_deps/unionapi-src/include" + "${CMAKE_BINARY_DIR}/_deps/unionapi-src/include/ZenGin/Gothic_UserAPI") +target_link_libraries(zbassmusic PRIVATE UnionAPI::UnionAPI zbassmusic_gothicapi bass_all) -add_compile_options(plugin PRIVATE /W4 /WX) -target_compile_definitions(plugin PRIVATE _UNION_API_DLL __G1 __G1A __G2 __G2A) -target_include_directories(plugin PRIVATE "src/" "${CMAKE_BINARY_DIR}/src/") -target_link_libraries(plugin PRIVATE union-api gothic-api bass_all) +if (${BUILD_TESTS}) + enable_testing() + add_subdirectory(tests) +endif () + +install(FILES $ DESTINATION ${CMAKE_BINARY_DIR}) +install(FILES $ TYPE BIN) +install(TARGETS zbassmusic + EXPORT zBassMusicTargets + LIBRARY DESTINATION bin + ARCHIVE DESTINATION bin + RUNTIME DESTINATION bin) +install(EXPORT zBassMusicTargets + FILE zBassMusicTargets.cmake + DESTINATION lib/cmake/Plugin) -install(FILES $ "${CMAKE_BINARY_DIR}/zBassMusic.dll" TYPE BIN) -install(FILES $ "${CMAKE_BINARY_DIR}/UnionAPI.dll" TYPE BIN) if (${BUILD_VDF}) install(FILES "${CMAKE_BINARY_DIR}/script.vdfs" DESTINATION "${CMAKE_INSTALL_PREFIX}") install(SCRIPT "${VDF_DIR}/vdf.cmake") @@ -54,16 +85,16 @@ endif () if (${BUILD_VDF}) string(REPLACE "build" "install" INSTALL_DIR "${CMAKE_BINARY_DIR}") - add_custom_target(plugin_vdf ALL + add_custom_target(zbassmusic_vdf ALL COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix ${INSTALL_DIR} - DEPENDS plugin + DEPENDS zbassmusic COMMENT "Run install to build VDF") if (DEFINED ENV{COPY_VDF_TARGET}) add_custom_target(copy_vdf ALL COMMAND ${CMAKE_COMMAND} -E copy "${INSTALL_DIR}/zBassMusic.vdf" "$ENV{COPY_VDF_TARGET}" - DEPENDS plugin_vdf - COMMENT "Copy plugin to target directory: $ENV{COPY_VDF_TARGET}") + DEPENDS zbassmusic_vdf + COMMENT "Copy zbassmusic to target directory: $ENV{COPY_VDF_TARGET}") endif () endif () @@ -75,6 +106,6 @@ if (DEFINED ENV{COPY_DLL_TARGET}) COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassmidi.dll" "$ENV{COPY_DLL_TARGET}/bassmidi.dll" COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassopus.dll" "$ENV{COPY_DLL_TARGET}/bassopus.dll" COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassflac.dll" "$ENV{COPY_DLL_TARGET}/bassflac.dll" - DEPENDS plugin - COMMENT "Copy plugin to target directory: $ENV{COPY_DLL_TARGET}") -endif () + DEPENDS zbassmusic + COMMENT "Copy zbassmusic to target directory: $ENV{COPY_DLL_TARGET}") +endif () \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 3bcb972..3fff09f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,7 +9,8 @@ "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" + "CMAKE_CXX_COMPILER": "cl.exe", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" }, "condition": { "type": "equals", @@ -38,11 +39,11 @@ } }, { - "name": "x86-release-pdb", - "displayName": "x86 Release (Debug Symbols)", + "name": "x86-relwithdebinfo", + "displayName": "x86 RelWithDebInfo", "inherits": "x86-release", "cacheVariables": { - "CMAKE_BUILD_RELEASE_PDB": "yes" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } } ] diff --git a/README.md b/README.md index 61574c1..3f2cbfe 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # zBassMusic +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=zbassmusic) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=bugs)](https://sonarcloud.io/summary/new_code?id=zbassmusic) +[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=zbassmusic) +[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=zbassmusic) +[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=zbassmusic) +[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=zbassmusic&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=zbassmusic) + zBassMusic is a modern music system for Gothic games based on ZenGin. It replaces the original DirectMusic system with a custom engine built on top of [BASS Audio Library](https://www.un4seen.com/) to provide easier workflow for composers diff --git a/cmake/gothic-api.cmake b/cmake/gothic-api.cmake deleted file mode 100644 index bfff530..0000000 --- a/cmake/gothic-api.cmake +++ /dev/null @@ -1,8 +0,0 @@ -add_library(gothic-api INTERFACE IMPORTED) -target_include_directories(gothic-api INTERFACE - "${GOTHIC_USERAPI_DIR}" - "${GOTHIC_API_DIR}" - "${GOTHIC_API_DIR}/ZenGin/Gothic_UserAPI" -) -target_link_directories(gothic-api INTERFACE "${GOTHIC_API_DIR}") -target_sources(gothic-api INTERFACE "${GOTHIC_API_DIR}/ZenGin/zGothicAPI.cpp") \ No newline at end of file diff --git a/cmake/union-api.cmake b/cmake/union-api.cmake deleted file mode 100644 index c349138..0000000 --- a/cmake/union-api.cmake +++ /dev/null @@ -1,20 +0,0 @@ -add_library(union-api SHARED) -set_target_properties(union-api PROPERTIES - OUTPUT_NAME "UnionAPI" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}") - -target_include_directories(union-api PUBLIC "${UNION_API_DIR}/union-api") -target_link_directories(union-api PUBLIC "${UNION_API_DIR}/union-api") - -file(GLOB_RECURSE UNION_SOURCES "${UNION_API_DIR}/union-api/union-api.cpp" "${UNION_API_DIR}/union-api/Union/Memory.cpp") -target_sources(union-api PRIVATE ${UNION_SOURCES}) - -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - target_compile_definitions(union-api PUBLIC WIN32 _DEBUG _CONSOLE _UNION_API_DLL PRIVATE _UNION_API_BUILD) -elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - target_compile_definitions(union-api PUBLIC WIN32 NDEBUG _CONSOLE _UNION_API_DLL PRIVATE _UNION_API_BUILD) -else () - message(FATAL_ERROR "Invalid $CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} not in range [Debug, Release]") -endif () \ No newline at end of file diff --git a/dependencies/gothic-api b/dependencies/gothic-api deleted file mode 160000 index 102f42a..0000000 --- a/dependencies/gothic-api +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 102f42aaf6fe2f2c9c296f8ec66ee8fcde08d646 diff --git a/dependencies/union-api b/dependencies/union-api deleted file mode 160000 index 406e3fb..0000000 --- a/dependencies/union-api +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 406e3fb32232300bae2ff2ee0018685c15c7f1ef diff --git a/set-version.ps1 b/set-version.ps1 index 7acd294..349c3b8 100644 --- a/set-version.ps1 +++ b/set-version.ps1 @@ -34,6 +34,11 @@ $cmakeVersion = $version -replace '-[a-z0-9]+$', '' Write-Host "Setting version to $version" Copy-Item CMakeLists.txt CMakeLists.txt.bak -$cmake = (Get-Content -Path ./CMakeLists.txt) -replace 'set\(PROJECT_VERSION "[^"]*"\)', "set(PROJECT_VERSION ""$version"")" -$cmake = (Get-Content -Path ./CMakeLists.txt) -replace 'set\(PROJECT_VERSION_CMAKE "[^"]*"\)', "set(PROJECT_VERSION_CMAKE ""$cmakeVersion"")" -$cmake | Set-Content -Path ./CMakeLists.txt \ No newline at end of file +$cmake = Get-Content -Path ./CMakeLists.txt +$cmake = $cmake -replace 'set\(PROJECT_VERSION "[^"]*"\)', "set(PROJECT_VERSION ""$version"")" +$cmake = $cmake -replace 'set\(PROJECT_VERSION_CMAKE "[^"]*"\)', "set(PROJECT_VERSION_CMAKE ""$cmakeVersion"")" +$cmake | Set-Content -Path ./CMakeLists.txt + +$vcpkg = Get-Content -Path ./vcpkg.json +$vcpkg = $vcpkg -replace '"version": "[^"]*"', """version"": ""$version""" +$vcpkg | Set-Content -Path ./vcpkg.json \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..fea3a9c --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,3 @@ +sonar.projectKey=zbassmusic +sonar.organization=silver-ore-team +sonar.sources=src,gothic-userapi \ No newline at end of file diff --git a/src/Gothic/BassLoader.hpp b/src/Gothic/BassLoader.hpp index 78165f7..97b6cec 100644 --- a/src/Gothic/BassLoader.hpp +++ b/src/Gothic/BassLoader.hpp @@ -1,5 +1,8 @@ +#pragma warning(push, 1) #include -#include +#pragma warning(pop) + +#include "NH/Bass/MidiFile.h" namespace GOTHIC_NAMESPACE { diff --git a/src/Gothic/Externals.hpp b/src/Gothic/Externals.hpp index 67dbd07..3f8f951 100644 --- a/src/Gothic/Externals.hpp +++ b/src/Gothic/Externals.hpp @@ -1,6 +1,8 @@ +#pragma warning(push, 1) #include #include #include +#pragma warning(pop) namespace GOTHIC_NAMESPACE { diff --git a/src/Gothic/Globals.hpp b/src/Gothic/Globals.hpp index 1d27877..33761ad 100644 --- a/src/Gothic/Globals.hpp +++ b/src/Gothic/Globals.hpp @@ -1,4 +1,6 @@ +#pragma warning(push, 1) #include +#pragma warning(pop) namespace GOTHIC_NAMESPACE { diff --git a/src/NH/Bass/Channel.cpp b/src/NH/Bass/Channel.cpp index 6a48f34..b043d28 100644 --- a/src/NH/Bass/Channel.cpp +++ b/src/NH/Bass/Channel.cpp @@ -74,7 +74,7 @@ namespace NH::Bass void Channel::OnPosition(double position, const std::function& callback) { - size_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position); + uint64_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position); BASS_ChannelSetSync(m_Stream, BASS_SYNC_POS, positionBytes, OnPositionSyncCallFunction, (void*)new OnSyncPosition{ m_Stream, callback }); } @@ -86,7 +86,7 @@ namespace NH::Bass void Channel::BeforeAudioEnds(double aheadSeconds, const std::function& onFinish) { double position = Length() - aheadSeconds; - size_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position); + uint64_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position); BASS_ChannelSetSync(m_Stream, BASS_SYNC_POS, positionBytes, BeforeAudioEndsSyncCallFunction, (void*)new OnSyncBeforeAudioEndsData{ m_Stream, onFinish }); } @@ -128,7 +128,7 @@ namespace NH::Bass return -1; } - void Channel::OnPositionSyncCallFunction(HSYNC, DWORD channel, DWORD data, void* userData) + void Channel::OnPositionSyncCallFunction(HSYNC, DWORD channel, [[maybe_unused]] DWORD data, void* userData) { auto* payload = static_cast(userData); if (channel != payload->Channel) return; @@ -136,14 +136,14 @@ namespace NH::Bass else { CreateLogger("HSYNC::OnPositionSyncCallFunction")->Error("onFinish is nullptr"); } } - void Channel::OnSlideVolumeSyncCallFunction(HSYNC, DWORD channel, DWORD data, void* userData) + void Channel::OnSlideVolumeSyncCallFunction(HSYNC, [[maybe_unused]] DWORD channel, [[maybe_unused]] DWORD data, void* userData) { auto* onFinish = static_cast*>(userData); if (onFinish) { (*onFinish)(); } else { CreateLogger("HSYNC::OnSlideVolumeSyncCallFunction")->Error("onFinish is nullptr"); } } - void Channel::OnAudioEndSyncCallFunction(HSYNC, DWORD channel, DWORD data, void* userData) + void Channel::OnAudioEndSyncCallFunction(HSYNC, DWORD channel, [[maybe_unused]] DWORD data, void* userData) { auto* payload = static_cast(userData); if (channel != payload->Channel) return; @@ -151,7 +151,7 @@ namespace NH::Bass else { CreateLogger("HSYNC::OnAudioEndSyncCallFunction")->Error("onFinish is nullptr"); } } - void Channel::BeforeAudioEndsSyncCallFunction(HSYNC, DWORD channel, DWORD data, void* userData) + void Channel::BeforeAudioEndsSyncCallFunction(HSYNC, DWORD channel, [[maybe_unused]] DWORD data, void* userData) { auto* payload = static_cast(userData); if (channel != payload->Channel) return; diff --git a/src/NH/Bass/Channel.h b/src/NH/Bass/Channel.h index 572719c..2477d50 100644 --- a/src/NH/Bass/Channel.h +++ b/src/NH/Bass/Channel.h @@ -2,10 +2,12 @@ #include "EventManager.h" #include "NH/Logger.h" -#include -#include +#include "NH/Bass/MusicTheme.h" +#include "NH/Bass/IChannel.h" +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/Command.h b/src/NH/Bass/Command.h index f460bc6..e148635 100644 --- a/src/NH/Bass/Command.h +++ b/src/NH/Bass/Command.h @@ -1,13 +1,15 @@ #pragma once -#include +#include "NH/Logger.h" +#pragma warning(push, 1) #include #include #include #include #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/Engine.cpp b/src/NH/Bass/Engine.cpp index f68dd28..03369e9 100644 --- a/src/NH/Bass/Engine.cpp +++ b/src/NH/Bass/Engine.cpp @@ -1,11 +1,12 @@ #include "Options.h" #include "Engine.h" +#pragma warning(push, 1) #include #include #include - #include +#pragma warning(pop) namespace NH::Bass { @@ -31,7 +32,7 @@ namespace NH::Bass static auto lastTimestamp = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now(); - uint64_t delta = std::chrono::duration_cast(now - lastTimestamp).count(); + uint32_t delta = static_cast(std::chrono::duration_cast(now - lastTimestamp).count()); lastTimestamp = now; m_CommandQueue.Update(*this); @@ -89,7 +90,7 @@ namespace NH::Bass } m_MasterVolume = volume; - BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 10000 * m_MasterVolume); + BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, static_cast(10000 * m_MasterVolume)); } float Engine::GetVolume() const diff --git a/src/NH/Bass/Engine.h b/src/NH/Bass/Engine.h index 75d4e23..7617db7 100644 --- a/src/NH/Bass/Engine.h +++ b/src/NH/Bass/Engine.h @@ -1,17 +1,20 @@ #pragma once -#include #include "EventManager.h" #include "Channel.h" #include "NH/Logger.h" #include "NH/HashString.h" -#include -#include -#include +#include "NH/Bass/IEngine.h" +#include "NH/Bass/MusicManager.h" +#include "NH/Bass/Command.h" + +#pragma warning(push, 1) +#include #include #include #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/EngineCommands.cpp b/src/NH/Bass/EngineCommands.cpp index 0f135bc..ad4b07a 100644 --- a/src/NH/Bass/EngineCommands.cpp +++ b/src/NH/Bass/EngineCommands.cpp @@ -1,7 +1,7 @@ #include "EngineCommands.h" -#include -#include +#include "NH/Bass/Engine.h" +#include "NH/Bass/Options.h" namespace NH::Bass { diff --git a/src/NH/Bass/EngineCommands.h b/src/NH/Bass/EngineCommands.h index 5c68cd2..a93ffd2 100644 --- a/src/NH/Bass/EngineCommands.h +++ b/src/NH/Bass/EngineCommands.h @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include -#include +#include "NH/HashString.h" +#include "NH/Logger.h" +#include "NH/Bass/Command.h" +#include "NH/Bass/IEngine.h" namespace NH::Bass { diff --git a/src/NH/Bass/EventManager.h b/src/NH/Bass/EventManager.h index fbf4dff..a8dd8c3 100644 --- a/src/NH/Bass/EventManager.h +++ b/src/NH/Bass/EventManager.h @@ -1,12 +1,14 @@ #pragma once #include "NH/Logger.h" -#include +#include "NH/HashString.h" +#pragma warning(push, 1) #include #include #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/IChannel.h b/src/NH/Bass/IChannel.h index 7916753..9c3ab72 100644 --- a/src/NH/Bass/IChannel.h +++ b/src/NH/Bass/IChannel.h @@ -1,11 +1,13 @@ #pragma once +#pragma warning(push, 1) #include #include +#pragma warning(pop) namespace NH::Bass { - class AudioFile; + struct AudioFile; struct IChannel { diff --git a/src/NH/Bass/IEngine.h b/src/NH/Bass/IEngine.h index e9d8f5a..2ada93b 100644 --- a/src/NH/Bass/IEngine.h +++ b/src/NH/Bass/IEngine.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "NH/Bass/IChannel.h" namespace NH::Bass { diff --git a/src/NH/Bass/MidiFile.cpp b/src/NH/Bass/MidiFile.cpp index 4dcbacc..0cc67c0 100644 --- a/src/NH/Bass/MidiFile.cpp +++ b/src/NH/Bass/MidiFile.cpp @@ -1,8 +1,10 @@ #include "MidiFile.h" +#pragma warning(push, 1) #include #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/MidiFile.h b/src/NH/Bass/MidiFile.h index d795116..d9bec37 100644 --- a/src/NH/Bass/MidiFile.h +++ b/src/NH/Bass/MidiFile.h @@ -1,11 +1,13 @@ #pragma once -#include -#include -#include +#include "NH/Logger.h" +#include "NH/HashString.h" +#include "NH/Executor.h" +#pragma warning(push, 1) #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/MusicManager.h b/src/NH/Bass/MusicManager.h index 2f63835..a689682 100644 --- a/src/NH/Bass/MusicManager.h +++ b/src/NH/Bass/MusicManager.h @@ -1,7 +1,10 @@ #pragma once -#include +#include "NH/Bass/MusicTheme.h" + +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/MusicTheme.cpp b/src/NH/Bass/MusicTheme.cpp index eb8af28..649c4cb 100644 --- a/src/NH/Bass/MusicTheme.cpp +++ b/src/NH/Bass/MusicTheme.cpp @@ -1,9 +1,11 @@ #include "MusicTheme.h" #include "EngineCommands.h" +#include "NH/Bass/Command.h" +#include "NH/Bass/EventManager.h" +#pragma warning(push, 1) #include -#include -#include +#pragma warning(pop) namespace NH::Bass { @@ -144,7 +146,7 @@ namespace NH::Bass })); engine.GetCommandQueue().AddCommand(std::make_shared( std::chrono::high_resolution_clock::now() + std::chrono::milliseconds((long long)((timePoint->Start + transition.JingleDelay) * 1000)), - std::make_shared([&playJingle](Engine& engine) -> CommandResult { + std::make_shared([&playJingle]([[maybe_unused]] Engine& engine) -> CommandResult { playJingle(); return CommandResult::DONE; }))); @@ -157,7 +159,7 @@ namespace NH::Bass Stop(engine, transition); engine.GetCommandQueue().AddCommand(std::make_shared( std::chrono::high_resolution_clock::now() + std::chrono::milliseconds((long long)(transition.JingleDelay * 1000)), - std::make_shared([&playJingle](Engine& engine) -> CommandResult { + std::make_shared([&playJingle]([[maybe_unused]] Engine& engine) -> CommandResult { playJingle(); return CommandResult::DONE; }))); @@ -211,7 +213,7 @@ namespace NH::Bass } void MusicTheme::Stop(IEngine& engine) { Stop(engine, m_TransitionInfo.GetDefaultTransition()); } - void MusicTheme::Stop(IEngine& engine, const struct Transition& transition) + void MusicTheme::Stop([[maybe_unused]] IEngine& engine, const struct Transition& transition) { auto channel = GetAcquiredChannel(); if (!channel) @@ -239,7 +241,7 @@ namespace NH::Bass } } - bool MusicTheme::ReadyToPlay(IEngine& engine, HashString audio) + bool MusicTheme::ReadyToPlay(IEngine& engine, [[maybe_unused]] HashString audio) { if (!HasAudioFile(AudioFile::DEFAULT)) { @@ -257,7 +259,7 @@ namespace NH::Bass if (file.Status != AudioFile::StatusType::READY) { engine.GetCommandQueue().AddCommand(std::make_shared( - [this, &engine](Engine& e) -> CommandResult { + [this, &engine]([[maybe_unused]] Engine& e) -> CommandResult { const AudioFile& f = GetAudioFile(AudioFile::DEFAULT); if (f.Status == AudioFile::StatusType::FAILED) { @@ -297,11 +299,7 @@ namespace NH::Bass std::shared_ptr MusicTheme::GetAcquiredChannel() { - for (auto& channel: m_AcquiredChannels) - { - return channel; - } - return {}; + return m_AcquiredChannels.size() > 0 ? m_AcquiredChannels.front() : nullptr; } void MusicTheme::ReleaseChannels() @@ -316,7 +314,7 @@ namespace NH::Bass String MusicTheme::ToString() const { String result = String("MusicTheme{ \n\tName: ") + m_Name + ", \n\tAudioFiles: {\n"; - int i = 0; + uint32_t i = 0; for (auto& [type, audioFile]: m_AudioFiles) { result += String("\t\t") + String(type) + ": " + audioFile.ToString().Replace("\n", "\n\tt"); diff --git a/src/NH/Bass/MusicTheme.h b/src/NH/Bass/MusicTheme.h index b18e522..ce6f632 100644 --- a/src/NH/Bass/MusicTheme.h +++ b/src/NH/Bass/MusicTheme.h @@ -1,17 +1,19 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include - +#include "NH/Logger.h" +#include "NH/HashString.h" +#include "NH/Executor.h" +#include "NH/ToString.h" +#include "NH/Bass/MidiFile.h" +#include "NH/Bass/IEngine.h" +#include "NH/Bass/IChannel.h" +#include "NH/Bass/TransitionInfo.h" + +#pragma warning(push, 1) #include #include #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/Options.h b/src/NH/Bass/Options.h index fe0f57d..5596c16 100644 --- a/src/NH/Bass/Options.h +++ b/src/NH/Bass/Options.h @@ -1,6 +1,8 @@ #pragma once -#include "Union/String.h" +#pragma warning(push, 1) +#include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/Transition.cpp b/src/NH/Bass/Transition.cpp index ab97d93..fbefd58 100644 --- a/src/NH/Bass/Transition.cpp +++ b/src/NH/Bass/Transition.cpp @@ -1,6 +1,6 @@ #include "Transition.h" -#include +#include "NH/Bass/MusicTheme.h" namespace NH::Bass { diff --git a/src/NH/Bass/Transition.h b/src/NH/Bass/Transition.h index 4eaf1ff..744bf59 100644 --- a/src/NH/Bass/Transition.h +++ b/src/NH/Bass/Transition.h @@ -1,9 +1,12 @@ #pragma once -#include -#include -#include +#include "NH/Commons.h" +#include "NH/Bass/IEngine.h" +#include "NH/ToString.h" + +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/TransitionInfo.cpp b/src/NH/Bass/TransitionInfo.cpp index 23faca5..e38ab38 100644 --- a/src/NH/Bass/TransitionInfo.cpp +++ b/src/NH/Bass/TransitionInfo.cpp @@ -1,10 +1,11 @@ #include "TransitionInfo.h" #include "Transition.h" +#include "NH/Bass/MidiFile.h" +#include "NH/Bass/MusicTheme.h" -#include -#include - +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Bass/TransitionInfo.h b/src/NH/Bass/TransitionInfo.h index 894463c..795406a 100644 --- a/src/NH/Bass/TransitionInfo.h +++ b/src/NH/Bass/TransitionInfo.h @@ -1,10 +1,12 @@ #pragma once #include "Transition.h" -#include -#include +#include "NH/Commons.h" +#include "NH/HashString.h" +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH::Bass { diff --git a/src/NH/Commons.h b/src/NH/Commons.h index 4030c0e..ddde0f0 100644 --- a/src/NH/Commons.h +++ b/src/NH/Commons.h @@ -1,6 +1,8 @@ #pragma once +#pragma warning(push, 1) #include +#pragma warning(pop) namespace NH { diff --git a/src/NH/Executor.h b/src/NH/Executor.h index 7adb645..9f10321 100644 --- a/src/NH/Executor.h +++ b/src/NH/Executor.h @@ -1,13 +1,15 @@ #pragma once -#include +#include "NH/Logger.h" +#pragma warning(push, 1) #include #include #include #include #include #include +#pragma warning(pop) namespace NH { diff --git a/src/NH/HashString.h b/src/NH/HashString.h index d9ec146..d75a472 100644 --- a/src/NH/HashString.h +++ b/src/NH/HashString.h @@ -1,9 +1,11 @@ #pragma once -#include +#include "NH/Commons.h" +#pragma warning(push, 1) #include #include +#pragma warning(pop) namespace NH { diff --git a/src/NH/Logger.cpp b/src/NH/Logger.cpp index 653c7ec..f0b2d62 100644 --- a/src/NH/Logger.cpp +++ b/src/NH/Logger.cpp @@ -1,8 +1,9 @@ #include "Logger.h" +#pragma warning(push, 1) #include - #include +#pragma warning(pop) namespace NH { diff --git a/src/NH/Logger.h b/src/NH/Logger.h index 3c4cb61..332bead 100644 --- a/src/NH/Logger.h +++ b/src/NH/Logger.h @@ -1,8 +1,11 @@ #pragma once -#include +#include "NH/Commons.h" + +#pragma warning(push, 1) #include #include +#pragma warning(pop) namespace NH { @@ -107,7 +110,7 @@ namespace NH template T* GetAdapter() const { - for (int i = 0; i < m_Adapters.GetCount(); i++) + for (uint32_t i = 0; i < m_Adapters.GetCount(); i++) { ILoggerAdapter* adapter = m_Adapters[i]; T* ptr = dynamic_cast(adapter); diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 522813a..37e5430 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -1,14 +1,14 @@ -// Disable macro redefinition warning -#pragma warning(disable: 4005) - // Headers required for GOTHIC_NAMESPACE files. Don't delete. -#include -#include -#include -#include -#include +#include "BuildInfo.h" +#include "NH/Bass/Options.h" +#include "NH/Bass/Engine.h" +#include "NH/Bass/Command.h" +#include "NH/Bass/EngineCommands.h" + +#pragma warning(push, 1) #include #include +#pragma warning(pop) #ifdef __G1 #define GOTHIC_NAMESPACE Gothic_I_Classic diff --git a/src/Plugin.hpp b/src/Plugin.hpp index 57cc2e5..368e607 100644 --- a/src/Plugin.hpp +++ b/src/Plugin.hpp @@ -1,6 +1,6 @@ -#include -#include -#include -#include -#include -#include +#include "Gothic/Globals.hpp" +#include "Gothic/Options.hpp" +#include "Gothic/CMusicSys_Bass.hpp" +#include "Gothic/BassLoader.hpp" +#include "Gothic/Externals.hpp" +#include "Gothic/Hooks.hpp" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..f705a47 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,10 @@ +find_package(GTest CONFIG REQUIRED) + +add_executable(tests) +target_sources(tests PRIVATE "src/example.cpp") +target_include_directories(tests PRIVATE "src") +target_compile_options(tests PRIVATE /W1) +target_link_libraries(tests PRIVATE GTest::gtest GTest::gtest_main) + +include(GoogleTest) +gtest_discover_tests(tests) \ No newline at end of file diff --git a/tests/src/example.cpp b/tests/src/example.cpp new file mode 100644 index 0000000..d0bf4ef --- /dev/null +++ b/tests/src/example.cpp @@ -0,0 +1,5 @@ +#include + +TEST(ExampleTest, GTestWorks) { + EXPECT_EQ(1, 1); +} \ No newline at end of file diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..0af830c --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,18 @@ +{ + "overlay-triplets": [ + "x86-windows-static", + "x86-windows-dynamic" + ], + "default-registry": { + "kind": "git", + "baseline": "cbf4a6641528cee6f172328984576f51698de726", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..ce564a9 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,13 @@ +{ + "name": "zbassmusic", + "version": "0.3.2", + "license": "MIT", + "dependencies": [ + { + "name": "spdlog" + }, + { + "name": "gtest" + } + ] +}