adjust playback speed with arrow keys

This commit is contained in:
2026-02-20 10:54:34 -08:00
parent 8ecb79a0b4
commit 57c545efa6
2 changed files with 21 additions and 1 deletions

View File

@@ -64,6 +64,9 @@ impl PlaybackHead{
state.set_offset(offset);
self.timer=Timer::from_state(state,paused);
}
pub fn set_scale(&mut self,time:SessionTime,new_scale:strafesnet_common::integer::Ratio64){
self.timer.set_scale(time,new_scale);
}
pub fn advance_time(&mut self,bot:&CompleteBot,time:SessionTime){
let mut simulation_time=self.time(bot,time);
let mut time_float=simulation_time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64;

View File

@@ -18,11 +18,20 @@ pub enum Instruction{
LoadReplay(strafesnet_roblox_bot_file::v0::Block),
}
fn speed_ratio(speed:i8)->strafesnet_common::integer::Ratio64{
if speed.is_negative(){
strafesnet_common::integer::Ratio64::new(4i64.pow(-speed as u32),5u64.pow(-speed as u32)).unwrap()
}else{
strafesnet_common::integer::Ratio64::new(5i64.pow(speed as u32),4u64.pow(speed as u32)).unwrap()
}
}
pub struct PlayerWorker<'a>{
surface:wgpu::Surface<'a>,
graphics_thread:Graphics,
bot:Option<CompleteBot>,
playback_head:PlaybackHead,
playback_speed:i8,
}
impl<'a> PlayerWorker<'a>{
pub fn new(
@@ -35,6 +44,7 @@ impl<'a> PlayerWorker<'a>{
graphics_thread,
bot:None,
playback_head,
playback_speed:0,
}
}
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
@@ -48,7 +58,14 @@ impl<'a> PlayerWorker<'a>{
Instruction::SessionControl(SessionControlInstruction::SkipBack)=>{
self.playback_head.seek_backward(SessionTime::from_secs(5));
},
Instruction::SessionControl(session_control_instruction)=>{},
Instruction::SessionControl(SessionControlInstruction::DecreaseTimescale)=>{
self.playback_speed=self.playback_speed.saturating_sub(1).max(-27);
self.playback_head.set_scale(ins.time,speed_ratio(self.playback_speed));
},
Instruction::SessionControl(SessionControlInstruction::IncreaseTimescale)=>{
self.playback_speed=self.playback_speed.saturating_add(1).min(27);
self.playback_head.set_scale(ins.time,speed_ratio(self.playback_speed));
},
Instruction::Render=>if let Some(bot)=&self.bot{
self.playback_head.advance_time(bot,ins.time);
let (pos,angles)=self.playback_head.get_position_angles(bot,ins.time);