Skip to content

Commit

Permalink
Fix resume_game_time to not jump to real time (#822)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
AlexKnauth and CryZe authored Jun 24, 2024
1 parent ccc781e commit bb8cb41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/timing/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,12 @@ impl Timer {
pub fn resume_game_time(&mut self) -> Result {
let active_attempt = self.active_attempt.as_mut().ok_or(Error::NoRunInProgress)?;

if active_attempt.game_time_paused_at.take().is_some() {
if active_attempt.game_time_paused_at.is_some() {
let current_time = active_attempt.current_time(&self.run);

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

Ok(Event::GameTimeResumed)
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/timing/timer/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,19 @@ fn skipping_keeps_timer_paused() {
assert_eq!(timer.current_phase(), TimerPhase::Paused);
assert_eq!(timer.current_split_index(), Some(0));
}

#[test]
fn paused_then_resumed_game_time_lags_behind_real_time() {
let mut timer = timer();

timer.start().unwrap();
timer.pause_game_time().unwrap();
timer.resume_game_time().unwrap();

let time = timer
.active_attempt
.as_ref()
.unwrap()
.current_time(timer.run());
assert!(time.game_time.unwrap() < time.real_time);
}

0 comments on commit bb8cb41

Please sign in to comment.