Fix bug where restart fast-forwarded the new run by the time spent in a modal dialog
This commit is contained in:
@@ -131,3 +131,26 @@ TEST_CASE("TickDriver::reset clears the accumulator", "[simulation]")
|
||||
// Nothing in the accumulator: zero elapsed time should not fire.
|
||||
REQUIRE(driver.advance(0.0, 1.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("TickDriver::reset discards a large pending delta so a restart does not "
|
||||
"fast-forward", "[simulation]")
|
||||
{
|
||||
// Regression guard for the "restart fast-forwards by the time spent in the
|
||||
// Game Over / Win / escape dialog" bug: on restart the frame timer holds the
|
||||
// whole wall-clock duration the modal was open. GameWorldView::resetForNewGame()
|
||||
// now calls TickDriver::reset() to discard that pending delta; without it the
|
||||
// fresh run would burst forward by the dialog duration on its first frame.
|
||||
TickDriver driver;
|
||||
|
||||
// 30 seconds spent in the dialog would otherwise be ~900 ticks at 30 Hz.
|
||||
const double dialogOpenMs = 30000.0;
|
||||
driver.reset();
|
||||
|
||||
// A brand-new run's first normal frame (~16 ms) advances only its own ticks;
|
||||
// the discarded dialog time contributes nothing.
|
||||
REQUIRE(driver.advance(16.0, 1.0) == 0);
|
||||
|
||||
// Sanity: had the dialog delta not been discarded, it would have fired ~900 ticks.
|
||||
TickDriver leaked;
|
||||
REQUIRE(leaked.advance(dialogOpenMs, 1.0) > 800);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user