2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-07-23 15:16:57 +00:00
|
|
|
#include "sdl.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
#include <signal.h>
|
2004-11-17 07:57:28 +00:00
|
|
|
|
|
|
|
#ifdef __MORPHOS__
|
2004-11-17 19:29:24 +00:00
|
|
|
// The system supplied definition of SIG_DFL is wrong on MorphOS
|
|
|
|
#undef SIG_DFL
|
2004-11-17 07:57:28 +00:00
|
|
|
#define SIG_DFL (void (*)(int))0
|
|
|
|
#endif
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int _sdl_usage;
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
#ifdef DYNAMICALLY_LOADED_SDL
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-24 06:09:54 +00:00
|
|
|
#include "win32.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#define M(x) x "\0"
|
2004-09-10 19:02:27 +00:00
|
|
|
static const char sdl_files[] =
|
2004-08-09 17:04:08 +00:00
|
|
|
M("sdl.dll")
|
|
|
|
M("SDL_Init")
|
|
|
|
M("SDL_InitSubSystem")
|
|
|
|
M("SDL_GetError")
|
|
|
|
M("SDL_QuitSubSystem")
|
|
|
|
M("SDL_UpdateRect")
|
|
|
|
M("SDL_UpdateRects")
|
|
|
|
M("SDL_SetColors")
|
|
|
|
M("SDL_WM_SetCaption")
|
|
|
|
M("SDL_ShowCursor")
|
|
|
|
M("SDL_FreeSurface")
|
|
|
|
M("SDL_PollEvent")
|
|
|
|
M("SDL_WarpMouse")
|
|
|
|
M("SDL_GetTicks")
|
|
|
|
M("SDL_OpenAudio")
|
|
|
|
M("SDL_PauseAudio")
|
|
|
|
M("SDL_CloseAudio")
|
|
|
|
M("SDL_LockSurface")
|
|
|
|
M("SDL_UnlockSurface")
|
|
|
|
M("SDL_GetModState")
|
|
|
|
M("SDL_Delay")
|
|
|
|
M("SDL_Quit")
|
|
|
|
M("SDL_SetVideoMode")
|
|
|
|
M("SDL_EnableKeyRepeat")
|
|
|
|
M("SDL_EnableUNICODE")
|
|
|
|
M("SDL_VideoDriverName")
|
|
|
|
M("SDL_ListModes")
|
|
|
|
M("SDL_GetKeyState")
|
|
|
|
M("")
|
|
|
|
;
|
|
|
|
#undef M
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
SDLProcs sdl_proc;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-05 18:05:42 +00:00
|
|
|
static const char *LoadSdlDLL(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-23 15:16:57 +00:00
|
|
|
if (sdl_proc.SDL_Init != NULL)
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
2005-07-24 06:09:54 +00:00
|
|
|
if (!LoadLibraryList((Function*)&sdl_proc, sdl_files))
|
2004-08-09 17:04:08 +00:00
|
|
|
return "Unable to load sdl.dll";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
#endif // DYNAMICALLY_LOADED_SDL
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
static void SdlAbort(int sig)
|
|
|
|
{
|
|
|
|
/* Own hand-made parachute for the cases of failed assertions. */
|
|
|
|
SDL_CALL SDL_Quit();
|
2004-11-17 08:11:24 +00:00
|
|
|
|
|
|
|
switch (sig) {
|
|
|
|
case SIGSEGV:
|
|
|
|
case SIGFPE:
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
raise(sig);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
const char* SdlOpen(uint32 x)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-23 15:16:57 +00:00
|
|
|
#ifdef DYNAMICALLY_LOADED_SDL
|
2004-11-15 09:05:06 +00:00
|
|
|
{
|
2005-02-05 18:05:42 +00:00
|
|
|
const char *s = LoadSdlDLL();
|
2004-11-15 09:05:06 +00:00
|
|
|
if (s != NULL) return s;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|
|
|
|
if (_sdl_usage++ == 0) {
|
|
|
|
if (SDL_CALL SDL_Init(x) == -1)
|
|
|
|
return SDL_CALL SDL_GetError();
|
2004-11-15 09:05:06 +00:00
|
|
|
} else if (x != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (SDL_CALL SDL_InitSubSystem(x) == -1)
|
|
|
|
return SDL_CALL SDL_GetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
signal(SIGABRT, SdlAbort);
|
2004-11-17 08:11:24 +00:00
|
|
|
signal(SIGSEGV, SdlAbort);
|
|
|
|
signal(SIGFPE, SdlAbort);
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
void SdlClose(uint32 x)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-15 09:05:06 +00:00
|
|
|
if (x != 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
SDL_CALL SDL_QuitSubSystem(x);
|
|
|
|
if (--_sdl_usage == 0) {
|
|
|
|
SDL_CALL SDL_Quit();
|
2004-11-15 09:05:06 +00:00
|
|
|
#ifdef UNIX
|
2004-11-17 07:57:28 +00:00
|
|
|
signal(SIGABRT, SIG_DFL);
|
2004-11-17 08:11:24 +00:00
|
|
|
signal(SIGSEGV, SIG_DFL);
|
|
|
|
signal(SIGFPE, SIG_DFL);
|
2004-11-15 09:05:06 +00:00
|
|
|
#endif
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|