XEEN: Implement autosave support

This commit is contained in:
Paul Gilbert 2019-08-18 15:18:48 -07:00
parent 1f38a8239f
commit 73a4f228f6
6 changed files with 47 additions and 8 deletions

@ -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) {

@ -63,6 +63,7 @@ private:
uint32 _frameCounter;
uint32 _priorFrameCounterTime;
uint32 _priorScreenRefreshTime;
int _lastAutosaveTime;
uint32 _gameCounter;
uint32 _gameCounters[6];
uint32 _playTime;

@ -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

@ -32,6 +32,10 @@
namespace Xeen {
enum {
kAutoSaveSlot = 0
};
struct XeenSavegameHeader {
uint8 _version;
Common::String _saveName;
@ -82,6 +86,11 @@ public:
*/
Common::Error saveGameState(int slot, const Common::String &desc);
/**
* Does an autosave
*/
void doAutosave();
/**
* Sets up a new game
*/

@ -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

@ -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;