diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 398be174b..481ddaaef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,9 +3,13 @@ name: Build on: workflow_dispatch: push: - branches: master + branches: + - master + - cicd-update pull_request: - branches: master + branches: + - master + - cicd-update release: types: [created] @@ -19,7 +23,7 @@ jobs: arch: [Win32] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 @@ -40,12 +44,12 @@ jobs: shell: cmd run: msbuild /m /p:Configuration=${{ matrix.build_type }} PACKAGE.vcxproj - #- uses: 'actions/upload-artifact@v3' + #- uses: 'actions/upload-artifact@v4' # with: # name: Windows Binaries (Installer), ${{ matrix.build_type }}, ${{ matrix.arch }} # path: ${{github.workspace}}/build/actions/out/${{ matrix.build_type }}/* - - uses: 'actions/upload-artifact@v3' + - uses: 'actions/upload-artifact@v4' with: name: Windows Package (Installer), ${{ matrix.build_type }}, ${{ matrix.arch }} path: ${{github.workspace}}/build/actions/out/*.exe @@ -83,7 +87,7 @@ jobs: arch: [Win32, x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 @@ -104,12 +108,12 @@ jobs: shell: cmd run: msbuild /m /p:Configuration=${{ matrix.build_type }} PACKAGE.vcxproj - #- uses: 'actions/upload-artifact@v3' + #- uses: 'actions/upload-artifact@v4' # with: # name: Windows Binaries (Portable), ${{ matrix.build_type }}, ${{ matrix.arch }} # path: ${{github.workspace}}/build/actions/out/${{ matrix.build_type }}/* - - uses: 'actions/upload-artifact@v3' + - uses: 'actions/upload-artifact@v4' if: ${{ matrix.build_type == 'RelWithDebInfo' }} with: name: Windows Package (Portable), ${{ matrix.build_type }}, ${{ matrix.arch }} @@ -139,80 +143,9 @@ jobs: } } - vs2019_xp: - name: Build VS 2019 (Portable - WinXP), ${{ matrix.build_type }}, ${{ matrix.arch }} - runs-on: windows-2019 - strategy: - matrix: - build_type: [Debug, RelWithDebInfo] - arch: [Win32] - - steps: - - uses: actions/checkout@v3 - with: - submodules: true - fetch-depth: 0 - - - name: Install WinXP Toolset - shell: powershell - run: | - Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\" - Start-Process -FilePath vs_installer.exe -ArgumentList "modify", "--installPath", "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise", "--add Microsoft.VisualStudio.Component.WinXP", "--quiet", "--norestart", "--nocache" -Wait -PassThru -WindowStyle Hidden - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.1 - - - name: Create Build Environment - run: cmake -E make_directory ${{github.workspace}}/build/actions - - - name: Configure CMake - shell: bash - working-directory: ${{github.workspace}}/build/actions - run: cmake $GITHUB_WORKSPACE -A ${{ matrix.arch }} -T v141_xp -DBuildPortableVersion=ON - - - name: Build - working-directory: ${{github.workspace}}/build/actions - shell: cmd - run: msbuild /m /p:Configuration=${{ matrix.build_type }} PACKAGE.vcxproj - - #- uses: 'actions/upload-artifact@v3' - # with: - # name: Windows Binaries (Portable - WinXP), ${{ matrix.build_type }}, ${{ matrix.arch }} - # path: ${{github.workspace}}/build/actions/out/${{ matrix.build_type }}/* - - - uses: 'actions/upload-artifact@v3' - if: ${{ matrix.build_type == 'RelWithDebInfo' }} - with: - name: Windows Package (Portable - WinXP), ${{ matrix.build_type }}, ${{ matrix.arch }} - path: ${{github.workspace}}/build/actions/out/*.zip - - # As actions/upload-release-asset seems to demand exact filenames and content types we use a script instead - - name: Upload Release - if: ${{ github.event_name == 'release' && matrix.build_type == 'RelWithDebInfo' }} - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const fs = require('fs').promises; - for ( let filename of await fs.readdir(String.raw`${{github.workspace}}/build/actions/out/`) ) - { - if ( filename.endsWith('.zip') ) - { - await github.rest.repos.uploadReleaseAsset( - { - owner: context.repo.owner, - repo: context.repo.repo, - release_id: ${{ github.event.release.id }}, - name: filename.split('.').slice(0, -1).join('.') + "-winxp.zip", - data: await fs.readFile( String.raw`${{github.workspace}}/build/actions/out/` + filename ) - } - ); - } - } - macos: name: Build macOS (${{ matrix.portable }}), ${{ matrix.build_type }}, ${{ matrix.arch }} - runs-on: macos-12 + runs-on: macos-13 strategy: matrix: build_type: [Debug, Release] @@ -220,11 +153,24 @@ jobs: arch: [x86_64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 + - name: Patch mvsdk CMake version + if: always() + shell: bash + run: | + FILE="${{ github.workspace }}/src/mvsdk/CMakeLists.txt" + if [ -f "$FILE" ]; then + # Replace first line that starts with cmake_minimum_required + sed -i '' '1s/.*/cmake_minimum_required(VERSION 3.1...3.31)/' "$FILE" + echo "Patched mvsdk CMakeLists.txt" + else + echo "mvsdk CMakeLists.txt not found!" + fi + - name: Set CMake parameters id: cmakeargs shell: bash @@ -243,7 +189,7 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{github.workspace}}/build/actions - run: cmake -G "Unix Makefiles" -DUseInternalLibs=ON ${{ steps.cmakeargs.outputs.PORTABLE }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} $GITHUB_WORKSPACE + run: cmake -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=14 -DUseInternalLibs=ON ${{ steps.cmakeargs.outputs.PORTABLE }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} $GITHUB_WORKSPACE - name: Build working-directory: ${{github.workspace}}/build/actions @@ -255,12 +201,12 @@ jobs: shell: bash run: make package - #- uses: 'actions/upload-artifact@v3' + #- uses: 'actions/upload-artifact@v4' # with: # name: macOS Binaries (${{ matrix.portable }}), ${{ matrix.build_type }}, ${{ matrix.arch }} # path: ${{github.workspace}}/build/actions/out/${{ matrix.build_type }}/* - - uses: 'actions/upload-artifact@v3' + - uses: 'actions/upload-artifact@v4' if: ${{ matrix.build_type == 'Release' }} with: name: macOS Package (${{ matrix.portable }}), ${{ matrix.build_type }}, ${{ matrix.arch }} @@ -297,12 +243,13 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - container_image: ["ubuntu:16.04", "i386/ubuntu:16.04"] + #container_image: ["ubuntu:16.04", "i386/ubuntu:16.04"] + container_image: ["ubuntu:22.04", "i386/ubuntu:18.04"] build_type: [Debug, Release] portable: [Portable, Non-Portable] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 @@ -312,9 +259,9 @@ jobs: shell: bash run: | if [ "${{ matrix.portable }}" == "Portable" ]; then - OPTIONS="-DUseInternalLibs=ON -DBuildPortableVersion=ON" + OPTIONS="-DCMAKE_CXX_STANDARD=14 -DUseInternalLibs=ON -DBuildPortableVersion=ON" else - OPTIONS="-DUseInternalLibs=OFF -DBuildPortableVersion=OFF" + OPTIONS="-DCMAKE_CXX_STANDARD=14 -DUseInternalLibs=OFF -DBuildPortableVersion=OFF" fi [[ "${{ matrix.container_image}}" == i386* ]] && OPTIONS="$OPTIONS -DSystemProcessor=i386" echo "OPTIONS=$OPTIONS" >> $GITHUB_OUTPUT @@ -328,7 +275,7 @@ jobs: podman pull docker.io/${{ matrix.container_image }} podman run --name buildenv -v ${{github.workspace}}:/jk2mv -td docker.io/${{ matrix.container_image }} /bin/bash podman exec buildenv apt-get update - podman exec buildenv apt-get install -y git zip wget libfuse2 build-essential libsdl2-dev libgl1-mesa-dev libopenal-dev libjpeg-dev libpng-dev libminizip-dev cmake rpm + podman exec buildenv apt-get install -y git zip wget libfuse2 build-essential libsdl2-dev libgl1-mesa-dev libopenal-dev libjpeg-dev libpng-dev libminizip-dev cmake rpm file mkdir -p ${{github.workspace}}/build/actions - name: Configure CMake @@ -343,12 +290,12 @@ jobs: shell: bash run: podman exec -w /jk2mv/build/actions buildenv make package - #- uses: 'actions/upload-artifact@v3' + #- uses: 'actions/upload-artifact@v4' # with: # name: ${{ steps.parameters.outputs.BINARTIFACTNAME }} # path: ${{github.workspace}}/build/actions/out/${{ matrix.build_type }}/* - - uses: 'actions/upload-artifact@v3' + - uses: 'actions/upload-artifact@v4' if: ${{ matrix.build_type == 'Release' }} with: name: ${{ steps.parameters.outputs.PKGARTIFACTNAME }} diff --git a/CMakeLists.txt b/CMakeLists.txt index c8f9a9393..7a98ab217 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.1...3.31) +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") # For checks in subdirectories set(InMV TRUE) diff --git a/src/client/cl_main.cpp b/src/client/cl_main.cpp index 1201c5b1c..348fc4e70 100644 --- a/src/client/cl_main.cpp +++ b/src/client/cl_main.cpp @@ -2599,7 +2599,6 @@ void CL_ShutdownRef( qboolean restarting ) { if ( rendererLib != NULL ) { Sys_UnloadDll (rendererLib); - //Sys_UnloadModuleLibrary? rendererLib = NULL; } } diff --git a/src/qcommon/vm.cpp b/src/qcommon/vm.cpp index dad369c8d..d4c2c6001 100644 --- a/src/qcommon/vm.cpp +++ b/src/qcommon/vm.cpp @@ -808,7 +808,7 @@ void VM_Free( vm_t *vm ) { vm->destroy(vm); if ( vm->dllHandle ) { - Sys_UnloadModuleLibrary( vm->dllHandle ); + Sys_UnloadDll( vm->dllHandle ); Com_Memset( vm, 0, sizeof( *vm ) ); } #if 0 // now automatically freed by hunk diff --git a/src/rd-vulkan/CMakeLists.txt b/src/rd-vulkan/CMakeLists.txt index b08b0e4e4..00fde9a5c 100644 --- a/src/rd-vulkan/CMakeLists.txt +++ b/src/rd-vulkan/CMakeLists.txt @@ -123,6 +123,8 @@ if (BuildMVMP) source_group("ghoul2" FILES ${MPVulkanRendererGhoul2Files}) set(MPVulkanRendererFiles ${MPVulkanRendererFiles} ${MPVulkanRendererGhoul2Files}) + set(MPVulkanRendererIncludeDirectories ${MPVulkanRendererIncludeDirectories} "${MPDir}/ghoul2") + #set(MPVulkanRendererOtherFiles # "../../mv_setup.h" #) @@ -203,7 +205,7 @@ if (BuildMVMP) ) set_target_properties(${MPVulkanRenderer} PROPERTIES C_STANDARD 90) - set_target_properties(${MPVulkanRenderer} PROPERTIES INCLUDE_DIRECTORIES "${MPVulkanRendererIncludeDirectories}") + target_include_directories(${MPVulkanRenderer} PRIVATE ${MPVulkanRendererIncludeDirectories}) set_target_properties(${MPVulkanRenderer} PROPERTIES PROJECT_LABEL "jk2mv rd-vulkan") target_link_libraries(${MPVulkanRenderer} ${MPVulkanRendererLibraries}) diff --git a/src/rd-vulkan/tr_WorldEffects.cpp b/src/rd-vulkan/tr_WorldEffects.cpp index b9de0bb3e..2555b3f47 100644 --- a/src/rd-vulkan/tr_WorldEffects.cpp +++ b/src/rd-vulkan/tr_WorldEffects.cpp @@ -1770,7 +1770,8 @@ CRainSystem::CRainSystem(int maxRain) : mImage = R_FindImageFile("gfx/world/rain", IMGFLAG_NONE); -#if 0 GL_Bind(mImage); +#if 0 + GL_Bind(mImage); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); #endif diff --git a/src/rd-vulkan/tr_init.cpp b/src/rd-vulkan/tr_init.cpp index 7c492547c..a90076aa7 100644 --- a/src/rd-vulkan/tr_init.cpp +++ b/src/rd-vulkan/tr_init.cpp @@ -29,7 +29,7 @@ along with this program; if not, see . #include "../rd-common/tr_common.h" #include "tr_WorldEffects.h" #include "qcommon/MiniHeap.h" -#include "ghoul2/g2_local.h" +#include "ghoul2/G2_local.h" glconfig_t glConfig; glconfigExt_t glConfigExt; diff --git a/src/rd-vulkan/tr_main.cpp b/src/rd-vulkan/tr_main.cpp index 936a332ec..78c707197 100644 --- a/src/rd-vulkan/tr_main.cpp +++ b/src/rd-vulkan/tr_main.cpp @@ -24,7 +24,7 @@ along with this program; if not, see . // tr_main.c -- main control flow for each frame #include "tr_local.h" -#include "ghoul2/g2_local.h" +#include "ghoul2/G2_local.h" trGlobals_t tr; @@ -1676,4 +1676,4 @@ void R_RenderView( const viewParms_t *parms ) { } R_SortDrawSurfs( tr.refdef.drawSurfs + firstDrawSurf, numDrawSurfs - firstDrawSurf ); -} \ No newline at end of file +} diff --git a/src/rd-vulkan/tr_scene.cpp b/src/rd-vulkan/tr_scene.cpp index 182664508..60efb36b5 100644 --- a/src/rd-vulkan/tr_scene.cpp +++ b/src/rd-vulkan/tr_scene.cpp @@ -24,7 +24,7 @@ along with this program; if not, see . #include "tr_local.h" #include "ghoul2/G2.h" -#include "ghoul2/g2_local.h" +#include "ghoul2/G2_local.h" #ifdef USE_JK2 #include "rd-common/matcomp.h" #else diff --git a/src/rd-vulkan/vk_init.cpp b/src/rd-vulkan/vk_init.cpp index 6819894a6..e05ffb058 100644 --- a/src/rd-vulkan/vk_init.cpp +++ b/src/rd-vulkan/vk_init.cpp @@ -27,7 +27,7 @@ along with this program; if not, see . #include "../rd-common/tr_common.h" #include "tr_WorldEffects.h" #include "qcommon/MiniHeap.h" -#include "ghoul2/g2_local.h" +#include "ghoul2/G2_local.h" int vkSamples = VK_SAMPLE_COUNT_1_BIT; int vkMaxSamples = VK_SAMPLE_COUNT_1_BIT; @@ -703,4 +703,4 @@ void vk_shutdown( void ) Com_Memset(&vk_world, 0, sizeof(vk_world)); vk_deinit_library(); -} \ No newline at end of file +} diff --git a/src/sys/sys_main.cpp b/src/sys/sys_main.cpp index 9af4bca7d..077824854 100644 --- a/src/sys/sys_main.cpp +++ b/src/sys/sys_main.cpp @@ -22,6 +22,10 @@ #include "../sys/sys_public.h" #include "con_local.h" +#ifdef MACOS_X +#include +#endif + static char binaryPath[ MAX_OSPATH ] = { 0 }; static char installPath[ MAX_OSPATH ] = { 0 }; @@ -58,12 +62,80 @@ void Sys_SetDefaultInstallPath(const char *path) Sys_DefaultInstallPath ================= */ +#if defined(MACOS_X) +static char *last_strstr(const char *haystack, const char *needle) +{ + if (*needle == '\0') + return (char *) haystack; + + char *result = NULL; + for (;;) { + char *p = (char *)strstr(haystack, needle); + if (p == NULL) + break; + result = p; + haystack = p + 1; + } + + return result; +} +#endif // MACOS_X + +#if !defined(MACOS_X) && !defined(_WIN32) && defined(INSTALLED) +#include + +char *Sys_LinuxGetInstallPrefix() { + static char path[MAX_OSPATH]; + int i; + + readlink("/proc/self/exe", path, sizeof(path)); + + // from: /usr/local/bin/jk2mvmp + // to: /usr/local + for (i = 0; i < 2; i++) { + char *l = strrchr(path, '/'); + if (!l) { + break; + } + + *l = 0; + } + + return path; +} +#endif + char *Sys_DefaultInstallPath(void) { - if (*installPath) - return installPath; - else + if (*installPath) { + return installPath; + } else { +#if defined(MACOS_X) && defined(INSTALLED) + // Inside the app... + static char path[MAX_OSPATH]; + char *override; + + uint32_t size = sizeof(path); + if (_NSGetExecutablePath(path, &size)) { + return Sys_Cwd(); + } + + override = last_strstr(path, "MacOS"); + if (!override) { + return Sys_Cwd(); + } + + override[5] = 0; + return path; +#elif !defined(MACOS_X) && !defined(_WIN32) && defined(INSTALLED) + static char path[MAX_OSPATH]; + + Com_sprintf(path, sizeof(path), "%s/share/jk2mv", Sys_LinuxGetInstallPrefix()); + return path; +#else return Sys_Cwd(); +#endif + } } /* @@ -240,22 +312,6 @@ time_t Sys_FileTime(const char *path) { return buf.st_mtime; } - -/* -================= -Sys_UnloadModuleLibrary -================= -*/ -void Sys_UnloadModuleLibrary(void *dllHandle) { - if (!dllHandle) { - return; - } - - if (!FreeLibrary((HMODULE)dllHandle)) { - Com_Error(ERR_FATAL, "Sys_UnloadDll FreeLibrary failed"); - } -} - /* ================= Sys_UnloadDll @@ -342,10 +398,10 @@ Used to load a module (jk2mpgame, cgame, ui) dll ================= */ void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint_t *entryPoint, intptr_t(QDECL *systemcalls)(intptr_t, ...)) { - HMODULE libHandle; + void *libHandle = NULL; void (QDECL *dllEntry)(intptr_t(QDECL *syscallptr)(intptr_t, ...)); const char *path, *filePath; - char filename[MAX_QPATH]; + char filename[MAX_OSPATH]; Com_sprintf(filename, sizeof(filename), "%s_" ARCH_STRING "." LIBRARY_EXTENSION, name); @@ -354,14 +410,14 @@ void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint filePath = FS_BuildOSPath(path, NULL, filename); Com_DPrintf("Loading module: %s...", filePath); - libHandle = LoadLibraryA(filePath); + libHandle = Sys_LoadLibrary(filePath); if (!libHandle) { Com_DPrintf(" failed!\n"); path = Cvar_VariableString("fs_homepath"); filePath = FS_BuildOSPath(path, NULL, filename); Com_DPrintf("Loading module: %s...", filePath); - libHandle = LoadLibraryA(filePath); + libHandle = Sys_LoadLibrary(filePath); if (!libHandle) { Com_DPrintf(" failed!\n"); return NULL; @@ -372,12 +428,12 @@ void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint Com_DPrintf(" success!\n"); } } else { - char dllPath[MAX_PATH]; + char dllPath[MAX_OSPATH]; path = Cvar_VariableString("fs_basepath"); Com_sprintf(dllPath, sizeof(dllPath), "%s\\%s", path, filename); Com_DPrintf("Loading module: %s...", dllPath); - libHandle = LoadLibraryA(dllPath); + libHandle = Sys_LoadLibrary(dllPath); if (!libHandle) { Com_DPrintf(" failed!\n"); return NULL; @@ -386,18 +442,18 @@ void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint } } - dllEntry = (void (QDECL *)(intptr_t(QDECL *)(intptr_t, ...)))GetProcAddress(libHandle, "dllEntry"); - *entryPoint = (VM_EntryPoint_t)GetProcAddress(libHandle, "vmMain"); + dllEntry = (void (QDECL *)(intptr_t(QDECL *)(intptr_t, ...)))Sys_LoadFunction( libHandle, "dllEntry" ); + *entryPoint = (VM_EntryPoint_t)Sys_LoadFunction( libHandle, "vmMain" ); if (!*entryPoint) { Com_DPrintf("Could not find vmMain in %s\n", filename); - FreeLibrary(libHandle); + Sys_UnloadLibrary(libHandle); return NULL; } if (!dllEntry) { Com_DPrintf("Could not find dllEntry in %s\n", filename); - FreeLibrary(libHandle); + Sys_UnloadLibrary(libHandle); return NULL; } diff --git a/src/sys/sys_public.h b/src/sys/sys_public.h index 5361b2c81..b83e4d718 100644 --- a/src/sys/sys_public.h +++ b/src/sys/sys_public.h @@ -77,7 +77,6 @@ void Sys_Init (void); typedef intptr_t (QDECL *VM_EntryPoint_t)( int, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t ); void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint_t *entryPoint, intptr_t(QDECL *systemcalls)(intptr_t, ...)); -void Sys_UnloadModuleLibrary(void *dllHandle); void Sys_UnloadDll( void *dllHandle ); char *Sys_GetCurrentUser( void ); diff --git a/src/sys/sys_unix.cpp b/src/sys/sys_unix.cpp index 686cc1612..ce3b5d60d 100644 --- a/src/sys/sys_unix.cpp +++ b/src/sys/sys_unix.cpp @@ -295,85 +295,6 @@ char *Sys_DefaultCDPath(void) return cdPath; } -void Sys_SetDefaultInstallPath(const char *path) -{ - Q_strncpyz(installPath, path, sizeof(installPath)); -} - -#if defined(MACOS_X) -static char *last_strstr(const char *haystack, const char *needle) -{ - if (*needle == '\0') - return (char *) haystack; - - char *result = NULL; - for (;;) { - char *p = (char *)strstr(haystack, needle); - if (p == NULL) - break; - result = p; - haystack = p + 1; - } - - return result; -} -#endif // MACOS_X - -#if !defined(MACOS_X) && defined(INSTALLED) -char *Sys_LinuxGetInstallPrefix() { - static char path[MAX_OSPATH]; - int i; - - readlink("/proc/self/exe", path, sizeof(path)); - - // from: /usr/local/bin/jk2mvmp - // to: /usr/local - for (i = 0; i < 2; i++) { - char *l = strrchr(path, '/'); - if (!l) { - break; - } - - *l = 0; - } - - return path; -} -#endif - -char *Sys_DefaultInstallPath(void) -{ - if (*installPath) { - return installPath; - } else { -#if defined(MACOS_X) && defined(INSTALLED) - // Inside the app... - static char path[MAX_OSPATH]; - char *override; - - uint32_t size = sizeof(path); - if (_NSGetExecutablePath(path, &size)) { - return Sys_Cwd(); - } - - override = last_strstr(path, "MacOS"); - if (!override) { - return Sys_Cwd(); - } - - override[5] = 0; - return path; -#elif !defined(MACOS_X) && defined(INSTALLED) - static char path[MAX_OSPATH]; - - Com_sprintf(path, sizeof(path), "%s/share/jk2mv", Sys_LinuxGetInstallPrefix()); - return path; -#else - return Sys_Cwd(); -#endif - } -} - void Sys_SetDefaultHomePath(const char *path) { Q_strncpyz(homePath, path, sizeof(homePath)); @@ -408,8 +329,27 @@ char *Sys_DefaultHomePath(void) #endif } -// try to find assets from /Applications (Appstore JK2) or Steam -// if not found try to find it in the same directory this app is +// Try to find assets from /Applications (Appstore JKA) or Steam. +// If neither worked try to find them in the same directory the jk2mv app is in. +#if defined(MACOS_X) +static char *last_strstr(const char *haystack, const char *needle) +{ + if (*needle == '\0') + return (char *) haystack; + + char *result = NULL; + for (;;) { + char *p = (char *)strstr(haystack, needle); + if (p == NULL) + break; + result = p; + haystack = p + 1; + } + + return result; +} +#endif // MACOS_X + char *Sys_DefaultAssetsPath() { #if defined(MACOS_X) && defined(INSTALLED) static char path[MAX_OSPATH]; @@ -453,8 +393,6 @@ char *Sys_DefaultAssetsPath() { #endif } -// Try to find assets from /Applications (Appstore JKA) or Steam. -// If neither worked try to find them in the same directory the jk2mv app is in. char *Sys_DefaultAssetsPathJKA() { #if defined(MACOS_X) && defined(INSTALLED) static char path[MAX_OSPATH]; @@ -702,97 +640,6 @@ void Sys_Sleep( int msec ) } } -/* -================= -Sys_UnloadModuleLibrary -================= -*/ -void Sys_UnloadModuleLibrary(void *dllHandle) { - if (!dllHandle) { - return; - } - - dlclose(dllHandle); -} - -/* -================= -Sys_LoadModuleLibrary - -Used to load a module (jk2mpgame, cgame, ui) so/dylib -================= -*/ -void *Sys_LoadModuleLibrary(const char *name, qboolean mvOverride, VM_EntryPoint_t *entryPoint, intptr_t(QDECL *systemcalls)(intptr_t, ...)) { - void (*dllEntry)(intptr_t(*syscallptr)(intptr_t, ...)); - char filename[MAX_QPATH]; - const char *path, *filePath; - void *libHandle; - - Com_sprintf(filename, sizeof(filename), "%s_" ARCH_STRING "." LIBRARY_EXTENSION, name); - - if (!mvOverride) { - path = Cvar_VariableString("fs_basepath"); - filePath = FS_BuildOSPath(path, NULL, filename); - - Com_DPrintf("Loading module: %s...", filePath); - assert(!dlopen(filePath, RTLD_NOLOAD)); - libHandle = dlopen(filePath, RTLD_NOW); - if (!libHandle) { - Com_DPrintf(" failed: %s\n", dlerror()); - path = Cvar_VariableString("fs_homepath"); - filePath = FS_BuildOSPath(path, NULL, filename); - - Com_DPrintf("Loading module: %s...", filePath); - assert(!dlopen(filePath, RTLD_NOLOAD)); - libHandle = dlopen(filePath, RTLD_NOW); - if (!libHandle) { - Com_DPrintf(" failed: %s\n", dlerror()); - return NULL; - } else { - Com_DPrintf(" success!\n"); - } - } else { - Com_DPrintf(" success!\n"); - } - } else { - char lpath[1024]; - -#if !defined(MACOS_X) && defined(INSTALLED) - Com_sprintf(lpath, sizeof(lpath), "%s/lib/%s", Sys_LinuxGetInstallPrefix(), filename); -#else - path = Cvar_VariableString("fs_basepath"); - Com_sprintf(lpath, sizeof(lpath), "%s/%s", path, filename); -#endif - - Com_DPrintf("Loading module: %s...", lpath); - assert(!dlopen(lpath, RTLD_NOLOAD)); - libHandle = dlopen(lpath, RTLD_NOW); - if (!libHandle) { - Com_DPrintf(" failed: %s\n", dlerror()); - return NULL; - } else { - Com_DPrintf(" success!\n"); - } - } - - dllEntry = (void (*)(intptr_t (*)(intptr_t,...))) dlsym(libHandle, "dllEntry"); - *entryPoint = (VM_EntryPoint_t)dlsym(libHandle, "vmMain"); - if ( !*entryPoint ) { - Com_DPrintf("Could not find vmMain in %s\n", filename); - dlclose(libHandle); - return NULL; - } - - if (!dllEntry) { - Com_DPrintf("Could not find dllEntry in %s\n", filename); - dlclose(libHandle); - return NULL; - } - - dllEntry(systemcalls); - return libHandle; -} - void Sys_SetTaskbarState(void *win_handle, tbstate_t state, uint64_t current, uint64_t total) { // TODO: OSX Dock support }