ENGINES: Implement autosaving in the Engine base class

This commit is contained in:
Paul Gilbert 2020-02-04 22:25:13 -08:00 committed by Paul Gilbert
parent a00e44ba6c
commit 30d34fa63d
3 changed files with 41 additions and 10 deletions

View file

@ -148,7 +148,9 @@ Engine::Engine(OSystem *syst)
_saveSlotToLoad(-1),
_engineStartTime(_system->getMillis()),
_mainMenuDialog(NULL),
_debugger(NULL) {
_debugger(NULL),
_autosaveInterval(ConfMan.getInt("autosave_period")),
_lastAutosaveTime(_system->getMillis()) {
g_engine = this;
Common::setErrorOutputFormatter(defaultOutputFormatter);
@ -482,10 +484,16 @@ void Engine::checkCD() {
#endif
}
bool Engine::shouldPerformAutoSave(int lastSaveTime) {
const int diff = _system->getMillis() - lastSaveTime;
const int autosavePeriod = ConfMan.getInt("autosave_period");
return autosavePeriod != 0 && diff > autosavePeriod * 1000;
void Engine::handleAutoSave() {
const int diff = _system->getMillis() - _lastAutosaveTime;
if (_autosaveInterval != 0 && diff > (_autosaveInterval * 1000)) {
// Save the autosave
saveGameState(getAutosaveSlot(), _("Autosave"), true);
// Reset the last autosave time
_lastAutosaveTime = _system->getMillis();
}
}
void Engine::errorString(const char *buf1, char *buf2, int size) {