# HG changeset patch # User rubidium # Date 2014-04-28 21:06:51 # Node ID 38079fc3bcd848874239b82a78a34062755e54aa # Parent 37fd42ff92b85b3e0d49fd775830e736828ae7f6 (svn r26538) -Codechange: remove double accounting of the drivers diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -482,7 +482,7 @@ void Blitter_32bppAnim::PaletteAnimate(c } /* 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 --- 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 --- 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 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -140,14 +140,14 @@ char *CrashLog::LogConfiguration(char *b 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 --- 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 * @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( 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( 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 --- 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 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -331,7 +331,7 @@ void GenerateWorld(GenWorldMode mode, ui _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 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -88,7 +88,7 @@ void GfxScroll(int left, int top, int wi 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, 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 AnimCu 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 --- 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 --- a/src/music/extmidi.cpp +++ b/src/music/extmidi.cpp @@ -37,8 +37,8 @@ static FMusicDriver_ExtMidi iFMusicDrive 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 --- 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(*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 --- 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 --- 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 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -775,7 +775,7 @@ void ScanNewGRFFiles(NewGRFScanCallback /* 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 --- 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_newg CheckForMissingGlyphs(); /* Play main theme */ - if (_music_driver->IsSongPlaying()) ResetMusic(); + if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic(); } void MakeNewgameSettingsLive() @@ -436,7 +436,7 @@ struct AfterNewGRFScan : NewGRFScanCallb *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 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -523,7 +523,7 @@ static LONG WINAPI ExceptionHandler(EXCE /* 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 --- 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 --- 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(*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 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -597,16 +597,16 @@ void CocoaDialog(const char *title, cons _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 --- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -287,7 +287,7 @@ static bool QZ_KeyEvent(unsigned short k 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 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -411,7 +411,7 @@ bool VideoDriver_SDL::CreateMainSurface( 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 --- 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(*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 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1002,7 +1002,7 @@ static LRESULT CALLBACK WndProcGdi(HWND if (active && minimized) { /* Restore the game window */ ShowWindow(hwnd, SW_RESTORE); - static_cast(_video_driver)->MakeWindow(true); + static_cast(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 --- 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 /* 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(widget_index); return true; @@ -483,7 +483,7 @@ bool Window::SetFocusedWidget(int widget */ 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(); } /**