tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" tron@2189: tron@2189: #ifdef WITH_SDL tron@2189: Darkvater@1891: #include "openttd.h" tron@2171: #include "sdl.h" truelight@0: #include truelight@0: truelight@0: #ifdef UNIX truelight@0: #include tron@443: tron@443: #ifdef __MORPHOS__ tron@454: // The system supplied definition of SIG_DFL is wrong on MorphOS tron@454: #undef SIG_DFL tron@443: #define SIG_DFL (void (*)(int))0 tron@443: #endif truelight@0: #endif truelight@0: truelight@0: static int _sdl_usage; truelight@0: tron@2171: #ifdef DYNAMICALLY_LOADED_SDL truelight@0: tron@2183: #include "win32.h" truelight@0: truelight@0: #define M(x) x "\0" truelight@193: static const char sdl_files[] = truelight@0: M("sdl.dll") truelight@0: M("SDL_Init") truelight@0: M("SDL_InitSubSystem") truelight@0: M("SDL_GetError") truelight@0: M("SDL_QuitSubSystem") truelight@0: M("SDL_UpdateRect") truelight@0: M("SDL_UpdateRects") truelight@0: M("SDL_SetColors") truelight@0: M("SDL_WM_SetCaption") truelight@0: M("SDL_ShowCursor") truelight@0: M("SDL_FreeSurface") truelight@0: M("SDL_PollEvent") truelight@0: M("SDL_WarpMouse") truelight@0: M("SDL_GetTicks") truelight@0: M("SDL_OpenAudio") truelight@0: M("SDL_PauseAudio") truelight@0: M("SDL_CloseAudio") truelight@0: M("SDL_LockSurface") truelight@0: M("SDL_UnlockSurface") truelight@0: M("SDL_GetModState") truelight@0: M("SDL_Delay") truelight@0: M("SDL_Quit") truelight@0: M("SDL_SetVideoMode") truelight@0: M("SDL_EnableKeyRepeat") truelight@0: M("SDL_EnableUNICODE") truelight@0: M("SDL_VideoDriverName") truelight@0: M("SDL_ListModes") truelight@0: M("SDL_GetKeyState") Darkvater@4256: M("SDL_LoadBMP_RW") Darkvater@4256: M("SDL_RWFromFile") Darkvater@4256: M("SDL_SetColorKey") Darkvater@4256: M("SDL_WM_SetIcon") Darkvater@4256: M("SDL_MapRGB") truelight@0: M("") truelight@0: ; truelight@0: #undef M truelight@0: tron@2171: SDLProcs sdl_proc; truelight@0: tron@1301: static const char *LoadSdlDLL(void) truelight@0: { tron@2171: if (sdl_proc.SDL_Init != NULL) truelight@0: return NULL; truelight@2903: if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) truelight@0: return "Unable to load sdl.dll"; truelight@0: return NULL; truelight@0: } truelight@0: tron@2171: #endif // DYNAMICALLY_LOADED_SDL truelight@0: truelight@0: truelight@0: #ifdef UNIX truelight@0: static void SdlAbort(int sig) truelight@0: { truelight@0: /* Own hand-made parachute for the cases of failed assertions. */ truelight@0: SDL_CALL SDL_Quit(); tron@444: tron@444: switch (sig) { tron@444: case SIGSEGV: tron@444: case SIGFPE: tron@444: signal(sig, SIG_DFL); tron@444: raise(sig); tron@444: break; tron@444: tron@444: default: tron@444: break; tron@444: } truelight@0: } truelight@0: #endif truelight@0: truelight@0: tron@2171: const char* SdlOpen(uint32 x) truelight@0: { tron@2171: #ifdef DYNAMICALLY_LOADED_SDL tron@423: { tron@1301: const char *s = LoadSdlDLL(); tron@423: if (s != NULL) return s; tron@423: } truelight@0: #endif truelight@0: if (_sdl_usage++ == 0) { truelight@0: if (SDL_CALL SDL_Init(x) == -1) truelight@0: return SDL_CALL SDL_GetError(); tron@423: } else if (x != 0) { truelight@0: if (SDL_CALL SDL_InitSubSystem(x) == -1) truelight@0: return SDL_CALL SDL_GetError(); truelight@0: } truelight@0: truelight@0: #ifdef UNIX truelight@0: signal(SIGABRT, SdlAbort); tron@444: signal(SIGSEGV, SdlAbort); tron@444: signal(SIGFPE, SdlAbort); truelight@0: #endif truelight@0: truelight@0: return NULL; truelight@0: } truelight@0: tron@2171: void SdlClose(uint32 x) truelight@0: { tron@423: if (x != 0) truelight@0: SDL_CALL SDL_QuitSubSystem(x); truelight@0: if (--_sdl_usage == 0) { truelight@0: SDL_CALL SDL_Quit(); tron@423: #ifdef UNIX tron@443: signal(SIGABRT, SIG_DFL); tron@444: signal(SIGSEGV, SIG_DFL); tron@444: signal(SIGFPE, SIG_DFL); tron@423: #endif truelight@0: } truelight@0: } tron@2189: tron@2189: #endif