sdl.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013
00014 #ifdef WITH_SDL
00015
00016 #include "sdl.h"
00017 #include <SDL.h>
00018
00020 static int _sdl_usage;
00021
00022 #ifdef DYNAMICALLY_LOADED_SDL
00023
00024 #include "os/windows/win32.h"
00025
00026 #define M(x) x "\0"
00027 static const char sdl_files[] =
00028 M("sdl.dll")
00029 M("SDL_Init")
00030 M("SDL_InitSubSystem")
00031 M("SDL_GetError")
00032 M("SDL_QuitSubSystem")
00033 M("SDL_UpdateRect")
00034 M("SDL_UpdateRects")
00035 M("SDL_SetColors")
00036 M("SDL_WM_SetCaption")
00037 M("SDL_ShowCursor")
00038 M("SDL_FreeSurface")
00039 M("SDL_PollEvent")
00040 M("SDL_WarpMouse")
00041 M("SDL_GetTicks")
00042 M("SDL_OpenAudio")
00043 M("SDL_PauseAudio")
00044 M("SDL_CloseAudio")
00045 M("SDL_LockSurface")
00046 M("SDL_UnlockSurface")
00047 M("SDL_GetModState")
00048 M("SDL_Delay")
00049 M("SDL_Quit")
00050 M("SDL_SetVideoMode")
00051 M("SDL_EnableKeyRepeat")
00052 M("SDL_EnableUNICODE")
00053 M("SDL_VideoDriverName")
00054 M("SDL_ListModes")
00055 M("SDL_GetKeyState")
00056 M("SDL_LoadBMP_RW")
00057 M("SDL_RWFromFile")
00058 M("SDL_SetColorKey")
00059 M("SDL_WM_SetIcon")
00060 M("SDL_MapRGB")
00061 M("SDL_VideoModeOK")
00062 M("SDL_Linked_Version")
00063 M("")
00064 ;
00065 #undef M
00066
00067 SDLProcs sdl_proc;
00068
00069 static const char *LoadSdlDLL()
00070 {
00071 if (sdl_proc.SDL_Init != NULL) {
00072 return NULL;
00073 }
00074 if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
00075 return "Unable to load sdl.dll";
00076 }
00077 return NULL;
00078 }
00079
00080 #endif
00081
00086 const char *SdlOpen(uint32 x)
00087 {
00088 #ifdef DYNAMICALLY_LOADED_SDL
00089 {
00090 const char *s = LoadSdlDLL();
00091 if (s != NULL) return s;
00092 }
00093 #endif
00094 if (_sdl_usage++ == 0) {
00095 if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
00096 } else if (x != 0) {
00097 if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
00098 }
00099
00100 return NULL;
00101 }
00102
00107 void SdlClose(uint32 x)
00108 {
00109 if (x != 0) {
00110 SDL_CALL SDL_QuitSubSystem(x);
00111 }
00112 if (--_sdl_usage == 0) {
00113 SDL_CALL SDL_Quit();
00114 }
00115 }
00116
00117 #endif