From 8ecb79a0b4026373ed30d155ab1a1e949d303b50 Mon Sep 17 00:00:00 2001 From: Rhys Lloyd Date: Fri, 20 Feb 2026 10:15:11 -0800 Subject: [PATCH] implement pause and seek --- lib/src/head.rs | 19 ++++++++++++++++++- native-player/src/player.rs | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/src/head.rs b/lib/src/head.rs index f955a48..d339eb1 100644 --- a/lib/src/head.rs +++ b/lib/src/head.rs @@ -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; diff --git a/native-player/src/player.rs b/native-player/src/player.rs index ec99fed..3e82016 100644 --- a/native-player/src/player.rs +++ b/native-player/src/player.rs @@ -39,6 +39,15 @@ impl<'a> PlayerWorker<'a>{ } pub fn send(&mut self,ins:TimedInstruction){ 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);