diff --git a/.github/linux/appimage.sh b/.github/linux/appimage.sh index 6905528..807b1f7 100755 --- a/.github/linux/appimage.sh +++ b/.github/linux/appimage.sh @@ -1,10 +1,10 @@ ARCH=$(uname -m) LINUX_DEPLOY_ARCH=$(uname -m) -if [ "$ARCH" == "x86_64" ]; then +if [ "$ARCH" = "x86_64" ]; then ARCH="x86_64" LINUX_DEPLOY_ARCH="x86_64" -elif [ "$ARCH" == "aarch64" ]; then +elif [ "$ARCH" = "aarch64" ]; then ARCH="arm_aarch64" LINUX_DEPLOY_ARCH="aarch64" else @@ -14,11 +14,13 @@ fi curl -sSfLO "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$LINUX_DEPLOY_ARCH.AppImage" curl -sSfLO "https://github.com/linuxdeploy/linuxdeploy-plugin-gtk/raw/master/linuxdeploy-plugin-gtk.sh" + chmod a+x linuxdeploy* mkdir -p AppDir/usr/bin cp Zelda64Recompiled AppDir/usr/bin/ cp -r assets/ AppDir/usr/bin/ +cp gamecontrollerdb.txt AppDir/usr/bin/ cp icons/512.png AppDir/Zelda64Recompiled.png cp .github/linux/Zelda64Recompiled.desktop AppDir/ @@ -34,4 +36,10 @@ echo 'else' >> AppDir/AppRun echo ' cd "$this_dir"/usr/bin/' >> AppDir/AppRun echo ' ./Zelda64Recompiled' >> AppDir/AppRun echo 'fi' >> AppDir/AppRun + +# Remove conflicting libraries +rm -rf AppDir/usr/lib/libgmodule* +rm -rf AppDir/usr/lib/gio/modules/*.so +rm -rf AppDir/usr/lib/libwayland* + ./deploy/usr/bin/linuxdeploy-plugin-appimage --appdir=AppDir diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 3c8d9ad..6d77e7c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,6 +10,10 @@ on: type: string required: false default: '2a2df89349ff25a3afb3a09617deb3a166efe2f3' + DXC_CHECKSUM: + type: string + required: false + default: '4e6f4e52989aca69739880b40b9f988357f15d10ca03284377b81f1502463ff5' secrets: ZRE_REPO_WITH_PAT: required: true @@ -18,13 +22,90 @@ concurrency: cancel-in-progress: true jobs: build-linux: - runs-on: ${{ matrix.arch == 'x64' && matrix.os || format('blaze/{0}', matrix.os) }} + runs-on: ${{ matrix.os }} + container: + image: dcvz/n64recomp:0.0.1-ubuntu-18.04 strategy: matrix: type: [ Debug, Release ] os: [ ubuntu-22.04 ] - arch: [ x64, arm64 ] - name: ${{ matrix.os }} (${{ matrix.arch }}, ${{ matrix.type }}) + name: ubuntu-18.04 (x64, ${{ matrix.type }}) + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} + submodules: recursive + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2.11 + with: + key: ${{ matrix.os }}-z64re-ccache-${{ matrix.type }}-x64-${{ inputs.N64RECOMP_COMMIT }} + - name: Prepare Build + run: |- + git clone ${{ secrets.ZRE_REPO_WITH_PAT }} + unzip zre/files.zip > /dev/null 2>&1 + - name: Build N64Recomp & RSPRecomp + run: | + git clone https://github.com/Mr-Wiseguy/N64Recomp.git --recurse-submodules N64RecompSource + cd N64RecompSource + git checkout ${{ inputs.N64RECOMP_COMMIT }} + git submodule update --init --recursive + + # enable ccache + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + + # Build N64Recomp & RSPRecomp + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_MAKE_PROGRAM=ninja -G Ninja -S . -B cmake-build + cmake --build cmake-build --config Release --target N64Recomp -j $(nproc) + cmake --build cmake-build --config Release --target RSPRecomp -j $(nproc) + + # Copy N64Recomp & RSPRecomp to root directory + cp cmake-build/N64Recomp .. + cp cmake-build/RSPRecomp .. + - name: Run N64Recomp & RSPRecomp + run: | + ./N64Recomp us.rev1.toml + ./RSPRecomp aspMain.us.rev1.toml + ./RSPRecomp njpgdspMain.us.rev1.toml + - name: Hotpatch DXC into RT64's contrib + run: | + # check if dxc was updated before we replace it, to detect changes + echo ${{ inputs.DXC_CHECKSUM }} ./lib/rt64/src/contrib/dxc/bin/x64/dxc | sha256sum --status -c - + + cp -v /usr/local/lib/libdxcompiler.so ./lib/rt64/src/contrib/dxc/lib/x64/libdxcompiler.so + cp -v /usr/local/bin/dxc ./lib/rt64/src/contrib/dxc/bin/x64/dxc + - name: Build ZeldaRecomp + run: |- + # enable ccache + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + + cmake -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER=clang++-17 -DCMAKE_C_COMPILER=clang-17 -DCMAKE_MAKE_PROGRAM=ninja -G Ninja -S . -B cmake-build -DPATCHES_C_COMPILER=clang-17 -DPATCHES_LD=ld.lld-17 -DPATCHES_OBJCOPY=llvm-objcopy-17 + cmake --build cmake-build --config ${{ matrix.type }} --target Zelda64Recompiled -j $(nproc) + - name: Prepare Archive + run: | + mv cmake-build/Zelda64Recompiled Zelda64Recompiled + rm -rf assets/scss + tar -czf Zelda64Recompiled.tar.gz Zelda64Recompiled assets/ gamecontrollerdb.txt + - name: Archive Zelda64Recomp + uses: actions/upload-artifact@v3 + with: + name: Zelda64Recompiled-${{ runner.os }}-X64-${{ matrix.type }} + path: Zelda64Recompiled.tar.gz + - name: Build AppImage + run: |- + ./.github/linux/appimage.sh + - name: Zelda64Recomp AppImage + uses: actions/upload-artifact@v3 + with: + name: Zelda64Recompiled-AppImage-X64-${{ matrix.type }} + path: Zelda64Recompiled-*.AppImage + build-linux-arm64: + runs-on: ${{ format('blaze/{0}', matrix.os) }} + strategy: + matrix: + type: [ Debug, Release ] + os: [ ubuntu-22.04 ] + name: ${{ matrix.os }} (arm64, ${{ matrix.type }}) steps: - name: Checkout uses: actions/checkout@v4 @@ -34,7 +115,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: - key: ${{ matrix.os }}-z64re-ccache-${{ matrix.type }}-${{ matrix.arch }} + key: ${{ matrix.os }}-z64re-ccache-${{ matrix.type }}-arm64-${{ inputs.N64RECOMP_COMMIT }} - name: Install Linux Dependencies run: | sudo apt-get update @@ -52,7 +133,7 @@ jobs: ./configure make -j 10 sudo make install - sudo cp -av /usr/local/lib/libSDL* /lib/x86_64-linux-gnu/ + sudo cp -av /usr/local/lib/libSDL* /lib/aarch64-linux-gnu/ echo ::endgroup:: - name: Prepare Build run: |- @@ -93,18 +174,18 @@ jobs: run: | mv cmake-build/Zelda64Recompiled Zelda64Recompiled rm -rf assets/scss - tar -czf Zelda64Recompiled.tar.gz Zelda64Recompiled assets/ + tar -czf Zelda64Recompiled.tar.gz Zelda64Recompiled assets/ gamecontrollerdb.txt - name: Archive Zelda64Recomp uses: actions/upload-artifact@v4 with: - name: Zelda64Recompiled-${{ runner.os }}-${{ runner.arch }}-${{ matrix.type }} + name: Zelda64Recompiled-${{ runner.os }}-ARM64-${{ matrix.type }} path: Zelda64Recompiled.tar.gz - name: Prepare AppImage run: ./.github/linux/appimage.sh - name: Zelda64Recomp AppImage uses: actions/upload-artifact@v4 with: - name: Zelda64Recompiled-AppImage-${{ runner.arch }}-${{ matrix.type }} + name: Zelda64Recompiled-AppImage-ARM64-${{ matrix.type }} path: Zelda64Recompiled-*.AppImage build-windows: runs-on: windows-latest @@ -186,3 +267,4 @@ jobs: dxil.dll SDL2.dll assets/ + gamecontrollerdb.txt diff --git a/.gitignore b/.gitignore index a718c25..6ff3307 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,6 @@ node_modules/ # Recompiler Linux binary N64Recomp .DS_Store + +# Controller mappings file +gamecontrollerdb.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9944309..159a3e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,8 +80,20 @@ target_sources(PatchesLib PRIVATE set_source_files_properties(${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) # Build patches elf +if(NOT DEFINED PATCHES_C_COMPILER) + set(PATCHES_C_COMPILER clang) +endif() + +if(NOT DEFINED PATCHES_LD) + set(PATCHES_LD ld.lld) +endif() + +if(NOT DEFINED PATCHES_OBJCOPY) + set(PATCHES_OBJCOPY llvm-objcopy) +endif() + add_custom_target(PatchesBin - COMMAND make + COMMAND ${CMAKE_COMMAND} -E env CC=${PATCHES_C_COMPILER} LD=${PATCHES_LD} OBJCOPY=${PATCHES_OBJCOPY} make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/patches BYPRODUCTS ${CMAKE_SOURCE_DIR}/patches/patches.bin ) @@ -103,8 +115,19 @@ add_custom_command(OUTPUT DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.bin ) +# Download controller db file for controller support via SDL2 +set(GAMECONTROLLERDB_COMMIT "b1e4090b3d4266e55feb0793efa35792e05faf66") +set(GAMECONTROLLERDB_URL "https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/${GAMECONTROLLERDB_COMMIT}/gamecontrollerdb.txt") + +file(DOWNLOAD ${GAMECONTROLLERDB_URL} ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt + TLS_VERIFY ON) + +add_custom_target(DownloadGameControllerDB + DEPENDS ${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt) + # Main executable add_executable(Zelda64Recompiled) +add_dependencies(Zelda64Recompiled DownloadGameControllerDB) # Generate mm_shader_cache.c from the MM shader cache if it exists if (EXISTS ${CMAKE_SOURCE_DIR}/shadercache/mm_shader_cache.bin) @@ -184,7 +207,7 @@ if (WIN32) if (DEFINED ENV{SDL2_VERSION}) set(SDL2_VERSION $ENV{SDL2_VERSION}) else() - set(SDL2_VERSION "2.28.5") + set(SDL2_VERSION "2.30.3") endif() # Fetch SDL2 on windows @@ -288,15 +311,12 @@ if (${WIN32}) set (DXC "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/x64/dxc.exe") add_compile_definitions(NOMINMAX) else() - if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") - if (APPLE) - set (DXC "DYLD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/x64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/x64/dxc") - else() - set (DXC "LD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/x64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/x64/dxc") - endif() + if (APPLE) + # Apple's binary is universal, so it'll work on both x86_64 and arm64 + set (DXC "DYLD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/arm64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/arm64/dxc-macos") else() - if (APPLE) - set (DXC "DYLD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/arm64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/arm64/dxc-macos") + if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") + set (DXC "LD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/x64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/x64/dxc") else() set (DXC "LD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/lib/arm64" "${PROJECT_SOURCE_DIR}/lib/rt64/src/contrib/dxc/bin/arm64/dxc-linux") endif() @@ -304,7 +324,7 @@ else() endif() build_vertex_shader(Zelda64Recompiled "shaders/InterfaceVS.hlsl" "shaders/InterfaceVS.hlsl") -build_pixel_shader (Zelda64Recompiled "shaders/InterfacePS.hlsl" "shaders/InterfacePS.hlsl") +build_pixel_shader(Zelda64Recompiled "shaders/InterfacePS.hlsl" "shaders/InterfacePS.hlsl") target_sources(Zelda64Recompiled PRIVATE ${SOURCES}) diff --git a/patches/Makefile b/patches/Makefile index 0416f19..21363fe 100644 --- a/patches/Makefile +++ b/patches/Makefile @@ -1,8 +1,8 @@ TARGET = patches.elf -CC := clang -LD := ld.lld -OBJCOPY := llvm-objcopy +CC ?= clang +LD ?= ld.lld +OBJCOPY ?= llvm-objcopy CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \ -fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \ diff --git a/src/main/main.cpp b/src/main/main.cpp index f730074..d3961a2 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -373,6 +373,11 @@ int main(int argc, char** argv) { SDL_InitSubSystem(SDL_INIT_AUDIO); reset_audio(48000); + // Source controller mappings file + if (SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt") < 0) { + fprintf(stderr, "Failed to load controller mappings: %s\n", SDL_GetError()); + } + // Register supported games and patches for (const auto& game : supported_games) { recomp::register_game(game);