From 790dfb2cede4f0c99a130c48b11b7c5003d0f6e8 Mon Sep 17 00:00:00 2001 From: gez Date: Fri, 19 Aug 2011 20:03:54 +0000 Subject: [PATCH] - Applied some parts of Alexey's MacOS patch. git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@1245 b0f79afe-0144-0410-b225-9a4edf0717df --- src/fragglescript/t_load.cpp | 2 +- src/gl/system/gl_interface.cpp | 30 ++++++++------ src/gl/system/gl_interface.h | 6 ++- src/gl/system/gl_system.h | 8 ++++ src/gl/utility/gl_clock.h | 7 ++++ src/p_glnodes.cpp | 2 +- src/sdl/crashcatcher.c | 3 ++ src/sdl/i_main.cpp | 22 ++++++++++ src/sdl/i_system.cpp | 19 ++++++++- src/sdl/sdlglvideo.cpp | 37 ++++++++++++++--- src/sdl/sdlglvideo.h | 2 + src/stats.cpp | 9 +++++ src/stats.h | 73 ++++++++++++++++++++++++++++++++++ 13 files changed, 197 insertions(+), 23 deletions(-) diff --git a/src/fragglescript/t_load.cpp b/src/fragglescript/t_load.cpp index 2d1e49fa..81a00b9a 100644 --- a/src/fragglescript/t_load.cpp +++ b/src/fragglescript/t_load.cpp @@ -342,7 +342,7 @@ void T_LoadScripts(MapData *map) // the default translator is being used. // Custom translators will not be patched. if ((gameinfo.gametype == GAME_Doom || gameinfo.gametype == GAME_Heretic) && level.info->Translator.IsEmpty() && - level.maptype == MAPTYPE_DOOM && SimpleLineTranslations[272 - 2*HasScripts].special == FS_Execute) + (level.maptype == MAPTYPE_DOOM) && SimpleLineTranslations[272 - 2*HasScripts].special == FS_Execute) { FLineTrans t = SimpleLineTranslations[270]; SimpleLineTranslations[270] = SimpleLineTranslations[272]; diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 0bec386f..34c70e4e 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -44,21 +44,21 @@ #include "i_system.h" #include "gl/system/gl_cvars.h" -#ifdef unix +#if defined (unix) || defined (__APPLE__) #include #define wglGetProcAddress(x) (*SDL_GL_GetProcAddress)(x) #endif static void APIENTRY glBlendEquationDummy (GLenum mode); -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB; #endif static TArray m_Extensions; -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) HWND m_Window; HDC m_hDC; HGLRC m_hRC; @@ -77,7 +77,7 @@ int occlusion_type=0; // //========================================================================== -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) static HWND InitDummy() { HMODULE g_hInst = GetModuleHandle(NULL); @@ -298,7 +298,7 @@ static void APIENTRY LoadExtensions() if (strcmp(version, "3.0") >= 0) gl->flags|=RFL_GL_30; -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) PFNWGLSWAPINTERVALEXTPROC vs = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); if (vs) gl->SetVSync = vs; #endif @@ -510,7 +510,7 @@ static void APIENTRY PrintStartupLog() // //========================================================================== -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) static bool SetupPixelFormat(HDC hDC, bool allowsoftware, bool nostencil, int multisample) { int colorDepth; @@ -745,7 +745,7 @@ static bool SetupPixelFormat(bool allowsoftware, bool nostencil, int multisample // //========================================================================== -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) CVAR(Bool, gl_debug, false, 0) static bool APIENTRY InitHardware (HWND Window, bool allowsoftware, bool nostencil, int multisample) @@ -806,7 +806,7 @@ static bool APIENTRY InitHardware (bool allowsoftware, bool nostencil, int multi // //========================================================================== -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) static void APIENTRY Shutdown() { if (m_hRC) @@ -853,17 +853,21 @@ static bool APIENTRY SetFullscreen(const char *devicename, int w, int h, int bit static void APIENTRY iSwapBuffers() { -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) SwapBuffers(m_hDC); #else SDL_GL_SwapBuffers (); #endif } -static BOOL APIENTRY SetVSync(int) +static BOOL APIENTRY SetVSync( int vsync ) { +#if defined (__APPLE__) + return kCGLNoError == CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &vsync ); +#else // !__APPLE__ // empty placeholder return false; +#endif // __APPLE__ } //========================================================================== @@ -982,11 +986,11 @@ void APIENTRY GetContext(RenderContext & gl) gl.SetTextureMode = SetTextureMode; gl.PrintStartupLog = PrintStartupLog; gl.InitHardware = InitHardware; -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) gl.Shutdown = Shutdown; #endif gl.SwapBuffers = iSwapBuffers; -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) gl.SetFullscreen = SetFullscreen; #endif @@ -1068,7 +1072,7 @@ void APIENTRY GetContext(RenderContext & gl) gl.BlendEquation = glBlendEquationDummy; gl.SetVSync = SetVSync; -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) ReadInitExtensions(); //GL is not yet inited in UNIX version, read them later in LoadExtensions #endif diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h index c2c39f95..25278410 100644 --- a/src/gl/system/gl_interface.h +++ b/src/gl/system/gl_interface.h @@ -1,6 +1,10 @@ #ifndef R_RENDER #define R_RENDER +#if defined(__APPLE__) +#define APIENTRY +#endif // __APPLE__ + enum RenderFlags { RFL_NPOT_TEXTURE=1, @@ -54,7 +58,7 @@ struct RenderContext void (APIENTRY * SetTextureMode) (int type); void (APIENTRY * PrintStartupLog) (); BOOL (APIENTRY * SetVSync) (int on); -#ifndef unix +#if !defined (unix) && !defined (__APPLE__) bool (APIENTRY * InitHardware) (HWND, bool allowsoftware, bool nostencil, int multisample); void (APIENTRY * Shutdown) (); #else diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h index b6f61487..4b60a47a 100644 --- a/src/gl/system/gl_system.h +++ b/src/gl/system/gl_system.h @@ -47,7 +47,9 @@ #include #include #include +#if !defined(__APPLE__) #include +#endif #include #ifdef _MSC_VER @@ -62,9 +64,15 @@ #include #include +#if defined(__APPLE__) +#include +#include +#else // !__APPLE__ #include #include #include +#endif // __APPLE__ + #ifdef _WIN32 #define DWORD WINDOWS_DWORD // I don't want to depend on this throughout the GL code! #include diff --git a/src/gl/utility/gl_clock.h b/src/gl/utility/gl_clock.h index cf2255df..45b86e6f 100644 --- a/src/gl/utility/gl_clock.h +++ b/src/gl/utility/gl_clock.h @@ -50,6 +50,12 @@ inline long long GetClockCycle () } #endif +#if defined (__APPLE__) + +typedef cycle_t glcycle_t; + +#else // !__APPLE__ + class glcycle_t { public: @@ -93,6 +99,7 @@ private: long long Counter; }; +#endif // __APPLE__ extern glcycle_t RenderWall,SetupWall,ClipWall,SplitWall; extern glcycle_t RenderFlat,SetupFlat; diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 8f623486..e0a4b9bc 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -1078,7 +1078,7 @@ static FString GetCachePath() FSRef folder; if (noErr == FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kCreateFolder, &folder) && - noErr == FSRefMakePath(&folder, (UInt8*)path.GetChars(), PATH_MAX)) + noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX)) { path = pathstr; } diff --git a/src/sdl/crashcatcher.c b/src/sdl/crashcatcher.c index 73fa4b03..cb7c040f 100644 --- a/src/sdl/crashcatcher.c +++ b/src/sdl/crashcatcher.c @@ -14,6 +14,9 @@ #ifndef PR_SET_PTRACER #define PR_SET_PTRACER 0x59616d61 #endif +#else if defined (__APPLE__) +#include +#endif #endif diff --git a/src/sdl/i_main.cpp b/src/sdl/i_main.cpp index d80d8a43..68346bf6 100644 --- a/src/sdl/i_main.cpp +++ b/src/sdl/i_main.cpp @@ -251,10 +251,12 @@ void I_ShutdownJoysticks(); int main (int argc, char **argv) { +#if !defined (__APPLE__) { int s[4] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS }; cc_install_handlers(argc, argv, 4, s, "zdoom-crash.log", DoomSpecificInfo); } +#endif // !__APPLE__ printf(GAMENAME" v%s - SVN revision %s - SDL version\nCompiled on %s\n\n", DOTVERSIONSTR_NOREV,SVN_REVISION_STRING,__DATE__); @@ -280,6 +282,26 @@ int main (int argc, char **argv) atterm (SDL_Quit); SDL_WM_SetCaption (GAMESIG " " DOTVERSIONSTR " (" __DATE__ ")", NULL); + +#ifdef __APPLE__ + + const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); + if ( NULL != videoInfo ) + { + EXTERN_CVAR( Int, vid_defwidth ) + EXTERN_CVAR( Int, vid_defheight ) + EXTERN_CVAR( Int, vid_defbits ) + EXTERN_CVAR( Bool, vid_vsync ) + EXTERN_CVAR( Bool, fullscreen ) + + vid_defwidth = videoInfo->current_w; + vid_defheight = videoInfo->current_h; + vid_defbits = videoInfo->vfmt->BitsPerPixel; + vid_vsync = True; + fullscreen = True; + } + +#endif // __APPLE__ try { diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index ecaf1a26..a3b1de1e 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -39,6 +39,7 @@ #endif #ifdef __APPLE__ +#include #include #include #include @@ -381,9 +382,25 @@ void STACK_ARGS I_FatalError (const char *error, ...) int index; va_list argptr; va_start (argptr, error); - index = vsprintf (errortext, error, argptr); + index = vsnprintf (errortext, MAX_ERRORTEXT, error, argptr); va_end (argptr); +#ifdef __APPLE__ + // Close window or exit fullscreen and release mouse capture + SDL_Quit(); + + const CFStringRef errorString = CFStringCreateWithCStringNoCopy( kCFAllocatorDefault, + errortext, kCFStringEncodingASCII, kCFAllocatorNull ); + if ( NULL != errorString ) + { + CFOptionFlags dummy; + + CFUserNotificationDisplayAlert( 0, kCFUserNotificationStopAlertLevel, NULL, NULL, NULL, + CFSTR( "Error" ), errorString, CFSTR( "Exit" ), NULL, NULL, &dummy ); + CFRelease( errorString ); + } +#endif // __APPLE__ + // Record error to log (if logging) if (Logfile) { diff --git a/src/sdl/sdlglvideo.cpp b/src/sdl/sdlglvideo.cpp index 7a3c1317..2a50e253 100644 --- a/src/sdl/sdlglvideo.cpp +++ b/src/sdl/sdlglvideo.cpp @@ -95,6 +95,7 @@ static MiniModeInfo WinModes[] = { 1280, 720 }, // 16:9 { 1280, 800 }, // 16:10 { 1280, 960 }, + { 1344, 756 }, // 16:9 { 1360, 768 }, // 16:9 { 1400, 787 }, // 16:9 { 1400, 875 }, // 16:10 @@ -103,10 +104,11 @@ static MiniModeInfo WinModes[] = { 1600, 900 }, // 16:9 { 1600, 1000 }, // 16:10 { 1600, 1200 }, - { 1680, 1050 }, - { 1920, 1080 }, - { 1920, 1200 }, - { 2054, 1536 } + { 1680, 1050 }, // 16:10 + { 1920, 1080 }, // 16:9 + { 1920, 1200 }, // 16:10 + { 2054, 1536 }, + { 2560, 1440 } // 16:9 }; // CODE -------------------------------------------------------------------- @@ -297,14 +299,29 @@ SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen) return; } - Screen = SDL_SetVideoMode (width, height, vid_displaybits, + // Mac OS X version will crash when entering fullscreen mode with BPP <= 8 + // Also it may crash with BPP == 16 on some configurations + // It seems 24 and 32 bits are safe values + // So value of vid_displaybits is ignored and hardcoded constant is used instead + + Screen = SDL_SetVideoMode (width, height, +#if defined(__APPLE__) + 32, +#else // ! __APPLE__ + vid_displaybits, +#endif // __APPLE__ SDL_HWSURFACE|SDL_HWPALETTE|SDL_OPENGL | SDL_GL_DOUBLEBUFFER|SDL_ANYFORMAT| (fullscreen ? SDL_FULLSCREEN : 0)); if (Screen == NULL) return; - m_supportsGamma = !!SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]); + m_supportsGamma = -1 != SDL_GetGammaRamp(m_origGamma[0], m_origGamma[1], m_origGamma[2]); + +#if defined(__APPLE__) + // Need to set title here because a window is not created yet when calling the same function from main() + SDL_WM_SetCaption( GAMESIG " " DOTVERSIONSTR " (" __DATE__ ")", NULL ); +#endif // __APPLE__ } SDLGLFB::~SDLGLFB () @@ -385,6 +402,14 @@ bool SDLGLFB::IsValid () return DFrameBuffer::IsValid() && Screen != NULL; } +void SDLGLFB::SetVSync( bool vsync ) +{ +#if defined (__APPLE__) + const GLint value = vsync ? 1 : 0; + CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &value ); +#endif +} + void SDLGLFB::NewRefreshRate () { } diff --git a/src/sdl/sdlglvideo.h b/src/sdl/sdlglvideo.h index 1e9a81ff..544c5ea2 100644 --- a/src/sdl/sdlglvideo.h +++ b/src/sdl/sdlglvideo.h @@ -49,6 +49,8 @@ public: bool IsValid (); bool IsFullscreen (); + virtual void SetVSync( bool vsync ); + void NewRefreshRate (); friend class SDLGLVideo; diff --git a/src/stats.cpp b/src/stats.cpp index dba058ca..76fe36c2 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -42,6 +42,15 @@ #include "m_swap.h" #include "sbar.h" + +#if defined (__APPLE__) + +mach_timebase_info_data_t cycle_t::s_info; +bool cycle_t::s_initialized; + +#endif // __APPLE__ + + FStat *FStat::FirstStat; FStat::FStat (const char *name) diff --git a/src/stats.h b/src/stats.h index 65eb7392..ed493188 100644 --- a/src/stats.h +++ b/src/stats.h @@ -38,6 +38,77 @@ #ifndef _WIN32 +#if defined (__APPLE__) + + +#include + + +class cycle_t +{ +public: + cycle_t() + { + if ( !s_initialized ) + { + mach_timebase_info( &s_info ); + s_initialized = true; + } + + Reset(); + } + + cycle_t &operator=( const cycle_t &other ) + { + if ( &other != this ) + { + m_seconds = other.m_seconds; + + } + + return *this; + } + + void Reset() + { + m_seconds = 0; + } + + void Clock() + { + m_seconds -= Nanoseconds() * 1e-9; + } + + void Unclock() + { + m_seconds += Nanoseconds() * 1e-9; + } + + double Time() + { + return m_seconds; + } + + double TimeMS() + { + return m_seconds * 1e3; + } + +private: + double m_seconds; + + static mach_timebase_info_data_t s_info; + static bool s_initialized; + + uint64_t Nanoseconds() const + { + return mach_absolute_time() * s_info.numer / s_info.denom; + } + +}; + +#else // !__APPLE__ + #ifdef NO_CLOCK_GETTIME class cycle_t { @@ -100,6 +171,8 @@ private: #endif +#endif // __APPLE__ + #else // Windows