From a2a8229abef229e631f5be0d9f68c6394fbe859e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Feb 2020 08:01:10 -0800 Subject: [PATCH] ENGINES: Do an autosave before loading a new game Unfortunately, this will only apply to new engines that use the Engine::loadGameState method. Other existing engines call loadGameState directly and provide their own implementations, so there's nowhere convenient to add the call that'd work for all of them --- engines/engine.cpp | 17 ++++++++++++----- engines/engine.h | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/engines/engine.cpp b/engines/engine.cpp index 56f84e327d2..377bed4e5ce 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -489,14 +489,18 @@ void Engine::handleAutoSave() { if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) { // Save the autosave - if (canSaveAutosaveCurrently()) - saveGameState(getAutosaveSlot(), _("Autosave"), true); - - // Reset the last autosave time - _lastAutosaveTime = _system->getMillis(); + saveAutosaveIfEnabled(); } } +void Engine::saveAutosaveIfEnabled() { + if (_autosaveInterval != 0 && canSaveAutosaveCurrently()) + saveGameState(getAutosaveSlot(), _("Autosave"), true); + + // Reset the last autosave time + _lastAutosaveTime = _system->getMillis(); +} + void Engine::errorString(const char *buf1, char *buf2, int size) { Common::strlcpy(buf2, buf1, size); } @@ -645,6 +649,9 @@ void Engine::flipMute() { } Common::Error Engine::loadGameState(int slot) { + // In case autosaves are on, do a save first before loading the new save + saveAutosaveIfEnabled(); + Common::InSaveFile *saveFile = _saveFileMan->openForLoading(getSaveStateName(slot)); if (!saveFile) diff --git a/engines/engine.h b/engines/engine.h index 49fddb2661c..56bb6b43999 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -385,6 +385,11 @@ public: */ void handleAutoSave(); + /** + * Does an autosave immediately if autosaves are turned on + */ + void saveAutosaveIfEnabled(); + /** * Indicates whether an autosave can currently be saved. */