summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2019-03-02 00:05:36 +0000
committerPatric Stout <truebrain@openttd.org>2019-03-02 17:13:05 +0100
commitc3bc7d657e84824bb2cfdea39f604c33110eaa14 (patch)
treebe2b7c082c6edac78daf1b527fb09e2a22ef60cd
parent63fe6c65983a4cf2eba4995d03abd7e8a39c4a43 (diff)
downloadopenttd-c3bc7d657e84824bb2cfdea39f604c33110eaa14.tar.xz
Codechange: Remove ability for SDL to be dynamically loaded on Windows
-rw-r--r--projects/openttd_vs140.vcxproj2
-rw-r--r--projects/openttd_vs140.vcxproj.filters6
-rw-r--r--projects/openttd_vs141.vcxproj2
-rw-r--r--projects/openttd_vs141.vcxproj.filters6
-rw-r--r--projects/openttd_vs142.vcxproj2
-rw-r--r--projects/openttd_vs142.vcxproj.filters6
-rw-r--r--source.list4
-rw-r--r--src/crashlog.cpp11
-rw-r--r--src/sdl.cpp119
-rw-r--r--src/sdl.h71
-rw-r--r--src/sound/sdl_s.cpp22
-rw-r--r--src/video/sdl_v.cpp95
12 files changed, 66 insertions, 280 deletions
diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj
index b2dbfd293..c5137a61d 100644
--- a/projects/openttd_vs140.vcxproj
+++ b/projects/openttd_vs140.vcxproj
@@ -410,7 +410,6 @@
<ClCompile Include="..\src\road.cpp" />
<ClCompile Include="..\src\roadstop.cpp" />
<ClCompile Include="..\src\screenshot.cpp" />
- <ClCompile Include="..\src\sdl.cpp" />
<ClCompile Include="..\src\settings.cpp" />
<ClCompile Include="..\src\signal.cpp" />
<ClCompile Include="..\src\signs.cpp" />
@@ -623,7 +622,6 @@
<ClInclude Include="..\src\roadveh.h" />
<ClInclude Include="..\src\safeguards.h" />
<ClInclude Include="..\src\screenshot.h" />
- <ClInclude Include="..\src\sdl.h" />
<ClInclude Include="..\src\sound\sdl_s.h" />
<ClInclude Include="..\src\video\sdl_v.h" />
<ClInclude Include="..\src\settings_func.h" />
diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters
index e93c94f1f..751e54887 100644
--- a/projects/openttd_vs140.vcxproj.filters
+++ b/projects/openttd_vs140.vcxproj.filters
@@ -318,9 +318,6 @@
<ClCompile Include="..\src\screenshot.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\sdl.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\src\settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -957,9 +954,6 @@
<ClInclude Include="..\src\screenshot.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\sdl.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\src\sound\sdl_s.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj
index 92edccd7c..66974da28 100644
--- a/projects/openttd_vs141.vcxproj
+++ b/projects/openttd_vs141.vcxproj
@@ -410,7 +410,6 @@
<ClCompile Include="..\src\road.cpp" />
<ClCompile Include="..\src\roadstop.cpp" />
<ClCompile Include="..\src\screenshot.cpp" />
- <ClCompile Include="..\src\sdl.cpp" />
<ClCompile Include="..\src\settings.cpp" />
<ClCompile Include="..\src\signal.cpp" />
<ClCompile Include="..\src\signs.cpp" />
@@ -623,7 +622,6 @@
<ClInclude Include="..\src\roadveh.h" />
<ClInclude Include="..\src\safeguards.h" />
<ClInclude Include="..\src\screenshot.h" />
- <ClInclude Include="..\src\sdl.h" />
<ClInclude Include="..\src\sound\sdl_s.h" />
<ClInclude Include="..\src\video\sdl_v.h" />
<ClInclude Include="..\src\settings_func.h" />
diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters
index e93c94f1f..751e54887 100644
--- a/projects/openttd_vs141.vcxproj.filters
+++ b/projects/openttd_vs141.vcxproj.filters
@@ -318,9 +318,6 @@
<ClCompile Include="..\src\screenshot.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\sdl.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\src\settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -957,9 +954,6 @@
<ClInclude Include="..\src\screenshot.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\sdl.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\src\sound\sdl_s.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/projects/openttd_vs142.vcxproj b/projects/openttd_vs142.vcxproj
index 34f7c5f28..f0a75ff82 100644
--- a/projects/openttd_vs142.vcxproj
+++ b/projects/openttd_vs142.vcxproj
@@ -410,7 +410,6 @@
<ClCompile Include="..\src\road.cpp" />
<ClCompile Include="..\src\roadstop.cpp" />
<ClCompile Include="..\src\screenshot.cpp" />
- <ClCompile Include="..\src\sdl.cpp" />
<ClCompile Include="..\src\settings.cpp" />
<ClCompile Include="..\src\signal.cpp" />
<ClCompile Include="..\src\signs.cpp" />
@@ -623,7 +622,6 @@
<ClInclude Include="..\src\roadveh.h" />
<ClInclude Include="..\src\safeguards.h" />
<ClInclude Include="..\src\screenshot.h" />
- <ClInclude Include="..\src\sdl.h" />
<ClInclude Include="..\src\sound\sdl_s.h" />
<ClInclude Include="..\src\video\sdl_v.h" />
<ClInclude Include="..\src\settings_func.h" />
diff --git a/projects/openttd_vs142.vcxproj.filters b/projects/openttd_vs142.vcxproj.filters
index e93c94f1f..751e54887 100644
--- a/projects/openttd_vs142.vcxproj.filters
+++ b/projects/openttd_vs142.vcxproj.filters
@@ -318,9 +318,6 @@
<ClCompile Include="..\src\screenshot.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\sdl.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\src\settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -957,9 +954,6 @@
<ClInclude Include="..\src\screenshot.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\sdl.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\src\sound\sdl_s.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/source.list b/source.list
index 358b16a7c..ce6c4cf15 100644
--- a/source.list
+++ b/source.list
@@ -71,9 +71,6 @@ rev.cpp
road.cpp
roadstop.cpp
screenshot.cpp
-#if SDL
- sdl.cpp
-#end
settings.cpp
signal.cpp
signs.cpp
@@ -312,7 +309,6 @@ roadstop_base.h
roadveh.h
safeguards.h
screenshot.h
-sdl.h
sound/sdl_s.h
video/sdl_v.h
settings_func.h
diff --git a/src/crashlog.cpp b/src/crashlog.cpp
index 78d9b1465..5aa707eb5 100644
--- a/src/crashlog.cpp
+++ b/src/crashlog.cpp
@@ -62,7 +62,6 @@
#include <lzo/lzo1x.h>
#endif
#ifdef WITH_SDL
-# include "sdl.h"
# include <SDL.h>
#endif /* WITH_SDL */
#ifdef WITH_ZLIB
@@ -268,14 +267,8 @@ char *CrashLog::LogLibraries(char *buffer, const char *last) const
#endif /* WITH_PNG */
#ifdef WITH_SDL
-#ifdef DYNAMICALLY_LOADED_SDL
- if (SDL_CALL SDL_Linked_Version != NULL) {
-#else
- {
-#endif
- const SDL_version *v = SDL_CALL SDL_Linked_Version();
- buffer += seprintf(buffer, last, " SDL: %d.%d.%d\n", v->major, v->minor, v->patch);
- }
+ const SDL_version *v = SDL_Linked_Version();
+ buffer += seprintf(buffer, last, " SDL: %d.%d.%d\n", v->major, v->minor, v->patch);
#endif /* WITH_SDL */
#ifdef WITH_ZLIB
diff --git a/src/sdl.cpp b/src/sdl.cpp
deleted file mode 100644
index 79e9ed292..000000000
--- a/src/sdl.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/* $Id$ */
-
-/*
- * 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/>.
- */
-
-/** @file sdl.cpp Implementation of SDL support. */
-
-#include "stdafx.h"
-
-#ifdef WITH_SDL
-
-#include "sdl.h"
-#include <SDL.h>
-
-/** Number of users of the SDL library. */
-static int _sdl_usage;
-
-#ifdef DYNAMICALLY_LOADED_SDL
-
-#include "os/windows/win32.h"
-
-#define M(x) x "\0"
-static const char sdl_files[] =
- 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")
- M("SDL_LoadBMP_RW")
- M("SDL_RWFromFile")
- M("SDL_SetColorKey")
- M("SDL_WM_SetIcon")
- M("SDL_MapRGB")
- M("SDL_VideoModeOK")
- M("SDL_Linked_Version")
- M("")
-;
-#undef M
-
-SDLProcs sdl_proc;
-
-static const char *LoadSdlDLL()
-{
- if (sdl_proc.SDL_Init != NULL) {
- return NULL;
- }
- if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
- return "Unable to load sdl.dll";
- }
- return NULL;
-}
-
-#endif /* DYNAMICALLY_LOADED_SDL */
-
-#include "safeguards.h"
-
-/**
- * Open the SDL library.
- * @param x The subsystem to load.
- */
-const char *SdlOpen(uint32 x)
-{
-#ifdef DYNAMICALLY_LOADED_SDL
- {
- const char *s = LoadSdlDLL();
- if (s != NULL) return s;
- }
-#endif
- if (_sdl_usage++ == 0) {
- if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
- } else if (x != 0) {
- if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
- }
-
- return NULL;
-}
-
-/**
- * Close the SDL library.
- * @param x The subsystem to close.
- */
-void SdlClose(uint32 x)
-{
- if (x != 0) {
- SDL_CALL SDL_QuitSubSystem(x);
- }
- if (--_sdl_usage == 0) {
- SDL_CALL SDL_Quit();
- }
-}
-
-#endif
diff --git a/src/sdl.h b/src/sdl.h
deleted file mode 100644
index 9033899a5..000000000
--- a/src/sdl.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* $Id$ */
-
-/*
- * 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/>.
- */
-
-/** @file sdl.h SDL support. */
-
-#ifndef SDL_H
-#define SDL_H
-
-const char *SdlOpen(uint32 x);
-void SdlClose(uint32 x);
-
-#ifdef _WIN32
- #define DYNAMICALLY_LOADED_SDL
-#endif
-
-#ifdef DYNAMICALLY_LOADED_SDL
- #include <SDL.h>
-
- struct SDLProcs {
- int (SDLCALL *SDL_Init)(Uint32);
- int (SDLCALL *SDL_InitSubSystem)(Uint32);
- char *(SDLCALL *SDL_GetError)();
- void (SDLCALL *SDL_QuitSubSystem)(Uint32);
- void (SDLCALL *SDL_UpdateRect)(SDL_Surface *, Sint32, Sint32, Uint32, Uint32);
- void (SDLCALL *SDL_UpdateRects)(SDL_Surface *, int, SDL_Rect *);
- int (SDLCALL *SDL_SetColors)(SDL_Surface *, SDL_Color *, int, int);
- void (SDLCALL *SDL_WM_SetCaption)(const char *, const char *);
- int (SDLCALL *SDL_ShowCursor)(int);
- void (SDLCALL *SDL_FreeSurface)(SDL_Surface *);
- int (SDLCALL *SDL_PollEvent)(SDL_Event *);
- void (SDLCALL *SDL_WarpMouse)(Uint16, Uint16);
- uint32 (SDLCALL *SDL_GetTicks)();
- int (SDLCALL *SDL_OpenAudio)(SDL_AudioSpec *, SDL_AudioSpec*);
- void (SDLCALL *SDL_PauseAudio)(int);
- void (SDLCALL *SDL_CloseAudio)();
- int (SDLCALL *SDL_LockSurface)(SDL_Surface*);
- void (SDLCALL *SDL_UnlockSurface)(SDL_Surface*);
- SDLMod (SDLCALL *SDL_GetModState)();
- void (SDLCALL *SDL_Delay)(Uint32);
- void (SDLCALL *SDL_Quit)();
- SDL_Surface *(SDLCALL *SDL_SetVideoMode)(int, int, int, Uint32);
- int (SDLCALL *SDL_EnableKeyRepeat)(int, int);
- void (SDLCALL *SDL_EnableUNICODE)(int);
- void (SDLCALL *SDL_VideoDriverName)(char *, int);
- SDL_Rect **(SDLCALL *SDL_ListModes)(void *, int);
- Uint8 *(SDLCALL *SDL_GetKeyState)(int *);
- SDL_Surface *(SDLCALL *SDL_LoadBMP_RW)(SDL_RWops *, int);
- SDL_RWops *(SDLCALL *SDL_RWFromFile)(const char *, const char *);
- int (SDLCALL *SDL_SetColorKey)(SDL_Surface *, Uint32, Uint32);
- void (SDLCALL *SDL_WM_SetIcon)(SDL_Surface *, Uint8 *);
- Uint32 (SDLCALL *SDL_MapRGB)(SDL_PixelFormat *, Uint8, Uint8, Uint8);
- int (SDLCALL *SDL_VideoModeOK)(int, int, int, Uint32);
- SDL_version *(SDLCALL *SDL_Linked_Version)();
- int (SDLCALL *SDL_BlitSurface)(SDL_Surface *, SDL_Rect *, SDL_Surface *, SDL_Rect *);
- SDL_Surface *(SDLCALL *SDL_CreateRGBSurface)(Uint32, int, int, int, Uint32, Uint32, Uint32, Uint32);
- };
-
- extern SDLProcs sdl_proc;
-
- #define SDL_CALL sdl_proc.
-#else
- #define SDL_CALL
-#endif
-
-#endif /* SDL_H */
diff --git a/src/sound/sdl_s.cpp b/src/sound/sdl_s.cpp
index e3fb99eaa..b37016c24 100644
--- a/src/sound/sdl_s.cpp
+++ b/src/sound/sdl_s.cpp
@@ -14,7 +14,6 @@
#include "../stdafx.h"
#include "../mixer.h"
-#include "../sdl.h"
#include "sdl_s.h"
#include <SDL.h>
@@ -38,8 +37,14 @@ const char *SoundDriver_SDL::Start(const char * const *parm)
{
SDL_AudioSpec spec;
- const char *s = SdlOpen(SDL_INIT_AUDIO);
- if (s != NULL) return s;
+ /* Only initialise SDL if the video driver hasn't done it already */
+ int ret_code = 0;
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ ret_code = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
+ } else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
+ ret_code = SDL_InitSubSystem(SDL_INIT_AUDIO);
+ }
+ if (ret_code == -1) return SDL_GetError();
spec.freq = GetDriverParamInt(parm, "hz", 44100);
spec.format = AUDIO_S16SYS;
@@ -47,15 +52,18 @@ const char *SoundDriver_SDL::Start(const char * const *parm)
spec.samples = GetDriverParamInt(parm, "samples", 1024);
spec.callback = fill_sound_buffer;
MxInitialize(spec.freq);
- SDL_CALL SDL_OpenAudio(&spec, &spec);
- SDL_CALL SDL_PauseAudio(0);
+ SDL_OpenAudio(&spec, &spec);
+ SDL_PauseAudio(0);
return NULL;
}
void SoundDriver_SDL::Stop()
{
- SDL_CALL SDL_CloseAudio();
- SdlClose(SDL_INIT_AUDIO);
+ SDL_CloseAudio();
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ SDL_Quit(); // If there's nothing left, quit SDL
+ }
}
#endif /* WITH_SDL */
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index e96decb45..8493ae89f 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -14,7 +14,6 @@
#include "../stdafx.h"
#include "../openttd.h"
#include "../gfx_func.h"
-#include "../sdl.h"
#include "../rev.h"
#include "../blitter/factory.hpp"
#include "../network/network.h"
@@ -73,7 +72,7 @@ static void UpdatePalette(bool init = false)
pal[i].unused = 0;
}
- SDL_CALL SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty);
+ SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty);
if (_sdl_screen != _sdl_realscreen && init) {
/* When using a shadow surface, also set our palette on the real screen. This lets SDL
@@ -96,7 +95,7 @@ static void UpdatePalette(bool init = false)
* palette change and the blitting below, so we only set
* the real palette during initialisation.
*/
- SDL_CALL SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty);
+ SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty);
}
if (_sdl_screen != _sdl_realscreen && !init) {
@@ -110,8 +109,8 @@ static void UpdatePalette(bool init = false)
* best mapping of shadow palette colors to real palette
* colors from scratch.
*/
- SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL);
- SDL_CALL SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0);
+ SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL);
+ SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0);
}
}
@@ -157,16 +156,16 @@ static void DrawSurfaceToScreen()
_num_dirty_rects = 0;
if (n > MAX_DIRTY_RECTS) {
if (_sdl_screen != _sdl_realscreen) {
- SDL_CALL SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL);
+ SDL_BlitSurface(_sdl_screen, NULL, _sdl_realscreen, NULL);
}
- SDL_CALL SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0);
+ SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0);
} else {
if (_sdl_screen != _sdl_realscreen) {
for (int i = 0; i < n; i++) {
- SDL_CALL SDL_BlitSurface(_sdl_screen, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]);
+ SDL_BlitSurface(_sdl_screen, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]);
}
}
- SDL_CALL SDL_UpdateRects(_sdl_realscreen, n, _dirty_rects);
+ SDL_UpdateRects(_sdl_realscreen, n, _dirty_rects);
}
}
@@ -206,14 +205,14 @@ static const Dimension _default_resolutions[] = {
static void GetVideoModes()
{
- SDL_Rect **modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE | SDL_FULLSCREEN);
+ SDL_Rect **modes = SDL_ListModes(NULL, SDL_SWSURFACE | SDL_FULLSCREEN);
if (modes == NULL) usererror("sdl: no modes available");
- _all_modes = (SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE | (_fullscreen ? SDL_FULLSCREEN : 0)) == (void*)-1);
+ _all_modes = (SDL_ListModes(NULL, SDL_SWSURFACE | (_fullscreen ? SDL_FULLSCREEN : 0)) == (void*)-1);
if (modes == (void*)-1) {
int n = 0;
for (uint i = 0; i < lengthof(_default_resolutions); i++) {
- if (SDL_CALL SDL_VideoModeOK(_default_resolutions[i].width, _default_resolutions[i].height, 8, SDL_FULLSCREEN) != 0) {
+ if (SDL_VideoModeOK(_default_resolutions[i].width, _default_resolutions[i].height, 8, SDL_FULLSCREEN) != 0) {
_resolutions[n] = _default_resolutions[i];
if (++n == lengthof(_resolutions)) break;
}
@@ -264,13 +263,6 @@ static void GetAvailableVideoMode(uint *w, uint *h)
*h = _resolutions[best].height;
}
-#ifdef _WIN32
-/* Let's redefine the LoadBMP macro with because we are dynamically
- * loading SDL and need to 'SDL_CALL' all functions */
-#undef SDL_LoadBMP
-#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_CALL SDL_RWFromFile(file, "rb"), 1)
-#endif
-
bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
{
SDL_Surface *newscreen, *icon;
@@ -287,14 +279,14 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
char icon_path[MAX_PATH];
if (FioFindFullPath(icon_path, lastof(icon_path), BASESET_DIR, "openttd.32.bmp") != NULL) {
/* Give the application an icon */
- icon = SDL_CALL SDL_LoadBMP(icon_path);
+ icon = SDL_LoadBMP(icon_path);
if (icon != NULL) {
/* Get the colourkey, which will be magenta */
- uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255);
+ uint32 rgbmap = SDL_MapRGB(icon->format, 255, 0, 255);
- SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap);
- SDL_CALL SDL_WM_SetIcon(icon, NULL);
- SDL_CALL SDL_FreeSurface(icon);
+ SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap);
+ SDL_WM_SetIcon(icon, NULL);
+ SDL_FreeSurface(icon);
}
}
@@ -329,7 +321,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palette");
/* Free any previously allocated shadow surface */
- if (_sdl_screen != NULL && _sdl_screen != _sdl_realscreen) SDL_CALL SDL_FreeSurface(_sdl_screen);
+ if (_sdl_screen != NULL && _sdl_screen != _sdl_realscreen) SDL_FreeSurface(_sdl_screen);
if (_sdl_realscreen != NULL) {
if (_requested_hwpalette != want_hwpalette) {
@@ -342,8 +334,8 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
* subsystem to force creating a new window.
*/
DEBUG(driver, 0, "SDL: Restarting SDL video subsystem, to force hwpalette change");
- SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO);
- SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO);
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDL_InitSubSystem(SDL_INIT_VIDEO);
ClaimMousePointer();
SetupKeyboard();
}
@@ -355,7 +347,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
_requested_hwpalette = want_hwpalette;
/* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */
- newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
+ newscreen = SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
if (newscreen == NULL) {
DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on");
return false;
@@ -382,7 +374,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
* we won't create a second shadow surface in this case.
*/
DEBUG(driver, 1, "SDL: using shadow surface");
- newscreen = SDL_CALL SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bpp, 0, 0, 0, 0);
+ newscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bpp, 0, 0, 0, 0);
if (newscreen == NULL) {
DEBUG(driver, 0, "SDL: Couldn't allocate a shadow surface to draw on");
return false;
@@ -409,7 +401,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
InitPalette();
seprintf(caption, lastof(caption), "OpenTTD %s", _openttd_revision);
- SDL_CALL SDL_WM_SetCaption(caption, caption);
+ SDL_WM_SetCaption(caption, caption);
GameSizeChanged();
@@ -418,7 +410,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
bool VideoDriver_SDL::ClaimMousePointer()
{
- SDL_CALL SDL_ShowCursor(0);
+ SDL_ShowCursor(0);
return true;
}
@@ -531,18 +523,18 @@ int VideoDriver_SDL::PollEvent()
{
SDL_Event ev;
- if (!SDL_CALL SDL_PollEvent(&ev)) return -2;
+ if (!SDL_PollEvent(&ev)) return -2;
switch (ev.type) {
case SDL_MOUSEMOTION:
if (_cursor.UpdateCursorPosition(ev.motion.x, ev.motion.y, true)) {
- SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
+ SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y);
}
HandleMouseEvents();
break;
case SDL_MOUSEBUTTONDOWN:
- if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) {
+ if (_rightclick_emulate && SDL_GetModState() & KMOD_CTRL) {
ev.button.button = SDL_BUTTON_RIGHT;
}
@@ -626,15 +618,23 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
char buf[30];
_use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2);
- const char *s = SdlOpen(SDL_INIT_VIDEO);
- if (s != NULL) return s;
+ /* Just on the offchance the audio subsystem started before the video system,
+ * check whether any part of SDL has been initialised before getting here.
+ * Slightly duplicated with sound/sdl_s.cpp */
+ int ret_code = 0;
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ ret_code = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
+ } else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
+ ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO);
+ }
+ if (ret_code == -1) return SDL_GetError();
GetVideoModes();
if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) {
- return SDL_CALL SDL_GetError();
+ return SDL_GetError();
}
- SDL_CALL SDL_VideoDriverName(buf, sizeof buf);
+ SDL_VideoDriverName(buf, sizeof buf);
DEBUG(driver, 1, "SDL: using driver '%s'", buf);
MarkWholeScreenDirty();
@@ -647,18 +647,21 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
void VideoDriver_SDL::SetupKeyboard()
{
- SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- SDL_CALL SDL_EnableUNICODE(1);
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+ SDL_EnableUNICODE(1);
}
void VideoDriver_SDL::Stop()
{
- SdlClose(SDL_INIT_VIDEO);
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ SDL_Quit(); // If there's nothing left, quit SDL
+ }
}
void VideoDriver_SDL::MainLoop()
{
- uint32 cur_ticks = SDL_CALL SDL_GetTicks();
+ uint32 cur_ticks = SDL_GetTicks();
uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
uint32 mod;
@@ -700,11 +703,11 @@ void VideoDriver_SDL::MainLoop()
while (PollEvent() == -1) {}
if (_exit_game) break;
- mod = SDL_CALL SDL_GetModState();
+ mod = SDL_GetModState();
#if SDL_VERSION_ATLEAST(1, 3, 0)
- keys = SDL_CALL SDL_GetKeyboardState(&numkeys);
+ keys = SDL_GetKeyboardState(&numkeys);
#else
- keys = SDL_CALL SDL_GetKeyState(&numkeys);
+ keys = SDL_GetKeyState(&numkeys);
#endif
#if defined(_DEBUG)
if (_shift_pressed)
@@ -723,7 +726,7 @@ void VideoDriver_SDL::MainLoop()
_fast_forward = 0;
}
- cur_ticks = SDL_CALL SDL_GetTicks();
+ cur_ticks = SDL_GetTicks();
if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
_realtime_tick += cur_ticks - last_cur_ticks;
last_cur_ticks = cur_ticks;