From 246e8a2c0a92076c9fad4d39f0233563c94728c7 Mon Sep 17 00:00:00 2001 From: Sour Date: Thu, 14 Nov 2019 21:26:22 -0500 Subject: [PATCH] Save states: Make auto save states ignore time when the game is paused --- Core/AutoSaveManager.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Core/AutoSaveManager.cpp b/Core/AutoSaveManager.cpp index d3934c43..85973e0f 100644 --- a/Core/AutoSaveManager.cpp +++ b/Core/AutoSaveManager.cpp @@ -9,18 +9,27 @@ AutoSaveManager::AutoSaveManager(shared_ptr console) _stopThread = false; _timer.Reset(); _autoSaveThread = std::thread([=]() { + bool showMessage = false; + double targetTime = (double)console->GetSettings()->GetAutoSaveDelay(showMessage) * 60 * 1000; while(!_stopThread) { - bool showMessage = false; uint32_t autoSaveDelay = console->GetSettings()->GetAutoSaveDelay(showMessage) * 60 * 1000; if(autoSaveDelay > 0) { - if(_timer.GetElapsedMS() > autoSaveDelay) { - if(!console->IsDebuggerAttached()) { - console->GetSaveStateManager()->SaveState(_autoSaveSlot, showMessage); + if(targetTime >= 0 && !console->IsExecutionStopped()) { + targetTime -= _timer.GetElapsedMS(); + _timer.Reset(); + if(targetTime <= 0) { + if(!console->IsDebuggerAttached()) { + console->GetSaveStateManager()->SaveState(_autoSaveSlot, showMessage); + } + targetTime = (double)console->GetSettings()->GetAutoSaveDelay(showMessage) * 60 * 1000; + _timer.Reset(); } + } else { _timer.Reset(); } } else { _timer.Reset(); + targetTime = autoSaveDelay; } if(!_stopThread) {