Initial OS X support. #87

This commit is contained in:
Radegast 2014-05-18 23:14:28 +01:00
parent 185f2aaf90
commit 812fb78d52
11 changed files with 150 additions and 51 deletions

View file

@ -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}

View file

@ -37,6 +37,8 @@ If you have questions concerning this license or the applicable additional terms
#ifdef _WIN32
#include <windows.h> // for DebugBreak
#else // POSIX for raise()
#include <signal.h>
#endif
/*

View file

@ -30,6 +30,15 @@ If you have questions concerning this license or the applicable additional terms
#pragma hdrstop
#include "../../precompiled.h"
#ifndef _WIN32
#include <sched.h>
#endif
#ifdef __APPLE__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#ifdef __FreeBSD__
#include <pthread_np.h> // 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;

View file

@ -28,6 +28,10 @@ If you have questions concerning this license or the applicable additional terms
#pragma hdrstop
#include "precompiled.h"
#ifndef _WIN32
#include <signal.h> // for raise()
#endif
/*
================================================================================================
Contains the AssertMacro implementation.

View file

@ -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

View file

@ -46,6 +46,8 @@ typedef HANDLE signalHandle_t;
typedef LONG interlockedInt_t;
#else
#include <pthread.h>
struct signalHandle_t
{
// DG: all this stuff is needed to emulate Window's Event API

View file

@ -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 )

View file

@ -97,9 +97,14 @@ typedef enum
//#define AL_ALEXT_PROTOTYPES
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
#ifdef __APPLE__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
#endif
#include "OpenAL/AL_SoundSample.h"
#include "OpenAL/AL_SoundVoice.h"

View file

@ -45,6 +45,12 @@ static const char** cmdargv = NULL;
static int cmdargc = 0;
// DG end
#if defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
#include <sys/sysctl.h>
#endif
#ifdef ID_MCHECK
#include <mcheck.h>
#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
}

View file

@ -49,6 +49,11 @@ If you have questions concerning this license or the applicable additional terms
#include <android/log.h>
#endif
#if defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#include <sys/statvfs.h>
// 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 )
{

View file

@ -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