diff options
author | Max Horn | 2011-06-06 15:51:46 +0200 |
---|---|---|
committer | Max Horn | 2011-06-06 16:13:57 +0200 |
commit | c81e94b25214d258e0789f51b0ad0236ba1bf9c0 (patch) | |
tree | 41e1a0a9e9c121e58f1379db19d0faf743d80fcd | |
parent | 848079b66de84cec7559bfbd009d664098ea42ac (diff) | |
download | scummvm-rg350-c81e94b25214d258e0789f51b0ad0236ba1bf9c0.tar.gz scummvm-rg350-c81e94b25214d258e0789f51b0ad0236ba1bf9c0.tar.bz2 scummvm-rg350-c81e94b25214d258e0789f51b0ad0236ba1bf9c0.zip |
BACKENDS: Unify EventManager setup
-rw-r--r-- | backends/base-backend.cpp | 20 | ||||
-rw-r--r-- | backends/base-backend.h | 3 | ||||
-rw-r--r-- | backends/modular-backend.cpp | 8 | ||||
-rw-r--r-- | backends/modular-backend.h | 2 | ||||
-rw-r--r-- | backends/platform/ps2/systemps2.cpp | 6 | ||||
-rw-r--r-- | backends/platform/ps2/systemps2.h | 1 | ||||
-rw-r--r-- | common/system.cpp | 13 | ||||
-rw-r--r-- | common/system.h | 19 |
8 files changed, 43 insertions, 29 deletions
diff --git a/backends/base-backend.cpp b/backends/base-backend.cpp index ecd22d58bc..156871eec5 100644 --- a/backends/base-backend.cpp +++ b/backends/base-backend.cpp @@ -24,7 +24,11 @@ */ #include "backends/base-backend.h" + +#ifndef DISABLE_DEFAULT_EVENT_MANAGER #include "backends/events/default/default-events.h" +#endif + #include "gui/message.h" void BaseBackend::displayMessageOnOSD(const char *msg) { @@ -33,16 +37,12 @@ void BaseBackend::displayMessageOnOSD(const char *msg) { dialog.runModal(); } - -static Common::EventManager *s_eventManager = 0; - -Common::EventManager *BaseBackend::getEventManager() { - // FIXME/TODO: Eventually this method should be turned into an abstract one, - // to force backends to implement this conciously (even if they - // end up returning the default event manager anyway). - if (!s_eventManager) - s_eventManager = new DefaultEventManager(this); - return s_eventManager; +void BaseBackend::initBackend() { + // Init Event manager +#ifndef DISABLE_DEFAULT_EVENT_MANAGER + if (!_eventManager) + _eventManager = new DefaultEventManager(this); +#endif } void BaseBackend::fillScreen(uint32 col) { diff --git a/backends/base-backend.h b/backends/base-backend.h index c71b481aa2..6b19b7a9cb 100644 --- a/backends/base-backend.h +++ b/backends/base-backend.h @@ -28,7 +28,8 @@ class BaseBackend : public OSystem, Common::EventSource { public: - virtual Common::EventManager *getEventManager(); + virtual void initBackend(); + virtual void displayMessageOnOSD(const char *msg); virtual void fillScreen(uint32 col); diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index d56c9479b9..bbf6a6c1ed 100644 --- a/backends/modular-backend.cpp +++ b/backends/modular-backend.cpp @@ -36,7 +36,6 @@ ModularBackend::ModularBackend() : _fsFactory(0), - _eventManager(0), _savefileManager(0), _timerManager(0), _mutexManager(0), @@ -50,8 +49,6 @@ ModularBackend::~ModularBackend() { _fsFactory = 0; delete _graphicsManager; _graphicsManager = 0; - delete _eventManager; - _eventManager = 0; delete _mixer; _mixer = 0; delete _savefileManager; @@ -223,11 +220,6 @@ Common::TimerManager *ModularBackend::getTimerManager() { return _timerManager; } -Common::EventManager *ModularBackend::getEventManager() { - assert(_eventManager); - return _eventManager; -} - OSystem::MutexRef ModularBackend::createMutex() { assert(_mutexManager); return _mutexManager->createMutex(); diff --git a/backends/modular-backend.h b/backends/modular-backend.h index a978f2062c..42bd0ed73a 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -111,7 +111,6 @@ public: //@{ virtual Common::TimerManager *getTimerManager(); - virtual Common::EventManager *getEventManager(); virtual Common::HardwareKeySet *getHardwareKeySet() { return 0; } //@} @@ -148,7 +147,6 @@ protected: //@{ FilesystemFactory *_fsFactory; - Common::EventManager *_eventManager; Common::SaveFileManager *_savefileManager; Common::TimerManager *_timerManager; MutexManager *_mutexManager; diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index e3a2f77dc8..9336468b35 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -603,11 +603,7 @@ void OSystem_PS2::delayMillis(uint msecs) { Common::TimerManager *OSystem_PS2::getTimerManager() { return _scummTimerManager; } -/* -Common::EventManager *OSystem_PS2::getEventManager() { - return getEventManager(); -} -*/ + Audio::Mixer *OSystem_PS2::getMixer() { return _scummMixer; } diff --git a/backends/platform/ps2/systemps2.h b/backends/platform/ps2/systemps2.h index 5e59a4f0c4..cc9c489827 100644 --- a/backends/platform/ps2/systemps2.h +++ b/backends/platform/ps2/systemps2.h @@ -94,7 +94,6 @@ public: virtual uint32 getMillis(); virtual void delayMillis(uint msecs); virtual Common::TimerManager *getTimerManager(); -// virtual Common::EventManager *getEventManager(); virtual bool pollEvent(Common::Event &event); virtual Audio::Mixer *getMixer(); diff --git a/common/system.cpp b/common/system.cpp index 298f1d7d0d..2a0dfd8dfd 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -26,8 +26,9 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_fflush #include "common/system.h" -#include "common/str.h" +#include "common/events.h" #include "common/fs.h" +#include "common/str.h" #include "common/textconsole.h" #include "backends/audiocd/default/default-audiocd.h" @@ -36,19 +37,29 @@ OSystem *g_system = 0; OSystem::OSystem() { _audiocdManager = 0; + _eventManager = 0; } OSystem::~OSystem() { delete _audiocdManager; + _audiocdManager = 0; + + delete _eventManager; + _eventManager = 0; } void OSystem::initBackend() { + // Init AudioCD manager #ifndef DISABLE_DEFAULT_AUDIOCD_MANAGER if (!_audiocdManager) _audiocdManager = new DefaultAudioCDManager(); #endif if (!_audiocdManager) error("Backend failed to instantiate AudioCD manager"); + + // Verify Event manager has been set + if (!_eventManager) + error("Backend failed to instantiate Event manager"); } bool OSystem::setGraphicsMode(const char *name) { diff --git a/common/system.h b/common/system.h index 85771cf982..87e74d928c 100644 --- a/common/system.h +++ b/common/system.h @@ -113,6 +113,21 @@ protected: */ AudioCDManager *_audiocdManager; + /** + * For backend authors only, this pointer may be set by OSystem + * subclasses to an EventManager instance. This is only useful + * if your backend does not want to use the DefaultEventManager. + * + * This instance is returned by OSystem::getEventManager(), + * and it is deleted by the OSystem destructor. + * + * A backend may set this pointer in its initBackend() method, + * its constructor or somewhere in between; but it must + * set it no later than in its initBackend() implementation, because + * OSystem::initBackend() will by default create a DefaultEventManager + * instance if _eventManager has not yet been set. + */ + Common::EventManager *_eventManager; public: /** @@ -848,7 +863,9 @@ public: * Return the event manager singleton. For more information, refer * to the EventManager documentation. */ - virtual Common::EventManager *getEventManager() = 0; + inline Common::EventManager *getEventManager() { + return _eventManager; + } /** * Register hardware keys with keymapper |