diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/xeen/events.cpp | 9 | ||||
-rw-r--r-- | engines/xeen/events.h | 1 | ||||
-rw-r--r-- | engines/xeen/saves.cpp | 7 | ||||
-rw-r--r-- | engines/xeen/saves.h | 9 | ||||
-rw-r--r-- | engines/xeen/xeen.cpp | 14 | ||||
-rw-r--r-- | engines/xeen/xeen.h | 15 |
6 files changed, 47 insertions, 8 deletions
diff --git a/engines/xeen/events.cpp b/engines/xeen/events.cpp index 17306a32fc..5243de630c 100644 --- a/engines/xeen/events.cpp +++ b/engines/xeen/events.cpp @@ -32,7 +32,7 @@ namespace Xeen { EventsManager::EventsManager(XeenEngine *vm) : _vm(vm), _playTime(0), _gameCounter(0), - _frameCounter(0), _priorFrameCounterTime(0), _priorScreenRefreshTime(0), + _frameCounter(0), _priorFrameCounterTime(0), _priorScreenRefreshTime(0), _lastAutosaveTime(0), _mousePressed(false), _sprites("mouse.icn") { Common::fill(&_gameCounters[0], &_gameCounters[6], 0); } @@ -69,12 +69,19 @@ void EventsManager::pollEvents() { _priorScreenRefreshTime = timer; g_vm->_screen->update(); } + if (timer >= (_priorFrameCounterTime + GAME_FRAME_TIME)) { // Time to build up next game frame _priorFrameCounterTime = timer; nextFrame(); } + // Handle auto saves + if (!_lastAutosaveTime) + _lastAutosaveTime = timer; + g_vm->autoSaveCheck(_lastAutosaveTime); + + // Event handling Common::Event event; while (g_system->getEventManager()->pollEvent(event)) { switch (event.type) { diff --git a/engines/xeen/events.h b/engines/xeen/events.h index 9913b2fbf1..768e241567 100644 --- a/engines/xeen/events.h +++ b/engines/xeen/events.h @@ -63,6 +63,7 @@ private: uint32 _frameCounter; uint32 _priorFrameCounterTime; uint32 _priorScreenRefreshTime; + int _lastAutosaveTime; uint32 _gameCounter; uint32 _gameCounters[6]; uint32 _playTime; diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index 82e294921b..6b88a19c8f 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -263,7 +263,7 @@ bool SavesManager::loadGame() { delete dialog; if (slotNum != -1) { - loadGameState(slotNum); + (void)loadGameState(slotNum); g_vm->_interface->drawParty(true); } @@ -291,4 +291,9 @@ bool SavesManager::saveGame() { } } +void SavesManager::doAutosave() { + if (saveGameState(kAutoSaveSlot, _("Autosave")).getCode() != Common::kNoError) + g_vm->GUIError(_("Failed to autosave")); +} + } // End of namespace Xeen diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h index 9b1bea62a3..d3352f187f 100644 --- a/engines/xeen/saves.h +++ b/engines/xeen/saves.h @@ -32,6 +32,10 @@ namespace Xeen { +enum { + kAutoSaveSlot = 0 +}; + struct XeenSavegameHeader { uint8 _version; Common::String _saveName; @@ -83,6 +87,11 @@ public: Common::Error saveGameState(int slot, const Common::String &desc); /** + * Does an autosave + */ + void doAutosave(); + + /** * Sets up a new game */ void newGame(); diff --git a/engines/xeen/xeen.cpp b/engines/xeen/xeen.cpp index 1952dc16c0..5f72623e91 100644 --- a/engines/xeen/xeen.cpp +++ b/engines/xeen/xeen.cpp @@ -266,7 +266,7 @@ void XeenEngine::gameLoop() { // Load any pending savegame int saveSlot = _loadSaveSlot; _loadSaveSlot = -1; - _saves->loadGameState(saveSlot); + (void)_saves->loadGameState(saveSlot); _interface->drawParty(true); } @@ -322,4 +322,16 @@ void XeenEngine::saveSettings() { ConfMan.flushToDisk(); } +void XeenEngine::GUIError(const Common::String &msg) { + GUIErrorMessage(msg); +} + +void XeenEngine::autoSaveCheck(int &lastSaveTime) { + if (shouldPerformAutoSave(lastSaveTime) && canSaveGameStateCurrently() && + (_map && !(_map->mazeData()._mazeFlags & RESTRICTION_SAVE))) { + _saves->doAutosave(); + lastSaveTime = g_system->getMillis(); + } +} + } // End of namespace Xeen diff --git a/engines/xeen/xeen.h b/engines/xeen/xeen.h index dfe2c79eec..2ac4ee4ec6 100644 --- a/engines/xeen/xeen.h +++ b/engines/xeen/xeen.h @@ -149,11 +149,6 @@ private: * Plays the actual game */ void play(); - - /** - * Shows a please wait dialog - */ - void pleaseWait(); protected: int _loadSaveSlot; protected: @@ -275,6 +270,16 @@ public: * Saves engine settings */ void saveSettings(); + + /** + * Show an error message in a GUI dialog + */ + void GUIError(const Common::String &msg); + + /** + * Checks if an auto save should be done, and if so, takes care of it + */ + void autoSaveCheck(int &lastSaveTime); }; extern XeenEngine *g_vm; |