1 /* $Id: sdl.cpp 22406 2011-05-01 19:51:52Z rubidium $ */
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/>.
10 /** @file sdl.cpp Implementation of SDL support. */
19 /** Number of users of the SDL library. */
20 static int _sdl_usage
;
22 #ifdef DYNAMICALLY_LOADED_SDL
24 #include "os/windows/win32.h"
27 static const char sdl_files
[] =
30 M("SDL_InitSubSystem")
32 M("SDL_QuitSubSystem")
36 M("SDL_WM_SetCaption")
46 M("SDL_UnlockSurface")
51 M("SDL_EnableKeyRepeat")
52 M("SDL_EnableUNICODE")
53 M("SDL_VideoDriverName")
62 M("SDL_Linked_Version")
69 static const char *LoadSdlDLL()
71 if (sdl_proc
.SDL_Init
!= NULL
) {
74 if (!LoadLibraryList((Function
*)(void *)&sdl_proc
, sdl_files
)) {
75 return "Unable to load sdl.dll";
80 #endif /* DYNAMICALLY_LOADED_SDL */
82 #include "safeguards.h"
85 * Open the SDL library.
86 * @param x The subsystem to load.
88 const char *SdlOpen(uint32 x
)
90 #ifdef DYNAMICALLY_LOADED_SDL
92 const char *s
= LoadSdlDLL();
93 if (s
!= NULL
) return s
;
96 if (_sdl_usage
++ == 0) {
97 if (SDL_CALL
SDL_Init(x
| SDL_INIT_NOPARACHUTE
) == -1) return SDL_CALL
SDL_GetError();
99 if (SDL_CALL
SDL_InitSubSystem(x
) == -1) return SDL_CALL
SDL_GetError();
106 * Close the SDL library.
107 * @param x The subsystem to close.
109 void SdlClose(uint32 x
)
112 SDL_CALL
SDL_QuitSubSystem(x
);
114 if (--_sdl_usage
== 0) {