Skip to content

Commit bb8cb41

Browse files
AlexKnauthCryZe
andauthored
Fix resume_game_time to not jump to real time (#822)
This fixes the game time to not jump back to the real time when you resume it after having paused it. Co-authored-by: Christopher Serr <[email protected]>
1 parent ccc781e commit bb8cb41

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/timing/timer/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,12 @@ impl Timer {
707707
pub fn resume_game_time(&mut self) -> Result {
708708
let active_attempt = self.active_attempt.as_mut().ok_or(Error::NoRunInProgress)?;
709709

710-
if active_attempt.game_time_paused_at.take().is_some() {
710+
if active_attempt.game_time_paused_at.is_some() {
711711
let current_time = active_attempt.current_time(&self.run);
712712

713713
let diff = catch! { current_time.real_time - current_time.game_time? };
714714
active_attempt.set_loading_times(diff.unwrap_or_default(), &self.run);
715+
active_attempt.game_time_paused_at = None;
715716

716717
Ok(Event::GameTimeResumed)
717718
} else {

src/timing/timer/tests/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,19 @@ fn skipping_keeps_timer_paused() {
673673
assert_eq!(timer.current_phase(), TimerPhase::Paused);
674674
assert_eq!(timer.current_split_index(), Some(0));
675675
}
676+
677+
#[test]
678+
fn paused_then_resumed_game_time_lags_behind_real_time() {
679+
let mut timer = timer();
680+
681+
timer.start().unwrap();
682+
timer.pause_game_time().unwrap();
683+
timer.resume_game_time().unwrap();
684+
685+
let time = timer
686+
.active_attempt
687+
.as_ref()
688+
.unwrap()
689+
.current_time(timer.run());
690+
assert!(time.game_time.unwrap() < time.real_time);
691+
}

0 commit comments

Comments
 (0)