diff --git a/backends/base-backend.cpp b/backends/base-backend.cpp index 9164b8d7216..d232a193a8f 100644 --- a/backends/base-backend.cpp +++ b/backends/base-backend.cpp @@ -40,12 +40,6 @@ void BaseBackend::displayMessageOnOSD(const char *msg) { } void BaseBackend::initBackend() { - // Init Event manager -#ifndef DISABLE_DEFAULT_EVENT_MANAGER - if (!_eventManager) - _eventManager = new DefaultEventManager(getDefaultEventSource()); -#endif - // Init audio CD manager #ifndef DISABLE_DEFAULT_AUDIOCD_MANAGER if (!_audiocdManager) @@ -61,3 +55,13 @@ void BaseBackend::fillScreen(uint32 col) { screen->fillRect(Common::Rect(screen->w, screen->h), col); unlockScreen(); } + +void EventsBaseBackend::initBackend() { + // Init Event manager +#ifndef DISABLE_DEFAULT_EVENT_MANAGER + if (!_eventManager) + _eventManager = new DefaultEventManager(this); +#endif + + BaseBackend::initBackend(); +} diff --git a/backends/base-backend.h b/backends/base-backend.h index 6d074a4c3e4..657a24a0997 100644 --- a/backends/base-backend.h +++ b/backends/base-backend.h @@ -27,8 +27,6 @@ #include "common/events.h" class BaseBackend : public OSystem { -protected: - virtual Common::EventSource *getDefaultEventSource() = 0; public: virtual void initBackend(); @@ -37,10 +35,9 @@ public: virtual void fillScreen(uint32 col); }; -class EventsBaseBackend : public BaseBackend, Common::EventSource { -protected: - virtual Common::EventSource *getDefaultEventSource() { return this; } +class EventsBaseBackend : virtual public BaseBackend, Common::EventSource { public: + virtual void initBackend(); }; diff --git a/backends/platform/3ds/config.cpp b/backends/platform/3ds/config.cpp index a160ac99509..0fe7f700aa9 100644 --- a/backends/platform/3ds/config.cpp +++ b/backends/platform/3ds/config.cpp @@ -74,7 +74,7 @@ void loadConfig() { gspLcdExit(); } - OSystem_3DS *osys = (OSystem_3DS *)g_system; + OSystem_3DS *osys = dynamic_cast(g_system); osys->updateConfig(); } diff --git a/backends/platform/3ds/osystem-audio.cpp b/backends/platform/3ds/osystem-audio.cpp index 6f16a58ad12..b9a4cc7a3ef 100644 --- a/backends/platform/3ds/osystem-audio.cpp +++ b/backends/platform/3ds/osystem-audio.cpp @@ -29,7 +29,7 @@ static bool hasAudio = false; static void audioThreadFunc(void *arg) { Audio::MixerImpl *mixer = (Audio::MixerImpl *)arg; - OSystem_3DS *osys = (OSystem_3DS *)g_system; + OSystem_3DS *osys = dynamic_cast(g_system); const int channel = 0; int bufferIndex = 0; diff --git a/backends/platform/3ds/osystem-events.cpp b/backends/platform/3ds/osystem-events.cpp index 7f4928d691e..c26306a2edd 100644 --- a/backends/platform/3ds/osystem-events.cpp +++ b/backends/platform/3ds/osystem-events.cpp @@ -91,7 +91,7 @@ static void doJoyEvent(Common::Queue *queue, u32 keysPressed, u32 } static void eventThreadFunc(void *arg) { - OSystem_3DS *osys = (OSystem_3DS *)g_system; + OSystem_3DS *osys = dynamic_cast(g_system); Common::Queue *eventQueue = (Common::Queue *)arg; uint32 touchStartTime = osys->getMillis(); @@ -206,7 +206,7 @@ static void eventThreadFunc(void *arg) { } static void aptHookFunc(APT_HookType hookType, void *param) { - OSystem_3DS *osys = (OSystem_3DS *)g_system; + OSystem_3DS *osys = dynamic_cast(g_system); switch (hookType) { case APTHOOK_ONSUSPEND: diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index 89124aed50e..050efd804e1 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -81,9 +81,6 @@ private: Common::String getSystemProperty(const char *name) const; -protected: - virtual Common::EventSource *getDefaultEventSource() { return this; } - public: OSystem_Android(int audio_sample_rate, int audio_buffer_size); virtual ~OSystem_Android(); diff --git a/backends/platform/ds/arm9/source/wordcompletion.cpp b/backends/platform/ds/arm9/source/wordcompletion.cpp index 2257c49005e..eb0d5d79146 100644 --- a/backends/platform/ds/arm9/source/wordcompletion.cpp +++ b/backends/platform/ds/arm9/source/wordcompletion.cpp @@ -104,7 +104,7 @@ bool findWordCompletions(const char *input) { if (wordBufferPtrPos == 0) return false; - OSystem_DS *system = (OSystem_DS *) g_system; + OSystem_DS *system = dynamic_cast(g_system); system->clearAutoComplete(); int start = 0; diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp index 23278a30df7..90bb5d69333 100644 --- a/backends/platform/ios7/ios7_osys_main.cpp +++ b/backends/platform/ios7/ios7_osys_main.cpp @@ -353,7 +353,7 @@ void OSystem_iOS7::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) } bool iOS7_touchpadModeEnabled() { - OSystem_iOS7 *sys = (OSystem_iOS7 *) g_system; + OSystem_iOS7 *sys = dynamic_cast(g_system); return sys && sys->touchpadModeEnabled(); } diff --git a/backends/platform/n64/osys_n64_utilities.cpp b/backends/platform/n64/osys_n64_utilities.cpp index b3b6d50667b..defe60a0a5b 100644 --- a/backends/platform/n64/osys_n64_utilities.cpp +++ b/backends/platform/n64/osys_n64_utilities.cpp @@ -24,7 +24,7 @@ #include "backends/timer/default/default-timer.h" void checkTimers(void) { - OSystem_N64 *osys = (OSystem_N64 *)g_system; + OSystem_N64 *osys = dynamic_cast(g_system); uint32 curTime = osys->getMillis(); @@ -46,7 +46,7 @@ void disableAudioPlayback(void) { void enableAudioPlayback(void) { static bool _firstRun = true; - OSystem_N64 *osys = (OSystem_N64 *)g_system; + OSystem_N64 *osys = dynamic_cast(g_system); Audio::MixerImpl *localmixer = (Audio::MixerImpl *)osys->getMixer(); uint32 sampleBufferSize = 3072; @@ -83,7 +83,7 @@ void vblCallback(void) { sndCallback(); } - ((OSystem_N64 *)g_system)->readControllerAnalogInput(); + dynamic_cast(g_system)->readControllerAnalogInput(); } void sndCallback() { @@ -95,7 +95,7 @@ void sndCallback() { void refillAudioBuffers(void) { if (!_audioEnabled) return; - OSystem_N64 *osys = (OSystem_N64 *)g_system; + OSystem_N64 *osys = dynamic_cast(g_system); byte *sndBuf; Audio::MixerImpl *localmixer = (Audio::MixerImpl *)osys->getMixer(); diff --git a/backends/platform/null/null.cpp b/backends/platform/null/null.cpp index 0840b457f6f..cd6677c60d2 100644 --- a/backends/platform/null/null.cpp +++ b/backends/platform/null/null.cpp @@ -72,7 +72,6 @@ public: virtual void initBackend(); - virtual Common::EventSource *getDefaultEventSource() { return this; } virtual bool pollEvent(Common::Event &event); virtual uint32 getMillis(bool skipRecord = false); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 4722b1fd1fa..0acb9beb9c8 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -124,8 +124,6 @@ protected: */ SdlWindow *_window; - virtual Common::EventSource *getDefaultEventSource() override { return _eventSource; } - /** * Initialze the SDL library. */ diff --git a/common/system.h b/common/system.h index 32838c001d0..a808e85278f 100644 --- a/common/system.h +++ b/common/system.h @@ -149,7 +149,7 @@ protected: /** * No default value is provided for _eventManager by OSystem. - * However, BaseBackend::initBackend() does set a default value + * However, EventsBaseBackend::initBackend() does set a default value * if none has been set before. * * @note _eventManager is deleted by the OSystem destructor.