Rearrange storage of reserved tracks for railway tiles
[openttd/fttd.git] / src / sdl.cpp
blob91d52d917a9afccc27731ffd05a66d311d0caad8
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file sdl.cpp Implementation of SDL support. */
12 #include "stdafx.h"
14 #ifdef WITH_SDL
16 #include "sdl.h"
17 #include <SDL.h>
19 /** Number of users of the SDL library. */
20 static int _sdl_usage;
22 #ifdef DYNAMICALLY_LOADED_SDL
24 #include "os/windows/win32.h"
26 #define M(x) x "\0"
27 static const char sdl_files[] =
28 M("sdl.dll")
29 M("SDL_Init")
30 M("SDL_InitSubSystem")
31 M("SDL_GetError")
32 M("SDL_QuitSubSystem")
33 M("SDL_UpdateRect")
34 M("SDL_UpdateRects")
35 M("SDL_SetColors")
36 M("SDL_WM_SetCaption")
37 M("SDL_ShowCursor")
38 M("SDL_FreeSurface")
39 M("SDL_PollEvent")
40 M("SDL_WarpMouse")
41 M("SDL_GetTicks")
42 M("SDL_OpenAudio")
43 M("SDL_PauseAudio")
44 M("SDL_CloseAudio")
45 M("SDL_LockSurface")
46 M("SDL_UnlockSurface")
47 M("SDL_GetModState")
48 M("SDL_Delay")
49 M("SDL_Quit")
50 M("SDL_SetVideoMode")
51 M("SDL_EnableKeyRepeat")
52 M("SDL_EnableUNICODE")
53 M("SDL_VideoDriverName")
54 M("SDL_ListModes")
55 M("SDL_GetKeyState")
56 M("SDL_LoadBMP_RW")
57 M("SDL_RWFromFile")
58 M("SDL_SetColorKey")
59 M("SDL_WM_SetIcon")
60 M("SDL_MapRGB")
61 M("SDL_VideoModeOK")
62 M("SDL_Linked_Version")
63 M("")
65 #undef M
67 SDLProcs sdl_proc;
69 static const char *LoadSdlDLL()
71 if (sdl_proc.SDL_Init != NULL) {
72 return NULL;
74 if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
75 return "Unable to load sdl.dll";
77 return NULL;
80 #endif /* DYNAMICALLY_LOADED_SDL */
82 /**
83 * Open the SDL library.
84 * @param x The subsystem to load.
86 const char *SdlOpen(uint32 x)
88 #ifdef DYNAMICALLY_LOADED_SDL
90 const char *s = LoadSdlDLL();
91 if (s != NULL) return s;
93 #endif
94 if (_sdl_usage++ == 0) {
95 if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
96 } else if (x != 0) {
97 if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
100 return NULL;
104 * Close the SDL library.
105 * @param x The subsystem to close.
107 void SdlClose(uint32 x)
109 if (x != 0) {
110 SDL_CALL SDL_QuitSubSystem(x);
112 if (--_sdl_usage == 0) {
113 SDL_CALL SDL_Quit();
117 #endif