From c31bad8a065d252225afa48f8083451933a65f1d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 3 Jan 2025 20:09:05 -0800 Subject: [PATCH] implement looping --- strafe-client/src/physics_worker.rs | 30 ++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/strafe-client/src/physics_worker.rs b/strafe-client/src/physics_worker.rs index 202516d..64f3c79 100644 --- a/strafe-client/src/physics_worker.rs +++ b/strafe-client/src/physics_worker.rs @@ -225,6 +225,7 @@ struct PlayBacker{ //"Simulation" event_id:usize, offset:f64, + duration:f64, timer:Timer, physics:crate::physics::PhysicsContext, } @@ -233,8 +234,11 @@ impl PlayBacker{ physics:crate::physics::PhysicsContext, timelines:strafesnet_roblox_bot_file::v0::Block, )->Self{ + let first=timelines.output_events.first().unwrap(); + let last=timelines.output_events.last().unwrap(); Self{ - offset:timelines.output_events[0].time, + offset:first.time, + duration:last.time-first.time, timelines, event_id:0, timer:Timer::from_state(Scaled::identity(),false), @@ -250,14 +254,22 @@ impl PlayBacker{ _=>(), } let simulation_time=self.timer.time(*time); - let time_float=simulation_time.get() as f64/Time::ONE_SECOND.get() as f64+self.offset; - while let Some(next_event)=self.timelines.output_events.get(self.event_id+1){ - //println!("{}<{}",next_event.time,time_float); - if next_event.time{ + if next_event.time{ + //reset playback + self.event_id=0; + self.offset-=self.duration; + time_float-=self.duration; + }, } } }