diff options
-rw-r--r-- | backends/modular-backend.cpp | 26 | ||||
-rw-r--r-- | backends/modular-backend.h | 8 | ||||
-rw-r--r-- | common/system.cpp | 43 | ||||
-rw-r--r-- | common/system.h | 81 |
4 files changed, 97 insertions, 61 deletions
diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index bbf6a6c1ed..e36348abd5 100644 --- a/backends/modular-backend.cpp +++ b/backends/modular-backend.cpp @@ -30,14 +30,13 @@ #include "audio/mixer.h" #include "common/events.h" +#include "common/timer.h" +#include "common/savefile.h" #include "gui/message.h" #include "graphics/pixelformat.h" ModularBackend::ModularBackend() : - _fsFactory(0), - _savefileManager(0), - _timerManager(0), _mutexManager(0), _graphicsManager(0), _mixer(0) { @@ -45,16 +44,10 @@ ModularBackend::ModularBackend() } ModularBackend::~ModularBackend() { - delete _fsFactory; - _fsFactory = 0; delete _graphicsManager; _graphicsManager = 0; delete _mixer; _mixer = 0; - delete _savefileManager; - _savefileManager = 0; - delete _timerManager; - _timerManager = 0; delete _mutexManager; _mutexManager = 0; } @@ -215,11 +208,6 @@ void ModularBackend::setCursorPalette(const byte *colors, uint start, uint num) _graphicsManager->setCursorPalette(colors, start, num); } -Common::TimerManager *ModularBackend::getTimerManager() { - assert(_timerManager); - return _timerManager; -} - OSystem::MutexRef ModularBackend::createMutex() { assert(_mutexManager); return _mutexManager->createMutex(); @@ -249,16 +237,6 @@ void ModularBackend::displayMessageOnOSD(const char *msg) { _graphicsManager->displayMessageOnOSD(msg); } -Common::SaveFileManager *ModularBackend::getSavefileManager() { - assert(_savefileManager); - return _savefileManager; -} - -FilesystemFactory *ModularBackend::getFilesystemFactory() { - assert(_fsFactory); - return _fsFactory; -} - void ModularBackend::quit() { exit(0); } diff --git a/backends/modular-backend.h b/backends/modular-backend.h index 42bd0ed73a..d2c3ce2067 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -24,8 +24,6 @@ #define BACKENDS_MODULAR_BACKEND_H #include "common/system.h" -#include "common/timer.h" -#include "common/savefile.h" class GraphicsManager; class MutexManager; @@ -110,7 +108,6 @@ public: /** @name Events and Time */ //@{ - virtual Common::TimerManager *getTimerManager(); virtual Common::HardwareKeySet *getHardwareKeySet() { return 0; } //@} @@ -135,8 +132,6 @@ public: /** @name Miscellaneous */ //@{ - virtual Common::SaveFileManager *getSavefileManager(); - virtual FilesystemFactory *getFilesystemFactory(); virtual void quit(); virtual void displayMessageOnOSD(const char *msg); @@ -146,9 +141,6 @@ protected: /** @name Managers variables */ //@{ - FilesystemFactory *_fsFactory; - Common::SaveFileManager *_savefileManager; - Common::TimerManager *_timerManager; MutexManager *_mutexManager; GraphicsManager *_graphicsManager; Audio::Mixer *_mixer; diff --git a/common/system.cpp b/common/system.cpp index cd6ee46335..e34aeb54d6 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -34,12 +34,16 @@ #include "common/textconsole.h" #include "backends/audiocd/default/default-audiocd.h" +#include "backends/timer/default/default-timer.h" OSystem *g_system = 0; OSystem::OSystem() { _audiocdManager = 0; _eventManager = 0; + _timerManager = 0; + _savefileManager = 0; + _fsFactory = 0; } OSystem::~OSystem() { @@ -48,20 +52,35 @@ OSystem::~OSystem() { delete _eventManager; _eventManager = 0; + + delete _timerManager; + _timerManager = 0; + + delete _savefileManager; + _savefileManager = 0; + + delete _fsFactory; + _fsFactory = 0; } void OSystem::initBackend() { - // Init AudioCD manager + // Init audio CD 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 + // Verify all managers has been set + if (!_audiocdManager) + error("Backend failed to instantiate audio CD manager"); if (!_eventManager) - error("Backend failed to instantiate Event manager"); + error("Backend failed to instantiate event manager"); + if (!_timerManager) + error("Backend failed to instantiate timer manager"); +// if (!_savefileManager) +// error("Backend failed to instantiate savefile manager"); +// if (!_fsFactory) +// error("Backend failed to instantiate fs factory"); } bool OSystem::setGraphicsMode(const char *name) { @@ -90,6 +109,20 @@ void OSystem::fatalError() { exit(1); } +Common::TimerManager *OSystem::getTimerManager() { + return _timerManager; +} + +Common::SaveFileManager *OSystem::getSavefileManager() { + assert(_savefileManager); + return _savefileManager; +} + +FilesystemFactory *OSystem::getFilesystemFactory() { + assert(_fsFactory); + return _fsFactory; +} + Common::SeekableReadStream *OSystem::createConfigReadStream() { Common::FSNode file(getDefaultConfigFileName()); return file.createReadStream(); diff --git a/common/system.h b/common/system.h index 780e5fcc7d..9036dcd6e1 100644 --- a/common/system.h +++ b/common/system.h @@ -98,36 +98,69 @@ protected: protected: /** - * For backend authors only, this pointer may be set by OSystem - * subclasses to an AudioCDManager instance. This is only useful - * if your backend does not want to use the DefaultAudioCDManager. + * @name Module slots * - * This instance is returned by OSystem::getAudioCDManager(), - * and it is deleted by the OSystem destructor. + * For backend authors only, the following pointers (= "slots) to various + * subsystem managers / factories / etc. can and should be set to + * a suitable instance of the respective type. * - * 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 DefaultAudioCDManager - * instance if _audiocdManager has not yet been set. + * For some of the slots, a default instance is set if your backend + * does not do so. For details, please look at the documentation of + * each slot. + * + * A backend may setup slot values in its initBackend() method, + * its constructor or somewhere in between. But it must a slot's value + * no later than in its initBackend() implementation, because + * OSystem::initBackend() will create any default instances if + * none has been set yet (and for other slots, will verify that + * one has been set; if not, an error may be generated). */ - 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. + * If no value is provided for this slot, then OSystem::initBackend() + * will populate it with a DefaultAudioCDManager instance. * - * This instance is returned by OSystem::getEventManager(), - * and it is deleted by the OSystem destructor. + * @note _audiocdManager is deleted by the OSystem destructor. + */ + AudioCDManager *_audiocdManager; + + /** + * No default value is provided for _eventManager by OSystem. + * However, BaseBackend::initBackend() does set a default value + * if none has been set before. * - * 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. + * @note _eventManager is deleted by the OSystem destructor. */ Common::EventManager *_eventManager; + + /** + * No default value is provided for _timerManager by OSystem. + * + * @note _timerManager is deleted by the OSystem destructor. + */ + Common::TimerManager *_timerManager; + + /** + * No default value is provided for _savefileManager by OSystem. + * + * @note _savefileManager is deleted by the OSystem destructor. + */ + Common::SaveFileManager *_savefileManager; + + /** + * No default value is provided for _fsFactory by OSystem. + * + * Note that _fsFactory is typically required very early on, + * so it usually should be set in the backends constructor or shortly + * thereafter, and before initBackend() is called. + * + * @note _fsFactory is deleted by the OSystem destructor. + */ + FilesystemFactory *_fsFactory; + + //@} + public: /** @@ -857,7 +890,7 @@ public: * Return the timer manager singleton. For more information, refer * to the TimerManager documentation. */ - virtual Common::TimerManager *getTimerManager() = 0; + virtual Common::TimerManager *getTimerManager(); /** * Return the event manager singleton. For more information, refer @@ -1007,14 +1040,14 @@ public: * and other modifiable persistent game data. For more information, * refer to the SaveFileManager documentation. */ - virtual Common::SaveFileManager *getSavefileManager() = 0; + virtual Common::SaveFileManager *getSavefileManager(); /** * Returns the FilesystemFactory object, depending on the current architecture. * * @return the FSNode factory for the current architecture */ - virtual FilesystemFactory *getFilesystemFactory() = 0; + virtual FilesystemFactory *getFilesystemFactory(); /** * Add system specific Common::Archive objects to the given SearchSet. |