diff options
-rw-r--r-- | base/engine.cpp | 7 | ||||
-rw-r--r-- | base/engine.h | 6 | ||||
-rw-r--r-- | base/main.cpp | 5 | ||||
-rw-r--r-- | queen/queen.cpp | 2 | ||||
-rw-r--r-- | queen/queen.h | 1 | ||||
-rw-r--r-- | scumm/scumm.cpp | 4 | ||||
-rw-r--r-- | sky/sky.cpp | 2 |
7 files changed, 22 insertions, 5 deletions
diff --git a/base/engine.cpp b/base/engine.cpp index d508ef35f3..4ef1bb4b31 100644 --- a/base/engine.cpp +++ b/base/engine.cpp @@ -46,6 +46,8 @@ Engine::Engine(OSystem *syst) Common::File::addDefaultDirectory(_gameDataPath); _saveFileMan = _system->getSavefileManager(); + + _autosavePeriod = ConfMan.getInt("autosave_period"); } Engine::~Engine() { @@ -136,6 +138,11 @@ void Engine::checkCD() { #endif } +bool Engine::shouldPerformAutoSave(int lastSaveTime) { + const int diff = _system->getMillis() - lastSaveTime; + return _autosavePeriod != 0 && diff > _autosavePeriod * 1000; +} + const char *Engine::getGameDataPath() const { return _gameDataPath.c_str(); } diff --git a/base/engine.h b/base/engine.h index 474c0c3783..5dafb272bc 100644 --- a/base/engine.h +++ b/base/engine.h @@ -44,6 +44,9 @@ protected: const Common::String _gameDataPath; Common::SaveFileManager *_saveFileMan; +private: + int _autosavePeriod; + public: Engine(OSystem *syst); virtual ~Engine(); @@ -72,6 +75,9 @@ public: /** On some systems, check if the game appears to be run from CD. */ void checkCD(); + + /* Indicate if an autosave should be performed */ + bool shouldPerformAutoSave(int lastSaveTime); }; extern Engine *g_engine; diff --git a/base/main.cpp b/base/main.cpp index 0ec3b1fdb4..b09fd3acbb 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -402,6 +402,11 @@ extern "C" int main(int argc, char *argv[]) { // Update the config file ConfMan.set("versioninfo", gScummVMVersion, Common::ConfigManager::kApplicationDomain); + if (!ConfMan.hasKey("autosave_period")) { + // By default, trigger autosave every 5 minutes + ConfMan.set("autosave_period", 5 * 60, Common::ConfigManager::kApplicationDomain); + } + // Load the plugins PluginManager::instance().loadPlugins(); diff --git a/queen/queen.cpp b/queen/queen.cpp index dc9f163c9a..11bb1df1ae 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -231,7 +231,7 @@ void QueenEngine::update(bool checkPlayerInput) { _input->quickLoadReset(); loadGameState(0); } - if (_system->getMillis() - _lastSaveTime >= AUTOSAVE_INTERVAL) { + if (shouldPerformAutoSave(_lastSaveTime)) { saveGameState(AUTOSAVE_SLOT, "Autosave"); _lastSaveTime = _system->getMillis(); } diff --git a/queen/queen.h b/queen/queen.h index e8ab8716d9..e88a7170bf 100644 --- a/queen/queen.h +++ b/queen/queen.h @@ -123,7 +123,6 @@ public: SAVESTATE_MAX_NUM = 100, SAVESTATE_MAX_SIZE = 30000, - AUTOSAVE_INTERVAL = 5 * 60 * 1000, AUTOSAVE_SLOT = 0xFF, MIN_TEXT_SPEED = 4, diff --git a/scumm/scumm.cpp b/scumm/scumm.cpp index 20e5b7b5dc..1e60334657 100644 --- a/scumm/scumm.cpp +++ b/scumm/scumm.cpp @@ -2359,8 +2359,8 @@ int ScummEngine::scummLoop(int delta) { } } - // Trigger autosave all 5 minutes. - if (!_saveLoadFlag && _system->getMillis() > _lastSaveTime + 5 * 60 * 1000) { + // Trigger autosave if necessary. + if (!_saveLoadFlag && shouldPerformAutoSave(_lastSaveTime)) { _saveLoadSlot = 0; sprintf(_saveLoadName, "Autosave %d", _saveLoadSlot); _saveLoadFlag = 1; diff --git a/sky/sky.cpp b/sky/sky.cpp index c31abb42ac..6cba9981af 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -240,7 +240,7 @@ int SkyEngine::go() { int32 frameTime = (int32)_system->getMillis(); - if (_system->getMillis() - _lastSaveTime > 5 * 60 * 1000) { + if (shouldPerformAutoSave(_lastSaveTime)) { if (_skyControl->loadSaveAllowed()) { _lastSaveTime = _system->getMillis(); _skyControl->doAutoSave(); |