diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-05 03:28:56 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-05 03:28:56 -0500 |
commit | 8fae72f67707924118f965b9e14b5838e41cc3ad (patch) | |
tree | e0f547da9e2a249d672d0ed3ec5fc4ce4f6cde7f /src/bin/ttyplay/timer.rs | |
parent | 84860b34b93047821584ca21824cd0fb5f9b3f24 (diff) | |
download | ttyrec-bin-8fae72f67707924118f965b9e14b5838e41cc3ad.tar.gz ttyrec-bin-8fae72f67707924118f965b9e14b5838e41cc3ad.zip |
implement speeding up and slowing down
Diffstat (limited to 'src/bin/ttyplay/timer.rs')
-rw-r--r-- | src/bin/ttyplay/timer.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/bin/ttyplay/timer.rs b/src/bin/ttyplay/timer.rs index 7be5245..db85001 100644 --- a/src/bin/ttyplay/timer.rs +++ b/src/bin/ttyplay/timer.rs @@ -17,6 +17,7 @@ pub fn spawn_task( None }; let mut force_update_time = false; + let mut playback_ratio = 16; loop { enum Res { Wait(Option<vt100::Screen>), @@ -34,7 +35,7 @@ pub fn spawn_task( frames.lock_arc().await.get(idx).unwrap().clone(); if force_update_time { let now = std::time::Instant::now(); - start_time = now - frame.delay() + start_time = now - frame.delay() * playback_ratio / 16 // give a bit of extra time before moving to the // next frame, otherwise backing up behind two // frames that are extremely close together @@ -48,7 +49,8 @@ pub fn spawn_task( std::future::pending::<()>().await; } else { async_std::task::sleep( - (start_time + frame.delay()) + (start_time + + frame.delay() * playback_ratio / 16) .saturating_duration_since( std::time::Instant::now(), ), @@ -111,6 +113,20 @@ pub fn spawn_task( idx = idx.saturating_sub(2); force_update_time = true; } + crate::event::TimerAction::SpeedUp => { + if playback_ratio > 1 { + playback_ratio /= 2; + let now = std::time::Instant::now(); + start_time = now - (now - start_time) / 2; + } + } + crate::event::TimerAction::SlowDown => { + if playback_ratio < 256 { + playback_ratio *= 2; + let now = std::time::Instant::now(); + start_time = now - (now - start_time) * 2; + } + } crate::event::TimerAction::Quit => break, }, Res::TimerAction(Err(e)) => panic!("{}", e), |