Merge pull request #117 from JanSimek/master

OS X support. #87
This commit is contained in:
Robert Beckebans 2014-05-20 09:27:44 +02:00
commit 9c2124718f
14 changed files with 170 additions and 50 deletions

View file

@ -260,6 +260,8 @@ __________________________________________
- Win64 support
- OS X support
- OpenAL Soft sound backend primarily developed for Linux but works on Windows as well
- Bink video support through FFmpeg

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,14 @@ 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 "../../../sys/posix/posix_public.h"
#endif
#ifdef __FreeBSD__
#include <pthread_np.h> // for pthread_set_name_np
#endif
@ -265,7 +273,7 @@ Sys_Yield
*/
void Sys_Yield()
{
pthread_yield();
sched_yield(); // pthread_yield();
}
/*
@ -411,7 +419,9 @@ bool Sys_SignalWait( signalHandle_t& handle, int timeout )
else
{
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
// 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__)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__i386__)
#define CPUSTRING "x86"
@ -111,12 +110,12 @@ If you have questions concerning this license or the applicable additional terms
#define CPUSTRING "x86_86"
#endif
#ifdef __FreeBSD__
#if defined(__FreeBSD__)
#define BUILD_STRING "freebsd-" CPUSTRING
#define BUILD_OS_ID 3
#else
#elif defined(__linux__)
#define BUILD_STRING "linux-" CPUSTRING
#define BUILD_OS_ID 2
#elif defined(__APPLE__)
#define BUILD_STRING "osx-" 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

@ -406,7 +406,7 @@ static void R_CheckPortableExtensions()
// GL_ARB_vertex_program / GL_ARB_fragment_program
glConfig.fragmentProgramAvailable = GLEW_ARB_fragment_program != 0;
if( glConfig.fragmentProgramAvailable )
//if( glConfig.fragmentProgramAvailable )
{
glGetIntegerv( GL_MAX_TEXTURE_COORDS, ( GLint* )&glConfig.maxTextureCoords );
glGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS, ( GLint* )&glConfig.maxTextureImageUnits );
@ -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,10 @@ static const char** cmdargv = NULL;
static int cmdargc = 0;
// DG end
#if defined(__APPLE__)
#include <sys/sysctl.h>
#endif
#ifdef ID_MCHECK
#include <mcheck.h>
#endif
@ -216,7 +220,9 @@ double Sys_GetClockTicks()
//#error unsupported CPU
// RB begin
struct timespec now;
clock_gettime( CLOCK_MONOTONIC, &now );
return now.tv_sec * 1000000000LL + now.tv_nsec;
// RB end
#endif
@ -409,26 +415,44 @@ 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 )
{
mb = size / ( 1024 * 1024 );
mb = ( mb + 8 ) & ~15;
return mb;
}
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;
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,12 @@ 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/clock_types.h>
#include <mach/mach.h>
#endif
#include <sys/statvfs.h>
// RB end
@ -190,6 +196,53 @@ Sys_Milliseconds
#define D3_CLOCK_TO_USE CLOCK_MONOTONIC
#endif
#ifdef __APPLE__
// OS X doesn't have clock_gettime()
int clock_gettime(clk_id_t clock, struct timespec *tp)
{
switch(clock)
{
case CLOCK_MONOTONIC_RAW:
case CLOCK_MONOTONIC:
{
clock_serv_t clock_ref;
mach_timespec_t tm;
host_name_port_t self = mach_host_self();
memset(&tm, 0, sizeof(tm));
if (KERN_SUCCESS != host_get_clock_service(self, SYSTEM_CLOCK, &clock_ref))
{
mach_port_deallocate(mach_task_self(), self);
return -1;
}
if (KERN_SUCCESS != clock_get_time(clock_ref, &tm))
{
mach_port_deallocate(mach_task_self(), self);
return -1;
}
mach_port_deallocate(mach_task_self(), self);
mach_port_deallocate(mach_task_self(), clock_ref);
tp->tv_sec = tm.tv_sec;
tp->tv_nsec = tm.tv_nsec;
break;
}
case CLOCK_REALTIME:
default:
{
struct timeval now;
if (KERN_SUCCESS != gettimeofday(&now, NULL))
{
return -1;
}
tp->tv_sec = now.tv_sec;
tp->tv_nsec = now.tv_usec * 1000;
break;
}
}
return 0;
}
#endif // __APPLE__
// RB: changed long to int
unsigned int sys_timeBase = 0;
// RB end
@ -270,7 +323,7 @@ uint64 Sys_Microseconds()
#else
uint64 curtime;
struct timespec ts;
clock_gettime( D3_CLOCK_TO_USE, &ts );
if( !sys_microTimeBase )

View file

@ -59,5 +59,10 @@ void Sys_DoStartProcess( const char* exeName, bool dofork = true ); // if not f
char* Posix_ConsoleInput();
#ifdef __APPLE__
enum clk_id_t { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW };
int clock_gettime(clk_id_t clock, struct timespec *tp);
#endif
#endif

View file

@ -935,7 +935,7 @@ sysEvent_t Sys_GetEvent()
return res_none;
#endif
case SDL_MOUSEMOTION:
// DG: return event with absolute mouse-coordinates when in menu
// to fix cursor problems in windowed mode
@ -955,10 +955,15 @@ sysEvent_t Sys_GetEvent()
mouse_polls.Append( mouse_poll_t( M_DELTAX, ev.motion.xrel ) );
mouse_polls.Append( mouse_poll_t( M_DELTAY, ev.motion.yrel ) );
return res;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
return res_none; // Avoid 'unknown event' spam when testing with touchpad
case SDL_MOUSEWHEEL:
res.evType = SE_KEY;

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