From e5b9559f92af51e40e744bf1884eae441a5628b1 Mon Sep 17 00:00:00 2001 From: morfidon <57798071+morfidon@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:35:18 +0100 Subject: [PATCH] Track autosave enabled state and reset timer on toggle --- Source/diablo.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 3f0c594cb..7ec96fdce 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -182,6 +182,7 @@ AutoSaveReason pendingAutoSaveReason = AutoSaveReason::None; bool hasEnteredActiveGameplay = false; uint32_t autoSaveCooldownUntil = 0; uint32_t autoSaveCombatCooldownUntil = 0; +bool wasAutoSaveEnabled = false; constexpr uint32_t AutoSaveCooldownMilliseconds = 5000; constexpr uint32_t AutoSaveCombatCooldownMilliseconds = 4000; constexpr int AutoSaveEnemyProximityTiles = 6; @@ -250,6 +251,7 @@ void StartGame(interface_mode uMsg) autoSaveCombatCooldownUntil = 0; pendingAutoSaveReason = AutoSaveReason::None; autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds(); + wasAutoSaveEnabled = *GetOptions().Gameplay.autoSaveEnabled; } void FreeGame() @@ -1612,14 +1614,20 @@ void GameLogic() if (!hasEnteredActiveGameplay && LastPlayerAction != PlayerActionType::None) hasEnteredActiveGameplay = true; - if (*GetOptions().Gameplay.autoSaveEnabled) { + const bool autoSaveEnabled = *GetOptions().Gameplay.autoSaveEnabled; + if (autoSaveEnabled != wasAutoSaveEnabled) { + if (!autoSaveEnabled) + pendingAutoSaveReason = AutoSaveReason::None; + + autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds(); + wasAutoSaveEnabled = autoSaveEnabled; + } + + if (autoSaveEnabled) { const uint32_t now = SDL_GetTicks(); if (SDL_TICKS_PASSED(now, autoSaveNextTimerDueAt)) { QueueAutoSave(AutoSaveReason::Timer); } - } else { - autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds(); - pendingAutoSaveReason = AutoSaveReason::None; } if (HasPendingAutoSave() && IsAutoSaveSafe()) {