implement pause and seek

This commit is contained in:
2026-02-20 10:15:11 -08:00
parent 98f56d0608
commit 8ecb79a0b4
2 changed files with 27 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
use glam::Vec3Swizzles;
use strafesnet_common::timer::{Timer,Scaled};
use strafesnet_common::timer::{Scaled,Timer,TimerState};
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
use strafesnet_common::physics::{Time as PhysicsTime,TimeInner as PhysicsTimeInner};
use strafesnet_roblox_bot_file::v0::{EventType,Head,Timed};
@@ -47,6 +47,23 @@ impl PlaybackHead{
self.state.process_event(bot,event_type,self.head.get_event_index(event_type));
self.head.push(event_type);
}
pub fn set_paused(&mut self,time:SessionTime,paused:bool){
_=self.timer.set_paused(time,paused);
}
pub fn seek_backward(&mut self,time:SessionTime){
let (mut state,paused)=self.timer.clone().into_state();
let offset=state.get_offset()-time.coerce();
state.set_offset(offset);
self.timer=Timer::from_state(state,paused);
// reset head
self.head=HEAD_NO_CRASH;
}
pub fn seek_forward(&mut self,time:SessionTime){
let (mut state,paused)=self.timer.clone().into_state();
let offset=state.get_offset()+time.coerce();
state.set_offset(offset);
self.timer=Timer::from_state(state,paused);
}
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

@@ -39,6 +39,15 @@ impl<'a> PlayerWorker<'a>{
}
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
match ins.instruction{
Instruction::SessionControl(SessionControlInstruction::SetPaused(paused))=>{
self.playback_head.set_paused(ins.time,paused);
},
Instruction::SessionControl(SessionControlInstruction::SkipForward)=>{
self.playback_head.seek_forward(SessionTime::from_secs(5));
},
Instruction::SessionControl(SessionControlInstruction::SkipBack)=>{
self.playback_head.seek_backward(SessionTime::from_secs(5));
},
Instruction::SessionControl(session_control_instruction)=>{},
Instruction::Render=>if let Some(bot)=&self.bot{
self.playback_head.advance_time(bot,ins.time);