Browse Source

Track autosave enabled state and reset timer on toggle

pull/8497/head
morfidon 6 days ago
parent
commit
e5b9559f92
  1. 16
      Source/diablo.cpp

16
Source/diablo.cpp

@ -182,6 +182,7 @@ AutoSaveReason pendingAutoSaveReason = AutoSaveReason::None;
bool hasEnteredActiveGameplay = false; bool hasEnteredActiveGameplay = false;
uint32_t autoSaveCooldownUntil = 0; uint32_t autoSaveCooldownUntil = 0;
uint32_t autoSaveCombatCooldownUntil = 0; uint32_t autoSaveCombatCooldownUntil = 0;
bool wasAutoSaveEnabled = false;
constexpr uint32_t AutoSaveCooldownMilliseconds = 5000; constexpr uint32_t AutoSaveCooldownMilliseconds = 5000;
constexpr uint32_t AutoSaveCombatCooldownMilliseconds = 4000; constexpr uint32_t AutoSaveCombatCooldownMilliseconds = 4000;
constexpr int AutoSaveEnemyProximityTiles = 6; constexpr int AutoSaveEnemyProximityTiles = 6;
@ -250,6 +251,7 @@ void StartGame(interface_mode uMsg)
autoSaveCombatCooldownUntil = 0; autoSaveCombatCooldownUntil = 0;
pendingAutoSaveReason = AutoSaveReason::None; pendingAutoSaveReason = AutoSaveReason::None;
autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds(); autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds();
wasAutoSaveEnabled = *GetOptions().Gameplay.autoSaveEnabled;
} }
void FreeGame() void FreeGame()
@ -1612,14 +1614,20 @@ void GameLogic()
if (!hasEnteredActiveGameplay && LastPlayerAction != PlayerActionType::None) if (!hasEnteredActiveGameplay && LastPlayerAction != PlayerActionType::None)
hasEnteredActiveGameplay = true; 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(); const uint32_t now = SDL_GetTicks();
if (SDL_TICKS_PASSED(now, autoSaveNextTimerDueAt)) { if (SDL_TICKS_PASSED(now, autoSaveNextTimerDueAt)) {
QueueAutoSave(AutoSaveReason::Timer); QueueAutoSave(AutoSaveReason::Timer);
} }
} else {
autoSaveNextTimerDueAt = SDL_GetTicks() + GetAutoSaveIntervalMilliseconds();
pendingAutoSaveReason = AutoSaveReason::None;
} }
if (HasPendingAutoSave() && IsAutoSaveSafe()) { if (HasPendingAutoSave() && IsAutoSaveSafe()) {

Loading…
Cancel
Save