summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blitter/32bpp_anim.cpp2
-rw-r--r--src/bootstrap_gui.cpp2
-rw-r--r--src/console_gui.cpp4
-rw-r--r--src/crashlog.cpp12
-rw-r--r--src/driver.cpp27
-rw-r--r--src/driver.h8
-rw-r--r--src/genworld.cpp2
-rw-r--r--src/gfx.cpp12
-rw-r--r--src/gfxinit.cpp4
-rw-r--r--src/music/extmidi.cpp4
-rw-r--r--src/music/music_driver.hpp8
-rw-r--r--src/music_gui.cpp8
-rw-r--r--src/network/network_chat_gui.cpp4
-rw-r--r--src/newgrf_config.cpp2
-rw-r--r--src/openttd.cpp35
-rw-r--r--src/os/windows/crashlog_win.cpp2
-rw-r--r--src/osk_gui.cpp2
-rw-r--r--src/sound/sound_driver.hpp8
-rw-r--r--src/video/cocoa/cocoa_v.mm6
-rw-r--r--src/video/cocoa/event.mm2
-rw-r--r--src/video/sdl_v.cpp2
-rw-r--r--src/video/video_driver.hpp8
-rw-r--r--src/video/win32_v.cpp2
-rw-r--r--src/window.cpp6
24 files changed, 97 insertions, 75 deletions
diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp
index 71c3e0a34..6127ff3a0 100644
--- a/src/blitter/32bpp_anim.cpp
+++ b/src/blitter/32bpp_anim.cpp
@@ -482,7 +482,7 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
}
/* Make sure the backend redraws the whole screen */
- _video_driver->MakeDirty(0, 0, _screen.width, _screen.height);
+ VideoDriver::GetInstance()->MakeDirty(0, 0, _screen.width, _screen.height);
}
Blitter::PaletteAnimation Blitter_32bppAnim::UsePaletteAnimation()
diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp
index 98c3175d6..7abc38563 100644
--- a/src/bootstrap_gui.cpp
+++ b/src/bootstrap_gui.cpp
@@ -246,7 +246,7 @@ bool HandleBootstrap()
new BootstrapAskForDownloadWindow();
/* Process the user events. */
- _video_driver->MainLoop();
+ VideoDriver::GetInstance()->MainLoop();
/* _exit_game is used to get out of the video driver's main loop.
* In case GM_BOOTSTRAP is still set we did not exit it via the
diff --git a/src/console_gui.cpp b/src/console_gui.cpp
index 4e454f476..ed46938cd 100644
--- a/src/console_gui.cpp
+++ b/src/console_gui.cpp
@@ -187,7 +187,7 @@ struct IConsoleWindow : Window
~IConsoleWindow()
{
_iconsole_mode = ICONSOLE_CLOSED;
- _video_driver->EditBoxLostFocus();
+ VideoDriver::GetInstance()->EditBoxLostFocus();
}
/**
@@ -376,7 +376,7 @@ struct IConsoleWindow : Window
virtual void OnFocusLost()
{
- _video_driver->EditBoxLostFocus();
+ VideoDriver::GetInstance()->EditBoxLostFocus();
}
};
diff --git a/src/crashlog.cpp b/src/crashlog.cpp
index 9159836c8..e8290a7c3 100644
--- a/src/crashlog.cpp
+++ b/src/crashlog.cpp
@@ -140,14 +140,14 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
_current_language == NULL ? "none" : _current_language->file,
- _music_driver == NULL ? "none" : _music_driver->GetName(),
+ MusicDriver::GetInstance() == NULL ? "none" : MusicDriver::GetInstance()->GetName(),
BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
_networking ? (_network_server ? "server" : "client") : "no",
- _sound_driver == NULL ? "none" : _sound_driver->GetName(),
+ SoundDriver::GetInstance() == NULL ? "none" : SoundDriver::GetInstance()->GetName(),
BaseSounds::GetUsedSet() == NULL ? "none" : BaseSounds::GetUsedSet()->name,
BaseSounds::GetUsedSet() == NULL ? UINT32_MAX : BaseSounds::GetUsedSet()->version,
- _video_driver == NULL ? "none" : _video_driver->GetName()
+ VideoDriver::GetInstance() == NULL ? "none" : VideoDriver::GetInstance()->GetName()
);
buffer += seprintf(buffer, last,
@@ -484,7 +484,7 @@ bool CrashLog::MakeCrashLog() const
*/
/* static */ void CrashLog::AfterCrashLogCleanup()
{
- if (_music_driver != NULL) _music_driver->Stop();
- if (_sound_driver != NULL) _sound_driver->Stop();
- if (_video_driver != NULL) _video_driver->Stop();
+ if (MusicDriver::GetInstance() != NULL) MusicDriver::GetInstance()->Stop();
+ if (SoundDriver::GetInstance() != NULL) SoundDriver::GetInstance()->Stop();
+ if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
}
diff --git a/src/driver.cpp b/src/driver.cpp
index 2e90c2df1..70f695122 100644
--- a/src/driver.cpp
+++ b/src/driver.cpp
@@ -18,17 +18,14 @@
#include "safeguards.h"
-VideoDriver *_video_driver; ///< The currently active video driver.
char *_ini_videodriver; ///< The video driver a stored in the configuration file.
int _num_resolutions; ///< The number of resolutions.
Dimension _resolutions[32]; ///< List of resolutions.
Dimension _cur_resolution; ///< The current resolution.
bool _rightclick_emulate; ///< Whether right clicking is emulated.
-SoundDriver *_sound_driver; ///< The currently active sound driver.
char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.
-MusicDriver *_music_driver; ///< The currently active music driver.
char *_ini_musicdriver; ///< The music driver a stored in the configuration file.
char *_ini_blitter; ///< The blitter as stored in the configuration file.
@@ -88,9 +85,25 @@ int GetDriverParamInt(const char * const *parm, const char *name, int def)
* @param type the type of driver to select
* @post Sets the driver so GetCurrentDriver() returns it too.
*/
-Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
+void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
{
- if (GetDrivers().size() == 0) return NULL;
+ if (!DriverFactoryBase::SelectDriverImpl(name, type)) {
+ StrEmpty(name) ?
+ usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) :
+ usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name);
+ }
+}
+
+/**
+ * Find the requested driver and return its class.
+ * @param name the driver to select.
+ * @param type the type of driver to select
+ * @post Sets the driver so GetCurrentDriver() returns it too.
+ * @return True upon success, otherwise false.
+ */
+bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
+{
+ if (GetDrivers().size() == 0) return false;
if (StrEmpty(name)) {
/* Probe for this driver, but do not fall back to dedicated/null! */
@@ -109,7 +122,7 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
delete *GetActiveDriver(type);
*GetActiveDriver(type) = newd;
- return newd;
+ return true;
}
DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
@@ -160,7 +173,7 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
delete *GetActiveDriver(type);
*GetActiveDriver(type) = newd;
- return newd;
+ return true;
}
usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
}
diff --git a/src/driver.h b/src/driver.h
index a466d67d0..12ca4474d 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -59,6 +59,10 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type)
/** Base for all driver factories. */
class DriverFactoryBase {
private:
+ friend class MusicDriver;
+ friend class SoundDriver;
+ friend class VideoDriver;
+
Driver::Type type; ///< The type of driver.
int priority; ///< The priority of this factory.
const char *name; ///< The name of the drivers of this factory.
@@ -97,6 +101,8 @@ private:
return driver_type_name[type];
}
+ static bool SelectDriverImpl(const char *name, Driver::Type type);
+
protected:
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
@@ -114,7 +120,7 @@ public:
}
}
- static Driver *SelectDriver(const char *name, Driver::Type type);
+ static void SelectDriver(const char *name, Driver::Type type);
static char *GetDriversInfo(char *p, const char *last);
/**
diff --git a/src/genworld.cpp b/src/genworld.cpp
index 474f51333..88e1b84a5 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -331,7 +331,7 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
_gw.thread = NULL;
}
- if (!_video_driver->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
+ if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
_gw.threaded = false;
_modal_progress_work_mutex->EndCritical();
diff --git a/src/gfx.cpp b/src/gfx.cpp
index a288ee0f4..20e27519a 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -88,7 +88,7 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
/* This part of the screen is now dirty. */
- _video_driver->MakeDirty(left, top, width, height);
+ VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
}
@@ -1186,7 +1186,7 @@ void UndrawMouseCursor()
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
_cursor.visible = false;
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
- _video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
+ VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
}
}
@@ -1246,7 +1246,7 @@ void DrawMouseCursor()
_cur_dpi = &_screen;
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x + _cursor.short_vehicle_offset, _cursor.pos.y);
- _video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
+ VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
_cursor.visible = true;
_cursor.dirty = false;
@@ -1270,7 +1270,7 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
DrawOverlappedWindowForAll(left, top, right, bottom);
- _video_driver->MakeDirty(left, top, right - left, bottom - top);
+ VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
}
/**
@@ -1579,12 +1579,12 @@ void SetAnimatedMouseCursor(const AnimCursor *table)
bool ChangeResInGame(int width, int height)
{
- return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height);
+ return (_screen.width == width && _screen.height == height) || VideoDriver::GetInstance()->ChangeResolution(width, height);
}
bool ToggleFullScreen(bool fs)
{
- bool result = _video_driver->ToggleFullscreen(fs);
+ bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
if (_fullscreen != fs && _num_resolutions == 0) {
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
}
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index ac116bf4a..72ded8f76 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -289,9 +289,9 @@ static bool SwitchNewGRFBlitter()
break;
}
- if (!_video_driver->AfterBlitterChange()) {
+ if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
/* Failed to switch blitter, let's hope we can return to the old one. */
- if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !_video_driver->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
+ if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !VideoDriver::GetInstance()->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
}
return true;
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp
index 919f689e0..7b9e649c0 100644
--- a/src/music/extmidi.cpp
+++ b/src/music/extmidi.cpp
@@ -37,8 +37,8 @@ static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
{
- if (strcmp(_video_driver->GetName(), "allegro") == 0 ||
- strcmp(_sound_driver->GetName(), "allegro") == 0) {
+ if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
+ strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
return "the extmidi driver does not work when Allegro is loaded.";
}
diff --git a/src/music/music_driver.hpp b/src/music/music_driver.hpp
index 03c70d569..be09d3ea2 100644
--- a/src/music/music_driver.hpp
+++ b/src/music/music_driver.hpp
@@ -39,9 +39,15 @@ public:
* @param vol The new volume.
*/
virtual void SetVolume(byte vol) = 0;
+
+ /**
+ * Get the currently active instance of the music driver.
+ */
+ static MusicDriver *GetInstance() {
+ return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC));
+ }
};
-extern MusicDriver *_music_driver;
extern char *_ini_musicdriver;
#endif /* MUSIC_MUSIC_DRIVER_HPP */
diff --git a/src/music_gui.cpp b/src/music_gui.cpp
index c9eb21aa3..1a6a4ca20 100644
--- a/src/music_gui.cpp
+++ b/src/music_gui.cpp
@@ -176,7 +176,7 @@ static void SkipToNextSong()
static void MusicVolumeChanged(byte new_vol)
{
- _music_driver->SetVolume(new_vol);
+ MusicDriver::GetInstance()->SetVolume(new_vol);
}
static void DoPlaySong()
@@ -185,13 +185,13 @@ static void DoPlaySong()
if (FioFindFullPath(filename, lastof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) {
FioFindFullPath(filename, lastof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename);
}
- _music_driver->PlaySong(filename);
+ MusicDriver::GetInstance()->PlaySong(filename);
SetWindowDirty(WC_MUSIC_WINDOW, 0);
}
static void DoStopMusic()
{
- _music_driver->StopSong();
+ MusicDriver::GetInstance()->StopSong();
SetWindowDirty(WC_MUSIC_WINDOW, 0);
}
@@ -273,7 +273,7 @@ void MusicLoop()
if (!_song_is_active) return;
- if (!_music_driver->IsSongPlaying()) {
+ if (!MusicDriver::GetInstance()->IsSongPlaying()) {
if (_game_mode != GM_MENU) {
StopMusic();
SkipToNextSong();
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 07224a9f1..fdfc4acff 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -169,7 +169,7 @@ void NetworkUndrawChatMessage()
/* Put our 'shot' back to the screen */
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
/* And make sure it is updated next time */
- _video_driver->MakeDirty(x, y, width, height);
+ VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
_chatmessage_dirty = true;
}
@@ -256,7 +256,7 @@ void NetworkDrawChatMessage()
}
/* Make sure the data is updated next flush */
- _video_driver->MakeDirty(x, y, width, height);
+ VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
_chatmessage_visible = true;
_chatmessage_dirty = false;
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index eb6322e32..2b268183f 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -775,7 +775,7 @@ void ScanNewGRFFiles(NewGRFScanCallback *callback)
/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
MarkWholeScreenDirty();
- if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
+ if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
_modal_progress_work_mutex->EndCritical();
_modal_progress_paint_mutex->EndCritical();
DoScanNewGRFFiles(callback);
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 2d5b06e73..f289545ec 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -97,7 +97,7 @@ void CDECL usererror(const char *s, ...)
va_end(va);
ShowOSErrorBox(buf, false);
- if (_video_driver != NULL) _video_driver->Stop();
+ if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
exit(1);
}
@@ -343,7 +343,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
CheckForMissingGlyphs();
/* Play main theme */
- if (_music_driver->IsSongPlaying()) ResetMusic();
+ if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
}
void MakeNewgameSettingsLive()
@@ -436,7 +436,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
*save_config_ptr = save_config;
/* restore saved music volume */
- _music_driver->SetVolume(_settings_client.music.music_vol);
+ MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
@@ -775,12 +775,7 @@ int openttd_main(int argc, char *argv[])
free(blitter);
if (videodriver == NULL && _ini_videodriver != NULL) videodriver = stredup(_ini_videodriver);
- _video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
- if (_video_driver == NULL) {
- StrEmpty(videodriver) ?
- usererror("Failed to autoprobe video driver") :
- usererror("Failed to select requested video driver '%s'", videodriver);
- }
+ DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
free(videodriver);
InitializeSpriteSorter();
@@ -811,7 +806,7 @@ int openttd_main(int argc, char *argv[])
goto exit_bootstrap;
}
- _video_driver->ClaimMousePointer();
+ VideoDriver::GetInstance()->ClaimMousePointer();
/* initialize screenshot formats */
InitializeScreenshotFormats();
@@ -843,21 +838,11 @@ int openttd_main(int argc, char *argv[])
free(music_set);
if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = stredup(_ini_sounddriver);
- _sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
- if (_sound_driver == NULL) {
- StrEmpty(sounddriver) ?
- usererror("Failed to autoprobe sound driver") :
- usererror("Failed to select requested sound driver '%s'", sounddriver);
- }
+ DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
free(sounddriver);
if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = stredup(_ini_musicdriver);
- _music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
- if (_music_driver == NULL) {
- StrEmpty(musicdriver) ?
- usererror("Failed to autoprobe music driver") :
- usererror("Failed to select requested music driver '%s'", musicdriver);
- }
+ DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
free(musicdriver);
/* Take our initial lock on whatever we might want to do! */
@@ -875,7 +860,7 @@ int openttd_main(int argc, char *argv[])
ScanNewGRFFiles(scanner);
scanner = NULL;
- _video_driver->MainLoop();
+ VideoDriver::GetInstance()->MainLoop();
WaitTillSaved();
@@ -943,7 +928,7 @@ static void MakeNewGameDone()
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
/* In a dedicated server, the server does not play */
- if (!_video_driver->HasGUI()) {
+ if (!VideoDriver::GetInstance()->HasGUI()) {
SetLocalCompany(COMPANY_SPECTATOR);
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
IConsoleCmdExec("exec scripts/game_start.scr 0");
@@ -1509,6 +1494,6 @@ void GameLoop()
InputLoop();
- _sound_driver->MainLoop();
+ SoundDriver::GetInstance()->MainLoop();
MusicLoop();
}
diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp
index 39f100601..6e28cdba6 100644
--- a/src/os/windows/crashlog_win.cpp
+++ b/src/os/windows/crashlog_win.cpp
@@ -523,7 +523,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
/* Close any possible log files */
CloseConsoleLogIfActive();
- if ((_video_driver == NULL || _video_driver->HasGUI()) && _safe_esp != NULL) {
+ if ((VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != NULL) {
#ifdef _M_AMD64
ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow;
ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 52ef5ebb9..974e465f4 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -208,7 +208,7 @@ struct OskWindow : public Window {
virtual void OnFocusLost()
{
- _video_driver->EditBoxLostFocus();
+ VideoDriver::GetInstance()->EditBoxLostFocus();
delete this;
}
};
diff --git a/src/sound/sound_driver.hpp b/src/sound/sound_driver.hpp
index 2b9cf145d..0df69b8b4 100644
--- a/src/sound/sound_driver.hpp
+++ b/src/sound/sound_driver.hpp
@@ -19,9 +19,15 @@ class SoundDriver : public Driver {
public:
/** Called once every tick */
virtual void MainLoop() {}
+
+ /**
+ * Get the currently active instance of the sound driver.
+ */
+ static SoundDriver *GetInstance() {
+ return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND));
+ }
};
-extern SoundDriver *_sound_driver;
extern char *_ini_sounddriver;
#endif /* SOUND_SOUND_DRIVER_HPP */
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index d87fa10b2..5665abb5b 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -597,16 +597,16 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
_cocoa_video_dialog = true;
bool wasstarted = _cocoa_video_started;
- if (_video_driver == NULL) {
+ if (VideoDriver::GetInstance() == NULL) {
setupApplication(); // Setup application before showing dialog
- } else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {
+ } else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(NULL) != NULL) {
fprintf(stderr, "%s: %s\n", title, message);
return;
}
NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil);
- if (!wasstarted && _video_driver != NULL) _video_driver->Stop();
+ if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
_cocoa_video_dialog = false;
}
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index b4f171a98..78785f8d0 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -287,7 +287,7 @@ static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow
case QZ_RETURN:
case QZ_f:
if (down && (_current_mods & NSCommandKeyMask)) {
- _video_driver->ToggleFullscreen(!_fullscreen);
+ VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
}
break;
}
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index d34f5e6db..d59ab20d4 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -411,7 +411,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
break;
case Blitter::PALETTE_ANIMATION_BLITTER:
- if (_video_driver != NULL) blitter->PaletteAnimate(_local_palette);
+ if (VideoDriver::GetInstance() != NULL) blitter->PaletteAnimate(_local_palette);
break;
default:
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index 190bfcc10..916044d35 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -78,9 +78,15 @@ public:
* An edit box lost the input focus. Abort character compositing if necessary.
*/
virtual void EditBoxLostFocus() {}
+
+ /**
+ * Get the currently active instance of the video driver.
+ */
+ static VideoDriver *GetInstance() {
+ return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
+ }
};
-extern VideoDriver *_video_driver;
extern char *_ini_videodriver;
extern int _num_resolutions;
extern Dimension _resolutions[32];
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 3774f3c0f..a7487bfb5 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -1002,7 +1002,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
if (active && minimized) {
/* Restore the game window */
ShowWindow(hwnd, SW_RESTORE);
- static_cast<VideoDriver_Win32 *>(_video_driver)->MakeWindow(true);
+ static_cast<VideoDriver_Win32 *>(VideoDriver::GetInstance())->MakeWindow(true);
} else if (!active && !minimized) {
/* Minimise the window and restore desktop */
ShowWindow(hwnd, SW_MINIMIZE);
diff --git a/src/window.cpp b/src/window.cpp
index 3ea69ca3c..32b7ce4fe 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -448,7 +448,7 @@ bool EditBoxInGlobalFocus()
void Window::UnfocusFocusedWidget()
{
if (this->nested_focus != NULL) {
- if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
+ if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
this->nested_focus->SetDirty(this);
@@ -472,7 +472,7 @@ bool Window::SetFocusedWidget(int widget_index)
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
this->nested_focus->SetDirty(this);
- if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
+ if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
}
this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
return true;
@@ -483,7 +483,7 @@ bool Window::SetFocusedWidget(int widget_index)
*/
void Window::OnFocusLost()
{
- if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
+ if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
}
/**