adjust playback speed with arrow keys

This commit is contained in:
2026-02-20 10:40:21 -08:00
parent 8a55fbffd9
commit 2ffce9d9ca
4 changed files with 18 additions and 2 deletions

View File

@@ -64,6 +64,9 @@ impl PlaybackHead{
state.set_offset(offset); state.set_offset(offset);
self.timer=Timer::from_state(state,paused); 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){ pub fn advance_time(&mut self,bot:&CompleteBot,time:SessionTime){
let mut simulation_time=self.time(bot,time); let mut simulation_time=self.time(bot,time);
let mut time_float=simulation_time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64; let mut time_float=simulation_time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64;

View File

@@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
pollster = "0.4.0" ratio_from_float = { version = "0.1.0", path = "../ratio_from_float" }
strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" } strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" }
pollster = "0.4.0"
wgpu = "28.0.0" wgpu = "28.0.0"
winit = "0.30.12" winit = "0.30.12"
strafesnet_common.workspace = true strafesnet_common.workspace = true

View File

@@ -23,6 +23,7 @@ pub struct PlayerWorker<'a>{
graphics_thread:Graphics, graphics_thread:Graphics,
bot:Option<CompleteBot>, bot:Option<CompleteBot>,
playback_head:PlaybackHead, playback_head:PlaybackHead,
playback_speed:i8,
} }
impl<'a> PlayerWorker<'a>{ impl<'a> PlayerWorker<'a>{
pub fn new( pub fn new(
@@ -35,6 +36,7 @@ impl<'a> PlayerWorker<'a>{
graphics_thread, graphics_thread,
bot:None, bot:None,
playback_head, playback_head,
playback_speed:0,
} }
} }
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){ pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
@@ -48,7 +50,16 @@ impl<'a> PlayerWorker<'a>{
Instruction::SessionControl(SessionControlInstruction::SkipBack)=>{ Instruction::SessionControl(SessionControlInstruction::SkipBack)=>{
self.playback_head.seek_backward(SessionTime::from_secs(5)); 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(-48);
let speed=2.0f64.powf(self.playback_speed as f64/3.0);
self.playback_head.set_scale(ins.time,ratio_from_float::ratio_from_f64(speed).unwrap());
},
Instruction::SessionControl(SessionControlInstruction::IncreaseTimescale)=>{
self.playback_speed=self.playback_speed.saturating_add(1).min(48);
let speed=2.0f64.powf(self.playback_speed as f64/3.0);
self.playback_head.set_scale(ins.time,ratio_from_float::ratio_from_f64(speed).unwrap());
},
Instruction::Render=>if let Some(bot)=&self.bot{ Instruction::Render=>if let Some(bot)=&self.bot{
self.playback_head.advance_time(bot,ins.time); self.playback_head.advance_time(bot,ins.time);
let (pos,angles)=self.playback_head.get_position_angles(bot,ins.time); let (pos,angles)=self.playback_head.get_position_angles(bot,ins.time);

View File

@@ -7,6 +7,7 @@ edition = "2024"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
ratio_from_float = { version = "0.1.0", path = "../ratio_from_float" }
strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" } strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" }
strafesnet_common.workspace = true strafesnet_common.workspace = true
strafesnet_graphics.workspace = true strafesnet_graphics.workspace = true