diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index cd5ba5fa..0d7fcf40 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -1321,6 +1321,9 @@ else() list(APPEND RBDOOM3_SOURCES ${SYS_INCLUDES} ${SYS_SOURCES}) + find_package(OpenGL REQUIRED) + include_directories(${OPENGL_INCLUDE_DIRS}) + if(UNIX) if(FFMPEG) find_package(FFMPEG REQUIRED) @@ -1439,25 +1442,22 @@ else() # make sure precompiled header is deleted after executable is compiled add_dependencies(rm_precomp_header RBDoom3BFG) - IF("${CMAKE_SYSTEM}" MATCHES "Linux") - target_link_libraries(RBDoom3BFG - idlib - GL - pthread - dl - rt - ${SDLx_LIBRARY} - ${OPENAL_LIBRARY} - ${FFMPEG_LIBRARIES} - ) - endif() - IF("${CMAKE_SYSTEM}" MATCHES "FreeBSD") + IF(NOT "${CMAKE_SYSTEM}" MATCHES "Darwin") + set(RT_LIBRARY rt) + ENDIF() + + IF(NOT "${CMAKE_SYSTEM}" MATCHES "FreeBSD") + set(DL_LIBRARY dl) + ENDIF() + + IF(NOT WIN32) target_link_libraries(RBDoom3BFG idlib - GL + ${OPENGL_LIBRARIES} pthread - rt + ${DL_LIBRARY} + ${RT_LIBRARY} ${SDLx_LIBRARY} ${OPENAL_LIBRARY} ${FFMPEG_LIBRARIES} diff --git a/neo/idlib/SoftwareCache.cpp b/neo/idlib/SoftwareCache.cpp index 002a16cf..539e5a42 100644 --- a/neo/idlib/SoftwareCache.cpp +++ b/neo/idlib/SoftwareCache.cpp @@ -37,6 +37,8 @@ If you have questions concerning this license or the applicable additional terms #ifdef _WIN32 #include // for DebugBreak +#else // POSIX for raise() +#include #endif /* diff --git a/neo/idlib/sys/posix/posix_thread.cpp b/neo/idlib/sys/posix/posix_thread.cpp index d51a93f0..e3543246 100644 --- a/neo/idlib/sys/posix/posix_thread.cpp +++ b/neo/idlib/sys/posix/posix_thread.cpp @@ -30,6 +30,15 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "../../precompiled.h" +#ifndef _WIN32 +#include +#endif + +#ifdef __APPLE__ +#include +#include +#endif + #ifdef __FreeBSD__ #include // for pthread_set_name_np #endif @@ -265,7 +274,7 @@ Sys_Yield */ void Sys_Yield() { - pthread_yield(); + sched_yield(); // pthread_yield(); } /* @@ -411,7 +420,17 @@ bool Sys_SignalWait( signalHandle_t& handle, int timeout ) else { timespec ts; - clock_gettime( CLOCK_REALTIME, &ts ); + #ifdef __APPLE__ + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; + #else + clock_gettime( CLOCK_REALTIME, &ts ); + #endif // DG: handle timeouts > 1s better ts.tv_nsec += ( timeout % 1000 ) * 1000000; // millisec to nanosec ts.tv_sec += timeout / 1000; diff --git a/neo/idlib/sys/sys_assert.cpp b/neo/idlib/sys/sys_assert.cpp index 0045b288..0caa142a 100644 --- a/neo/idlib/sys/sys_assert.cpp +++ b/neo/idlib/sys/sys_assert.cpp @@ -28,6 +28,10 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "precompiled.h" +#ifndef _WIN32 +#include // for raise() +#endif + /* ================================================================================================ Contains the AssertMacro implementation. diff --git a/neo/idlib/sys/sys_defines.h b/neo/idlib/sys/sys_defines.h index 82940727..80fedfbf 100644 --- a/neo/idlib/sys/sys_defines.h +++ b/neo/idlib/sys/sys_defines.h @@ -43,7 +43,6 @@ If you have questions concerning this license or the applicable additional terms #define CPUSTRING "x86" #define BUILD_STRING "win-" CPUSTRING -#define BUILD_OS_ID 0 #ifdef _MSC_VER #define ALIGN16( x ) __declspec(align(16)) x @@ -103,7 +102,7 @@ If you have questions concerning this license or the applicable additional terms #endif -#elif defined(__linux__) || defined(__FreeBSD__) +#else // not WIN32 #if defined(__i386__) #define CPUSTRING "x86" @@ -113,10 +112,12 @@ If you have questions concerning this license or the applicable additional terms #ifdef __FreeBSD__ #define BUILD_STRING "freebsd-" CPUSTRING -#define BUILD_OS_ID 3 -#else +#elif __linux__ #define BUILD_STRING "linux-" CPUSTRING -#define BUILD_OS_ID 2 +#elif __APPLE__ +#define BUILD_STRING "osx-" CPUSTRING +#else // unknown OS +#define BUILD_STRING "unknown-" CPUSTRING #endif #define _alloca alloca diff --git a/neo/idlib/sys/sys_threading.h b/neo/idlib/sys/sys_threading.h index 1a8b7fa1..ed2f2703 100644 --- a/neo/idlib/sys/sys_threading.h +++ b/neo/idlib/sys/sys_threading.h @@ -46,6 +46,8 @@ typedef HANDLE signalHandle_t; typedef LONG interlockedInt_t; #else +#include + struct signalHandle_t { // DG: all this stuff is needed to emulate Window's Event API diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 74732f30..57aac532 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -538,7 +538,7 @@ static void R_CheckPortableExtensions() // GL_ARB_vertex_program / GL_ARB_fragment_program if( !glConfig.fragmentProgramAvailable ) { - idLib::Error( "GL_ARB_fragment_program not available" ); + idLib::Warning( "GL_ARB_fragment_program not available" ); } // GLSL if( !glConfig.glslAvailable ) diff --git a/neo/sound/snd_local.h b/neo/sound/snd_local.h index 688ab051..35178498 100644 --- a/neo/sound/snd_local.h +++ b/neo/sound/snd_local.h @@ -97,9 +97,14 @@ typedef enum //#define AL_ALEXT_PROTOTYPES -#include -#include -#include +#ifdef __APPLE__ + #include + #include +#else + #include + #include + #include +#endif #include "OpenAL/AL_SoundSample.h" #include "OpenAL/AL_SoundVoice.h" diff --git a/neo/sys/linux/linux_main.cpp b/neo/sys/linux/linux_main.cpp index d913ca35..9864134f 100644 --- a/neo/sys/linux/linux_main.cpp +++ b/neo/sys/linux/linux_main.cpp @@ -45,6 +45,12 @@ static const char** cmdargv = NULL; static int cmdargc = 0; // DG end +#if defined(__APPLE__) +#include +#include +#include +#endif + #ifdef ID_MCHECK #include #endif @@ -216,7 +222,18 @@ double Sys_GetClockTicks() //#error unsupported CPU // RB begin struct timespec now; - clock_gettime( CLOCK_MONOTONIC, &now ); + + #ifdef __APPLE__ + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + now.tv_sec = mts.tv_sec; + now.tv_nsec = mts.tv_nsec; + #else + clock_gettime( CLOCK_MONOTONIC, &now ); + #endif return now.tv_sec * 1000000000LL + now.tv_nsec; // RB end #endif @@ -409,26 +426,41 @@ returns in megabytes ================ */ int Sys_GetSystemRam() -{ - long count, page_size; - int mb; - - count = sysconf( _SC_PHYS_PAGES ); - if( count == -1 ) - { - common->Printf( "GetSystemRam: sysconf _SC_PHYS_PAGES failed\n" ); +{ + #if defined(__APPLE__) + int mib[2]; + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; + int64_t size = 0; + size_t len = sizeof( size ); + if ( sysctl( mib, 2, &size, &len, NULL, 0 ) == 0 ) + { + return size; + } + + common->Printf( "GetSystemRam: sysctl HW_MEMSIZE failed\n" ); return 512; - } - page_size = sysconf( _SC_PAGE_SIZE ); - if( page_size == -1 ) - { - common->Printf( "GetSystemRam: sysconf _SC_PAGE_SIZE failed\n" ); - return 512; - } - mb = ( int )( ( double )count * ( double )page_size / ( 1024 * 1024 ) ); - // round to the nearest 16Mb - mb = ( mb + 8 ) & ~15; - return mb; + #else + long count, page_size; + int mb; + + count = sysconf( _SC_PHYS_PAGES ); + if( count == -1 ) + { + common->Printf( "GetSystemRam: sysconf _SC_PHYS_PAGES failed\n" ); + return 512; + } + page_size = sysconf( _SC_PAGE_SIZE ); + if( page_size == -1 ) + { + common->Printf( "GetSystemRam: sysconf _SC_PAGE_SIZE failed\n" ); + return 512; + } + mb = ( int )( ( double )count * ( double )page_size / ( 1024 * 1024 ) ); + // round to the nearest 16Mb + mb = ( mb + 8 ) & ~15; + return mb; + #endif } diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index 1d39b45b..8d5e5463 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -49,6 +49,11 @@ If you have questions concerning this license or the applicable additional terms #include #endif +#if defined(__APPLE__) +#include +#include +#endif + #include // RB end @@ -205,7 +210,17 @@ int Sys_Milliseconds() int curtime; struct timespec ts; - clock_gettime( D3_CLOCK_TO_USE, &ts ); + #ifdef __APPLE__ + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; + #else + clock_gettime( D3_CLOCK_TO_USE, &ts ); + #endif if( !sys_timeBase ) { @@ -270,8 +285,18 @@ uint64 Sys_Microseconds() #else uint64 curtime; struct timespec ts; - - clock_gettime( D3_CLOCK_TO_USE, &ts ); + + #ifdef __APPLE__ + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; + #else + clock_gettime( D3_CLOCK_TO_USE, &ts ); + #endif if( !sys_microTimeBase ) { diff --git a/neo/sys/sdl/sdl_glimp.cpp b/neo/sys/sdl/sdl_glimp.cpp index 89faa88c..c689334b 100644 --- a/neo/sys/sdl/sdl_glimp.cpp +++ b/neo/sys/sdl/sdl_glimp.cpp @@ -188,6 +188,10 @@ bool GLimp_Init( glimpParms_t parms ) #if SDL_VERSION_ATLEAST(2, 0, 0) + #ifdef __APPLE__ + r_useOpenGL32.SetInteger( 2 ); // only core profile is supported on OS X + #endif + // RB begin if( r_useOpenGL32.GetInteger() > 0 ) { @@ -209,7 +213,7 @@ bool GLimp_Init( glimpParms_t parms ) SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); } // RB end - + // DG: set display num for fullscreen int windowPos = SDL_WINDOWPOS_UNDEFINED; if( parms.fullScreen > 0 ) @@ -238,6 +242,7 @@ bool GLimp_Init( glimpParms_t parms ) windowPos, parms.width, parms.height, flags ); // DG end + context = SDL_GL_CreateContext( window ); if( !window ) @@ -302,6 +307,10 @@ bool GLimp_Init( glimpParms_t parms ) common->Printf( "No usable GL mode found: %s", SDL_GetError() ); return false; } + + #ifdef __APPLE__ + glewExperimental = GL_TRUE; + #endif GLenum glewResult = glewInit(); if( GLEW_OK != glewResult ) @@ -313,7 +322,7 @@ bool GLimp_Init( glimpParms_t parms ) { common->Printf( "Using GLEW %s\n", glewGetString( GLEW_VERSION ) ); } - + // DG: disable cursor, we have two cursors in menu (because mouse isn't grabbed in menu) SDL_ShowCursor( SDL_DISABLE ); // DG end