diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index bbf6a6c1ed83..e36348abd587 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 42bd0ed73ad8..d2c3ce206756 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 @@ class ModularBackend : public OSystem { /** @name Events and Time */ //@{ - virtual Common::TimerManager *getTimerManager(); virtual Common::HardwareKeySet *getHardwareKeySet() { return 0; } //@} @@ -135,8 +132,6 @@ class ModularBackend : public OSystem { /** @name Miscellaneous */ //@{ - virtual Common::SaveFileManager *getSavefileManager(); - virtual FilesystemFactory *getFilesystemFactory(); virtual void quit(); virtual void displayMessageOnOSD(const char *msg); @@ -146,9 +141,6 @@ class ModularBackend : public OSystem { /** @name Managers variables */ //@{ - FilesystemFactory *_fsFactory; - Common::SaveFileManager *_savefileManager; - Common::TimerManager *_timerManager; MutexManager *_mutexManager; GraphicsManager *_graphicsManager; Audio::Mixer *_mixer; diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index a67ee51b4d35..1acb080a60c1 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -132,10 +132,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _show_mouse(false), _show_overlay(false), _enable_zoning(false), - _savefile(0), _mixer(0), - _timer(0), - _fsFactory(new POSIXFilesystemFactory()), _shake_offset(0), _event_queue_lock(createMutex()), _touch_pt_down(), @@ -149,6 +146,9 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _dpad_scale(4), _fingersDown(0), _trackball_scale(2) { + + _fsFactory = new POSIXFilesystemFactory(); + Common::String mf = getSystemProperty("ro.product.manufacturer"); LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s", @@ -170,17 +170,17 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : OSystem_Android::~OSystem_Android() { ENTER(); - delete _savefile; - delete _timer; delete _mixer; + _mixer = 0; delete _fsFactory; + _fsFactory = 0; deleteMutex(_event_queue_lock); } void *OSystem_Android::timerThreadFunc(void *arg) { OSystem_Android *system = (OSystem_Android *)arg; - DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer); + DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timerManager); // renice this thread to boost the audio thread if (setpriority(PRIO_PROCESS, 0, 19) < 0) @@ -359,8 +359,8 @@ void OSystem_Android::initBackend() { // BUG: "transient" ConfMan settings get nuked by the options // screen. Passing the savepath in this way makes it stick // (via ConfMan.registerDefault) - _savefile = new DefaultSaveFileManager(ConfMan.get("savepath")); - _timer = new DefaultTimerManager(); + _savefileManager = new DefaultSaveFileManager(ConfMan.get("savepath")); + _timerManager = new DefaultTimerManager(); gettimeofday(&_startTime, 0); @@ -535,21 +535,11 @@ void OSystem_Android::showVirtualKeyboard(bool enable) { JNI::showVirtualKeyboard(enable); } -Common::SaveFileManager *OSystem_Android::getSavefileManager() { - assert(_savefile); - return _savefile; -} - Audio::Mixer *OSystem_Android::getMixer() { assert(_mixer); return _mixer; } -Common::TimerManager *OSystem_Android::getTimerManager() { - assert(_timer); - return _timer; -} - void OSystem_Android::getTimeAndDate(TimeDate &td) const { struct tm tm; const time_t curTime = time(0); @@ -563,10 +553,6 @@ void OSystem_Android::getTimeAndDate(TimeDate &td) const { td.tm_year = tm.tm_year; } -FilesystemFactory *OSystem_Android::getFilesystemFactory() { - return _fsFactory; -} - void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { ENTER(""); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index b70fdb7c30c1..cd7ad5f8f037 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -152,10 +152,7 @@ class OSystem_Android : public BaseBackend, public PaletteManager { bool _enable_zoning; bool _virtkeybd_on; - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - Common::TimerManager *_timer; - FilesystemFactory *_fsFactory; timeval _startTime; Common::String getSystemProperty(const char *name) const; @@ -289,11 +286,8 @@ class OSystem_Android : public BaseBackend, public PaletteManager { virtual void displayMessageOnOSD(const char *msg); virtual void showVirtualKeyboard(bool enable); - virtual Common::SaveFileManager *getSavefileManager(); virtual Audio::Mixer *getMixer(); virtual void getTimeAndDate(TimeDate &t) const; - virtual Common::TimerManager *getTimerManager(); - virtual FilesystemFactory *getFilesystemFactory(); virtual void logMessage(LogMessageType::Type type, const char *message); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h index c7659e8292e9..84fdd581689b 100644 --- a/backends/platform/dc/dc.h +++ b/backends/platform/dc/dc.h @@ -185,24 +185,19 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Palette void setWindowCaption(const char *caption); // Modulatized backend - Common::SaveFileManager *getSavefileManager() { return _savefile; } Audio::Mixer *getMixer() { return _mixer; } - Common::TimerManager *getTimerManager() { return _timer; } // Extra SoftKbd support void mouseToSoftKbd(int x, int y, int &rx, int &ry) const; // Filesystem - FilesystemFactory *getFilesystemFactory() { return this; } AbstractFSNode *makeRootFileNode() const; AbstractFSNode *makeCurrentDirectoryFileNode() const; AbstractFSNode *makeFileNodePath(const Common::String &path) const; private: - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - DefaultTimerManager *_timer; SoftKeyboard _softkbd; int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y; diff --git a/backends/platform/dc/dcmain.cpp b/backends/platform/dc/dcmain.cpp index 47bfb0c15d24..d1fcdd4a0524 100644 --- a/backends/platform/dc/dcmain.cpp +++ b/backends/platform/dc/dcmain.cpp @@ -41,20 +41,21 @@ const char *gGameName; OSystem_Dreamcast::OSystem_Dreamcast() : _devpoll(0), screen(NULL), mouse(NULL), overlay(NULL), _softkbd(this), - _ms_buf(NULL), _timer(NULL), _mixer(NULL), _savefile(NULL), + _ms_buf(NULL), _mixer(NULL), _current_shake_pos(0), _aspect_stretch(false), _softkbd_on(false), _softkbd_motion(0), _enable_cursor_palette(false), _screenFormat(0) { memset(screen_tx, 0, sizeof(screen_tx)); memset(mouse_tx, 0, sizeof(mouse_tx)); memset(ovl_tx, 0, sizeof(ovl_tx)); + _fsFactory = this; } void OSystem_Dreamcast::initBackend() { ConfMan.setInt("autosave_period", 0); - _savefile = createSavefileManager(); - _timer = new DefaultTimerManager(); + _savefileManager = createSavefileManager(); + _timerManager = new DefaultTimerManager(); uint sampleRate = initSound(); _mixer = new Audio::MixerImpl(this, sampleRate); diff --git a/backends/platform/dc/input.cpp b/backends/platform/dc/input.cpp index 7054ad196e00..3759eec6dfc4 100644 --- a/backends/platform/dc/input.cpp +++ b/backends/platform/dc/input.cpp @@ -192,8 +192,8 @@ bool OSystem_Dreamcast::pollEvent(Common::Event &event) { unsigned int t = Timer(); - if (_timer != NULL) - _timer->handler(); + if (_timerManager != NULL) + ((DefaultTimerManager *)_timerManager)->handler(); if (((int)(t-_devpoll))<0) return false; diff --git a/backends/platform/dc/time.cpp b/backends/platform/dc/time.cpp index c343852321f6..8cc3a71e8df9 100644 --- a/backends/platform/dc/time.cpp +++ b/backends/platform/dc/time.cpp @@ -48,8 +48,8 @@ void OSystem_Dreamcast::delayMillis(uint msecs) unsigned int t, start = Timer(); int time = (((unsigned int)msecs)*3125U)>>6; while (((int)((t = Timer())-start))handler(); + if (_timerManager != NULL) + ((DefaultTimerManager *)_timerManager)->handler(); checkSound(); } getMillis(); diff --git a/backends/platform/ds/arm9/source/osystem_ds.cpp b/backends/platform/ds/arm9/source/osystem_ds.cpp index eab9fd6a3342..8fbe5ac934c8 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.cpp +++ b/backends/platform/ds/arm9/source/osystem_ds.cpp @@ -42,6 +42,7 @@ #include "backends/fs/ds/ds-fs-factory.h" #include "backends/audiocd/default/default-audiocd.h" +#include "backends/timer/default/default-timer.h" #ifdef ENABLE_AGI #include "wordcompletion.h" @@ -81,7 +82,7 @@ OSystem_DS *OSystem_DS::_instance = NULL; OSystem_DS::OSystem_DS() - : eventNum(0), lastPenFrame(0), queuePos(0), _mixer(NULL), _timer(NULL), _frameBufferExists(false), + : eventNum(0), lastPenFrame(0), queuePos(0), _mixer(NULL), _frameBufferExists(false), _disableCursorPalette(true), _graphicsEnable(true), _gammaValue(0) { // eventNum = 0; @@ -89,13 +90,11 @@ OSystem_DS::OSystem_DS() // queuePos = 0; _instance = this; // _mixer = NULL; - // _timer = NULL; //_frameBufferExists = false; } OSystem_DS::~OSystem_DS() { delete _mixer; - delete _timer; } int OSystem_DS::timerHandler(int t) { @@ -108,7 +107,11 @@ void OSystem_DS::initBackend() { ConfMan.setInt("autosave_period", 0); ConfMan.setBool("FM_medium_quality", true); - _timer = new DefaultTimerManager(); + if (DS::isGBAMPAvailable()) { + _savefileManager = &mpSaveManager; + } + + _timerManager = new DefaultTimerManager(); DS::setTimerCallback(&OSystem_DS::timerHandler, 10); if (ConfMan.hasKey("22khzaudio", "ds") && ConfMan.getBool("22khzaudio", "ds")) { @@ -747,14 +750,6 @@ void OSystem_DS::quit() { swiSoftReset();*/ } -Common::SaveFileManager *OSystem_DS::getSavefileManager() { - if (DS::isGBAMPAvailable()) { - return &mpSaveManager; - } - return NULL; -} - - Graphics::Surface *OSystem_DS::createTempFrameBuffer() { // Ensure we copy using 16 bit quantities due to limitation of VRAM addressing diff --git a/backends/platform/ds/arm9/source/osystem_ds.h b/backends/platform/ds/arm9/source/osystem_ds.h index 1e032ba2cf39..b8a12a5808e9 100644 --- a/backends/platform/ds/arm9/source/osystem_ds.h +++ b/backends/platform/ds/arm9/source/osystem_ds.h @@ -29,7 +29,6 @@ #include "nds.h" #include "gbampsave.h" #include "backends/saves/default/default-saves.h" -#include "backends/timer/default/default-timer.h" #include "audio/mixer_intern.h" #include "graphics/surface.h" #include "graphics/colormasks.h" @@ -46,7 +45,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager { GBAMPSaveFileManager mpSaveManager; Audio::MixerImpl *_mixer; - DefaultTimerManager *_timer; Graphics::Surface _framebuffer; bool _frameBufferExists; bool _graphicsEnable; @@ -140,8 +138,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager { virtual void quit(); - virtual Common::SaveFileManager *getSavefileManager(); - void addEvent(const Common::Event& e); bool isEventQueueEmpty() const { return queuePos == 0; } @@ -159,7 +155,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager { virtual Audio::Mixer *getMixer() { return _mixer; } Audio::MixerImpl *getMixerImpl() { return _mixer; } - virtual Common::TimerManager *getTimerManager() { return _timer; } static int timerHandler(int t); diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index 9007f006f83c..5f27091108db 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -53,7 +53,7 @@ SoundProc OSystem_IPHONE::s_soundCallback = NULL; void *OSystem_IPHONE::s_soundParam = NULL; OSystem_IPHONE::OSystem_IPHONE() : - _savefile(NULL), _mixer(NULL), _timer(NULL), _offscreen(NULL), + _mixer(NULL), _offscreen(NULL), _overlayVisible(false), _fullscreen(NULL), _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _queuedEventTime(0), _secondaryTapped(false), _lastSecondaryTap(0), @@ -72,10 +72,7 @@ OSystem_IPHONE::OSystem_IPHONE() : OSystem_IPHONE::~OSystem_IPHONE() { AudioQueueDispose(s_AudioQueue.queue, true); - delete _fsFactory; - delete _savefile; delete _mixer; - delete _timer; delete _offscreen; delete _fullscreen; } @@ -88,12 +85,12 @@ int OSystem_IPHONE::timerHandler(int t) { void OSystem_IPHONE::initBackend() { #ifdef IPHONE_OFFICIAL - _savefile = new DefaultSaveFileManager(iPhone_getDocumentsDir()); + _savefileManager = new DefaultSaveFileManager(iPhone_getDocumentsDir()); #else - _savefile = new DefaultSaveFileManager(SCUMMVM_SAVE_PATH); + _savefileManager = new DefaultSaveFileManager(SCUMMVM_SAVE_PATH); #endif - _timer = new DefaultTimerManager(); + _timerManager = new DefaultTimerManager(); gettimeofday(&_startTime, NULL); @@ -210,21 +207,11 @@ void OSystem_IPHONE::getTimeAndDate(TimeDate &td) const { td.tm_year = t.tm_year; } -Common::SaveFileManager *OSystem_IPHONE::getSavefileManager() { - assert(_savefile); - return _savefile; -} - Audio::Mixer *OSystem_IPHONE::getMixer() { assert(_mixer); return _mixer; } -Common::TimerManager *OSystem_IPHONE::getTimerManager() { - assert(_timer); - return _timer; -} - OSystem *OSystem_IPHONE_create() { return new OSystem_IPHONE(); } diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index 36b4b7356b91..e5ec22f19fe7 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -57,9 +57,7 @@ class OSystem_IPHONE : public BaseBackend, public PaletteManager { static SoundProc s_soundCallback; static void *s_soundParam; - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - Common::TimerManager *_timer; Graphics::Surface _framebuffer; byte *_offscreen; @@ -110,7 +108,6 @@ class OSystem_IPHONE : public BaseBackend, public PaletteManager { bool _fullScreenIsDirty; bool _fullScreenOverlayIsDirty; int _screenChangeCount; - FilesystemFactory *_fsFactory; public: @@ -173,13 +170,10 @@ class OSystem_IPHONE : public BaseBackend, public PaletteManager { virtual int getScreenChangeID() const { return _screenChangeCount; } virtual void quit(); - FilesystemFactory *getFilesystemFactory() { return _fsFactory; } virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); virtual void getTimeAndDate(TimeDate &t) const; - virtual Common::SaveFileManager *getSavefileManager(); virtual Audio::Mixer *getMixer(); - virtual Common::TimerManager *getTimerManager(); void startSoundsystem(); void stopSoundsystem(); diff --git a/backends/platform/n64/osys_n64.h b/backends/platform/n64/osys_n64.h index f22b221ccc08..2c908c7fc322 100644 --- a/backends/platform/n64/osys_n64.h +++ b/backends/platform/n64/osys_n64.h @@ -27,8 +27,6 @@ #include "common/config-manager.h" #include "backends/base-backend.h" -#include "backends/saves/default/default-saves.h" -#include "backends/timer/default/default-timer.h" #include "base/main.h" @@ -75,10 +73,7 @@ enum GraphicModeID { class OSystem_N64 : public BaseBackend, public PaletteManager { protected: - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - Common::TimerManager *_timer; - FilesystemFactory *_fsFactory; struct display_context * _dc; // Display context for N64 on screen buffer switching @@ -201,12 +196,9 @@ class OSystem_N64 : public BaseBackend, public PaletteManager { virtual void quit(); - virtual Common::SaveFileManager *getSavefileManager(); virtual Audio::Mixer *getMixer(); virtual void getTimeAndDate(TimeDate &t) const; - virtual Common::TimerManager *getTimerManager(); virtual void setTimerCallback(TimerProc callback, int interval); - FilesystemFactory *getFilesystemFactory(); void rebuildOffscreenGameBuffer(void); void rebuildOffscreenMouseBuffer(void); diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp index 62fe145bcc6d..68a1a4860765 100644 --- a/backends/platform/n64/osys_n64_base.cpp +++ b/backends/platform/n64/osys_n64_base.cpp @@ -30,6 +30,8 @@ #include "pakfs_save_manager.h" #include "framfs_save_manager.h" #include "backends/fs/n64/n64-fs-factory.h" +#include "backends/saves/default/default-saves.h" +#include "backends/timer/default/default-timer.h" typedef unsigned long long uint64; @@ -137,9 +139,7 @@ OSystem_N64::OSystem_N64() { _mouseMaxX = _overlayWidth; _mouseMaxY = _overlayHeight; - _savefile = 0; _mixer = 0; - _timer = 0; _dirtyOffscreen = false; @@ -154,10 +154,7 @@ OSystem_N64::OSystem_N64() { } OSystem_N64::~OSystem_N64() { - delete _savefile; delete _mixer; - delete _timer; - delete _fsFactory; } void OSystem_N64::initBackend() { @@ -170,7 +167,7 @@ void OSystem_N64::initBackend() { if (FRAM_Detect()) { // Use FlashRAM initFramFS(); - _savefile = new FRAMSaveManager(); + _savefileManager = new FRAMSaveManager(); } else { // Use PakFS // Init Controller Pak initPakFs(); @@ -185,10 +182,10 @@ void OSystem_N64::initBackend() { } } - _savefile = new PAKSaveManager(); + _savefileManager = new PAKSaveManager(); } - _timer = new DefaultTimerManager(); + _timerManager = new DefaultTimerManager(); setTimerCallback(&timer_handler, 10); @@ -851,21 +848,11 @@ void OSystem_N64::quit() { return; } -Common::SaveFileManager *OSystem_N64::getSavefileManager() { - assert(_savefile); - return _savefile; -} - Audio::Mixer *OSystem_N64::getMixer() { assert(_mixer); return _mixer; } -Common::TimerManager *OSystem_N64::getTimerManager() { - assert(_timer); - return _timer; -} - void OSystem_N64::getTimeAndDate(TimeDate &t) const { // No RTC inside the N64, read mips timer to simulate // passing of time, not a perfect solution, but can't think @@ -883,10 +870,6 @@ void OSystem_N64::getTimeAndDate(TimeDate &t) const { return; } -FilesystemFactory *OSystem_N64::getFilesystemFactory() { - return _fsFactory; -} - void OSystem_N64::setTimerCallback(TimerProc callback, int interval) { assert (interval > 0); diff --git a/backends/platform/n64/osys_n64_utilities.cpp b/backends/platform/n64/osys_n64_utilities.cpp index 8d9f0471d3db..0622e6423db7 100644 --- a/backends/platform/n64/osys_n64_utilities.cpp +++ b/backends/platform/n64/osys_n64_utilities.cpp @@ -21,6 +21,7 @@ */ #include "osys_n64.h" +#include "backends/timer/default/default-timer.h" void checkTimers(void) { OSystem_N64 *osys = (OSystem_N64 *)g_system; diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp index 4c29636e4072..6bac4ea7d75c 100644 --- a/backends/platform/openpandora/op-backend.cpp +++ b/backends/platform/openpandora/op-backend.cpp @@ -177,26 +177,6 @@ void OSystem_OP::initBackend() { _inited = true; } - - - // enable joystick -// if (joystick_num > -1 && SDL_NumJoysticks() > 0) { -// printf("Using joystick: %s\n", SDL_JoystickName(0)); -// _joystick = SDL_JoystickOpen(joystick_num); -// } -// -// setupMixer(); - - // Note: We could implement a custom SDLTimerManager by using - // SDL_AddTimer. That might yield better timer resolution, but it would - // also change the semantics of a timer: Right now, ScummVM timers - // *never* run in parallel, due to the way they are implemented. If we - // switched to SDL_AddTimer, each timer might run in a separate thread. - // However, not all our code is prepared for that, so we can't just - // switch. Still, it's a potential future change to keep in mind. -// _timer = new DefaultTimerManager(); -// _timerID = SDL_AddTimer(10, &timer_handler, _timer); - void OSystem_OP::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index 728a67fbadf9..d3acd060892c 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -60,7 +60,6 @@ #include "backends/fs/ps2/ps2-fs-factory.h" #include "backends/plugins/ps2/ps2-provider.h" -#include "backends/saves/default/default-saves.h" #include "backends/timer/default/default-timer.h" #include "audio/mixer_intern.h" @@ -348,14 +347,14 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) { void OSystem_PS2::init(void) { sioprintf("Timer...\n"); - _scummTimerManager = new DefaultTimerManager(); + _timerManager = new DefaultTimerManager(); _scummMixer = new Audio::MixerImpl(this, 48000); _scummMixer->setReady(true); initTimer(); sioprintf("Starting SavefileManager\n"); - _saveManager = new Ps2SaveFileManager(this, _screen); + _savefileManager = new Ps2SaveFileManager(this, _screen); sioprintf("Initializing ps2Input\n"); _input = new Ps2Input(this, _useMouse, _useKbd); @@ -430,7 +429,7 @@ void OSystem_PS2::initTimer(void) { void OSystem_PS2::timerThreadCallback(void) { while (!_systemQuit) { WaitSema(g_TimerThreadSema); - _scummTimerManager->handler(); + ((DefaultTimerManager *)_timerManager)->handler(); } ExitThread(); } @@ -600,18 +599,10 @@ void OSystem_PS2::delayMillis(uint msecs) { } } -Common::TimerManager *OSystem_PS2::getTimerManager() { - return _scummTimerManager; -} - Audio::Mixer *OSystem_PS2::getMixer() { return _scummMixer; } -Common::SaveFileManager *OSystem_PS2::getSavefileManager(void) { - return _saveManager; -} - FilesystemFactory *OSystem_PS2::getFilesystemFactory() { return &Ps2FilesystemFactory::instance(); } @@ -770,7 +761,7 @@ void OSystem_PS2::msgPrintf(int millis, const char *format, ...) { void OSystem_PS2::powerOffCallback(void) { sioprintf("powerOffCallback\n"); - // _saveManager->quit(); // romeo + // _savefileManager->quit(); // romeo if (_useHdd) { sioprintf("umount\n"); fio.umount("pfs0:"); @@ -810,7 +801,7 @@ void OSystem_PS2::quit(void) { DisableIntc(INT_TIMER0); RemoveIntcHandler(INT_TIMER0, _intrId); - // _saveManager->quit(); // romeo + // _savefileManager->quit(); // romeo _screen->quit(); padEnd(); // stop pad library diff --git a/backends/platform/ps2/systemps2.h b/backends/platform/ps2/systemps2.h index cc9c489827c8..d12d02b10487 100644 --- a/backends/platform/ps2/systemps2.h +++ b/backends/platform/ps2/systemps2.h @@ -27,12 +27,8 @@ #include "backends/base-backend.h" #include "graphics/palette.h" -class DefaultTimerManager; -class DefaultSaveFileManager; - class Gs2dScreen; class Ps2Input; -class Ps2SaveFileManager; // class Ps2FilesystemFactory; struct IrxReference; @@ -44,10 +40,6 @@ struct Ps2Mutex { int count; }; -namespace Common { -class TimerManager; -}; - namespace Audio { class MixerImpl; }; @@ -93,7 +85,6 @@ class OSystem_PS2 : public BaseBackend, public PaletteManager { virtual uint32 getMillis(); virtual void delayMillis(uint msecs); - virtual Common::TimerManager *getTimerManager(); virtual bool pollEvent(Common::Event &event); virtual Audio::Mixer *getMixer(); @@ -116,7 +107,6 @@ class OSystem_PS2 : public BaseBackend, public PaletteManager { virtual void logMessage(LogMessageType::Type type, const char *message); virtual Graphics::PixelFormat getOverlayFormat() const; - virtual Common::SaveFileManager *getSavefileManager(); virtual FilesystemFactory *getFilesystemFactory(); virtual void getTimeAndDate(TimeDate &t) const; @@ -144,15 +134,11 @@ class OSystem_PS2 : public BaseBackend, public PaletteManager { void initTimer(void); void readRtcTime(void); - DefaultTimerManager *_scummTimerManager; Audio::MixerImpl *_scummMixer; bool _mouseVisible; bool _useMouse, _useKbd, _useHdd, _usbMassLoaded, _useNet; - Ps2SaveFileManager *_saveManager; - // DefaultSaveFileManager *_saveManager; - Gs2dScreen *_screen; Ps2Input *_input; uint16 _oldMouseX, _oldMouseY; diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index 4408cbf4811e..12916f872535 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -89,9 +89,9 @@ void OSystem_PSP::initBackend() { _imageViewer.setInputHandler(&_inputHandler); _imageViewer.setDisplayManager(&_displayManager); - _savefile = new PSPSaveFileManager; + _savefileManager = new PSPSaveFileManager; - _timer = new DefaultTimerManager(); + _timerManager = new DefaultTimerManager(); PSP_DEBUG_PRINT("calling keyboard.load()\n"); _keyboard.load(); // Load virtual keyboard files into memory diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 4f1d6f2fa78d..8ca09924ad34 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -45,9 +45,7 @@ class OSystem_PSP : public BaseBackend, public PaletteManager { private: - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - Common::TimerManager *_timer; bool _pendingUpdate; // save an update we couldn't perform uint32 _pendingUpdateCounter; // prevent checking for pending update too often, in a cheap way @@ -63,7 +61,7 @@ class OSystem_PSP : public BaseBackend, public PaletteManager { ImageViewer _imageViewer; public: - OSystem_PSP() : _savefile(0), _mixer(0), _timer(0), _pendingUpdate(false), _pendingUpdateCounter(0) {} + OSystem_PSP() : _mixer(0), _pendingUpdate(false), _pendingUpdateCounter(0) {} ~OSystem_PSP(); static OSystem *instance(); @@ -133,7 +131,6 @@ class OSystem_PSP : public BaseBackend, public PaletteManager { // Timer typedef int (*TimerProc)(int interval); void setTimerCallback(TimerProc callback, int interval); - Common::TimerManager *getTimerManager() { return _timer; } // Mutex MutexRef createMutex(void); @@ -147,7 +144,6 @@ class OSystem_PSP : public BaseBackend, public PaletteManager { Audio::Mixer *getMixer() { return _mixer; } // Misc - Common::SaveFileManager *getSavefileManager() { return _savefile; } FilesystemFactory *getFilesystemFactory() { return &PSPFilesystemFactory::instance(); } void getTimeAndDate(TimeDate &t) const; virtual void engineDone(); diff --git a/backends/platform/wii/osystem.cpp b/backends/platform/wii/osystem.cpp index c16578d9b30d..a981c61aeaed 100644 --- a/backends/platform/wii/osystem.cpp +++ b/backends/platform/wii/osystem.cpp @@ -34,6 +34,8 @@ #include "common/config-manager.h" #include "common/textconsole.h" #include "backends/fs/wii/wii-fs-factory.h" +#include "backends/saves/default/default-saves.h" +#include "backends/timer/default/default-timer.h" #include "osystem.h" #include "options.h" @@ -96,20 +98,12 @@ OSystem_Wii::OSystem_Wii() : _padSensitivity(16), _padAcceleration(4), - _savefile(NULL), - _mixer(NULL), - _timer(NULL) { + _mixer(NULL) { } OSystem_Wii::~OSystem_Wii() { - delete _savefile; - _savefile = NULL; - delete _mixer; _mixer = NULL; - - delete _timer; - _timer = NULL; } void OSystem_Wii::initBackend() { @@ -143,8 +137,8 @@ void OSystem_Wii::initBackend() { if (!getcwd(buf, MAXPATHLEN)) strcpy(buf, "/"); - _savefile = new DefaultSaveFileManager(buf); - _timer = new DefaultTimerManager(); + _savefileManager = new DefaultSaveFileManager(buf); + _timerManager = new DefaultTimerManager(); initGfx(); initSfx(); @@ -261,21 +255,11 @@ void OSystem_Wii::setWindowCaption(const char *caption) { printf("window caption: %s\n", caption); } -Common::SaveFileManager *OSystem_Wii::getSavefileManager() { - assert(_savefile); - return _savefile; -} - Audio::Mixer *OSystem_Wii::getMixer() { assert(_mixer); return _mixer; } -Common::TimerManager *OSystem_Wii::getTimerManager() { - assert(_timer); - return _timer; -} - FilesystemFactory *OSystem_Wii::getFilesystemFactory() { return &WiiFilesystemFactory::instance(); } diff --git a/backends/platform/wii/osystem.h b/backends/platform/wii/osystem.h index 981b25f69cff..fe214a95cdfe 100644 --- a/backends/platform/wii/osystem.h +++ b/backends/platform/wii/osystem.h @@ -32,8 +32,6 @@ #include "common/rect.h" #include "common/events.h" #include "backends/base-backend.h" -#include "backends/saves/default/default-saves.h" -#include "backends/timer/default/default-timer.h" #include "graphics/colormasks.h" #include "graphics/palette.h" #include "graphics/surface.h" @@ -130,9 +128,7 @@ class OSystem_Wii : public BaseBackend, public PaletteManager { void showOptionsDialog(); protected: - Common::SaveFileManager *_savefile; Audio::MixerImpl *_mixer; - DefaultTimerManager *_timer; public: enum { @@ -211,9 +207,7 @@ class OSystem_Wii : public BaseBackend, public PaletteManager { virtual void setWindowCaption(const char *caption); - virtual Common::SaveFileManager *getSavefileManager(); virtual Audio::Mixer *getMixer(); - virtual Common::TimerManager *getTimerManager(); virtual FilesystemFactory *getFilesystemFactory(); virtual void getTimeAndDate(TimeDate &t) const; diff --git a/backends/platform/wii/osystem_events.cpp b/backends/platform/wii/osystem_events.cpp index 8e51bbc673a2..389d3823e734 100644 --- a/backends/platform/wii/osystem_events.cpp +++ b/backends/platform/wii/osystem_events.cpp @@ -35,6 +35,7 @@ #endif #include "common/config-manager.h" +#include "backends/timer/default/default-timer.h" #define TIMER_THREAD_STACKSIZE (1024 * 32) #define TIMER_THREAD_PRIO 64 diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index a53bc416678b..d5f5c203d2c3 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -379,10 +379,17 @@ void OSystem_WINCE3::initBackend() { ((WINCESdlEventSource *)_eventSource)->init((WINCESdlGraphicsManager *)_graphicsManager); + + // FIXME: This timer manager is *not accesible* from the outside. + // Instead the timer manager setup by OSystem_SDL is visible on the outside. + // Since the WinCE backend actually seems to work, my guess is that + // SDL_AddTimer works after all and the following code is redundant. + // However it may be, this must be resolved one way or another. + // Create the timer. CE SDL does not support multiple timers (SDL_AddTimer). // We work around this by using the SetTimer function, since we only use // one timer in scummvm (for the time being) - _timer = _int_timer = new DefaultTimerManager(); + _int_timer = new DefaultTimerManager(); //_timerID = NULL; // OSystem_SDL will call removetimer with this, it's ok SDL_SetTimer(10, &timer_handler_wrapper); @@ -443,14 +450,9 @@ OSystem_WINCE3::OSystem_WINCE3() : OSystem_SDL(), } OSystem_WINCE3::~OSystem_WINCE3() { - delete _fsFactory; delete _mixer; } -FilesystemFactory *OSystem_WINCE3::getFilesystemFactory() { - return _fsFactory; -} - void OSystem_WINCE3::swap_sound_master() { _soundMaster = !_soundMaster; diff --git a/backends/platform/wince/wince-sdl.h b/backends/platform/wince/wince-sdl.h index a1e46081f9c3..adb63eb9363b 100644 --- a/backends/platform/wince/wince-sdl.h +++ b/backends/platform/wince/wince-sdl.h @@ -58,7 +58,6 @@ class OSystem_WINCE3 : public OSystem_SDL { void getTimeAndDate(TimeDate &t) const; virtual Common::String getDefaultConfigFileName(); - virtual FilesystemFactory *getFilesystemFactory(); void swap_sound_master(); @@ -73,8 +72,6 @@ class OSystem_WINCE3 : public OSystem_SDL { protected: void initSDL(); Audio::MixerImpl *_mixer; - DefaultTimerManager *_timer; - FilesystemFactory *_fsFactory; private: void check_mappings(); diff --git a/common/system.cpp b/common/system.cpp index cd6ee463353b..27baea59f956 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,43 @@ 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"); + + // TODO: We currently don't check _savefileManager, because at least + // on the Nintendo DS, it is possible that none is set. That should + // probably be treated as "saving is not possible". Or else the NDS + // port needs to be changed to always set a _savefileManager +// if (!_savefileManager) +// error("Backend failed to instantiate savefile manager"); + + // TODO: We currently don't check _fsFactory because not all ports + // set it. +// if (!_fsFactory) +// error("Backend failed to instantiate fs factory"); } bool OSystem::setGraphicsMode(const char *name) { @@ -90,6 +117,11 @@ void OSystem::fatalError() { exit(1); } +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 780e5fcc7d16..0d0ffda1e061 100644 --- a/common/system.h +++ b/common/system.h @@ -98,36 +98,69 @@ class OSystem : Common::NonCopyable { 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,9 @@ class OSystem : Common::NonCopyable { * Return the timer manager singleton. For more information, refer * to the TimerManager documentation. */ - virtual Common::TimerManager *getTimerManager() = 0; + inline Common::TimerManager *getTimerManager() { + return _timerManager; + } /** * Return the event manager singleton. For more information, refer @@ -1007,14 +1042,16 @@ class OSystem : Common::NonCopyable { * and other modifiable persistent game data. For more information, * refer to the SaveFileManager documentation. */ - virtual Common::SaveFileManager *getSavefileManager() = 0; + inline Common::SaveFileManager *getSavefileManager() { + return _savefileManager; + } /** * 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.