Fix bug where restart fast-forwarded the new run by the time spent in a modal dialog

This commit is contained in:
2026-07-19 21:19:36 +02:00
parent d412c69f82
commit a4267a4760
2 changed files with 35 additions and 0 deletions

View File

@@ -227,6 +227,12 @@ void GameWorldView::onFrame()
{
m_viewResetPending = false;
resetForNewGame();
// The reset command may have drained after a long-open modal (e.g. the
// Game Over dialog), so `elapsed` above still holds the whole time that
// dialog was open. Feeding it into the tick driver would fast-forward the
// brand-new run by that duration. resetForNewGame() has rebased the time
// source; skip this frame's tick advance so the stale delta is discarded.
return;
}
// Notify presentation widgets that queued commands were applied, so a
@@ -2391,6 +2397,12 @@ void GameWorldView::resetForNewGame()
EventManager::getInstance()->sendEventImmediately(
std::make_shared<SelectionChangedEvent>(std::vector<BuildingId>{}));
setGameSpeed(1.0);
// Rebase the wall-clock time source so a fresh run starts from a clean time
// base. Without this, wall time accumulated while a modal (Game Over, Win, or
// the escape menu) was open would be converted into ticks on the new run,
// fast-forwarding it by the time the player spent in the dialog.
m_frameTimer.restart();
m_tickDriver.reset();
update();
}