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
00019 static int _sdl_usage;
00020
00021 #ifdef DYNAMICALLY_LOADED_SDL
00022
00023 #include "os/windows/win32.h"
00024
00025 #define M(x) x "\0"
00026 static const char sdl_files[] =
00027 M("sdl.dll")
00028 M("SDL_Init")
00029 M("SDL_InitSubSystem")
00030 M("SDL_GetError")
00031 M("SDL_QuitSubSystem")
00032 M("SDL_UpdateRect")
00033 M("SDL_UpdateRects")
00034 M("SDL_SetColors")
00035 M("SDL_WM_SetCaption")
00036 M("SDL_ShowCursor")
00037 M("SDL_FreeSurface")
00038 M("SDL_PollEvent")
00039 M("SDL_WarpMouse")
00040 M("SDL_GetTicks")
00041 M("SDL_OpenAudio")
00042 M("SDL_PauseAudio")
00043 M("SDL_CloseAudio")
00044 M("SDL_LockSurface")
00045 M("SDL_UnlockSurface")
00046 M("SDL_GetModState")
00047 M("SDL_Delay")
00048 M("SDL_Quit")
00049 M("SDL_SetVideoMode")
00050 M("SDL_EnableKeyRepeat")
00051 M("SDL_EnableUNICODE")
00052 M("SDL_VideoDriverName")
00053 M("SDL_ListModes")
00054 M("SDL_GetKeyState")
00055 M("SDL_LoadBMP_RW")
00056 M("SDL_RWFromFile")
00057 M("SDL_SetColorKey")
00058 M("SDL_WM_SetIcon")
00059 M("SDL_MapRGB")
00060 M("SDL_VideoModeOK")
00061 M("SDL_Linked_Version")
00062 M("")
00063 ;
00064 #undef M
00065
00066 SDLProcs sdl_proc;
00067
00068 static const char *LoadSdlDLL()
00069 {
00070 if (sdl_proc.SDL_Init != NULL) {
00071 return NULL;
00072 }
00073 if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
00074 return "Unable to load sdl.dll";
00075 }
00076 return NULL;
00077 }
00078
00079 #endif
00080
00081
00082 const char *SdlOpen(uint32 x)
00083 {
00084 #ifdef DYNAMICALLY_LOADED_SDL
00085 {
00086 const char *s = LoadSdlDLL();
00087 if (s != NULL) return s;
00088 }
00089 #endif
00090 if (_sdl_usage++ == 0) {
00091 if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
00092 } else if (x != 0) {
00093 if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
00094 }
00095
00096 return NULL;
00097 }
00098
00099 void SdlClose(uint32 x)
00100 {
00101 if (x != 0) {
00102 SDL_CALL SDL_QuitSubSystem(x);
00103 }
00104 if (--_sdl_usage == 0) {
00105 SDL_CALL SDL_Quit();
00106 }
00107 }
00108
00109 #endif