2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file sdl.cpp Implementation of SDL support. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-07-25 07:16:10 +00:00
|
|
|
|
|
|
|
#ifdef WITH_SDL
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
#include "sdl.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
|
2011-05-01 19:51:52 +00:00
|
|
|
/** Number of users of the SDL library. */
|
2004-08-09 17:04:08 +00:00
|
|
|
static int _sdl_usage;
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
#ifdef DYNAMICALLY_LOADED_SDL
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-09-01 14:20:35 +00:00
|
|
|
#include "os/windows/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")
|
2006-08-13 08:18:11 +00:00
|
|
|
M("SDL_LoadBMP_RW")
|
|
|
|
M("SDL_RWFromFile")
|
|
|
|
M("SDL_SetColorKey")
|
|
|
|
M("SDL_WM_SetIcon")
|
|
|
|
M("SDL_MapRGB")
|
2009-12-09 02:49:01 +00:00
|
|
|
M("SDL_VideoModeOK")
|
2009-10-14 08:20:42 +00:00
|
|
|
M("SDL_Linked_Version")
|
2004-08-09 17:04:08 +00:00
|
|
|
M("")
|
|
|
|
;
|
|
|
|
#undef M
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
SDLProcs sdl_proc;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static const char *LoadSdlDLL()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-07-24 10:14:39 +00:00
|
|
|
if (sdl_proc.SDL_Init != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
|
|
|
if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return "Unable to load sdl.dll";
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
#endif /* DYNAMICALLY_LOADED_SDL */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-05-01 19:51:52 +00:00
|
|
|
/**
|
|
|
|
* Open the SDL library.
|
|
|
|
* @param x The subsystem to load.
|
|
|
|
*/
|
2009-01-10 00:31:47 +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) {
|
2010-07-24 10:14:39 +00:00
|
|
|
if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
|
2004-11-15 09:05:06 +00:00
|
|
|
} else if (x != 0) {
|
2010-07-24 10:14:39 +00:00
|
|
|
if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-01 19:51:52 +00:00
|
|
|
/**
|
|
|
|
* Close the SDL library.
|
|
|
|
* @param x The subsystem to close.
|
|
|
|
*/
|
2005-07-23 15:16:57 +00:00
|
|
|
void SdlClose(uint32 x)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-07-24 10:14:39 +00:00
|
|
|
if (x != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
SDL_CALL SDL_QuitSubSystem(x);
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
if (--_sdl_usage == 0) {
|
|
|
|
SDL_CALL SDL_Quit();
|
|
|
|
}
|
|
|
|
}
|
2005-07-25 07:16:10 +00:00
|
|
|
|
|
|
|
#endif
|