implement looping

This commit is contained in:
Quaternions 2025-01-03 20:09:05 -08:00
parent d04a5e4625
commit 89d51c60f4

View File

@ -225,6 +225,7 @@ struct PlayBacker{
//"Simulation" //"Simulation"
event_id:usize, event_id:usize,
offset:f64, offset:f64,
duration:f64,
timer:Timer<Scaled>, timer:Timer<Scaled>,
physics:crate::physics::PhysicsContext, physics:crate::physics::PhysicsContext,
} }
@ -233,8 +234,11 @@ impl PlayBacker{
physics:crate::physics::PhysicsContext, physics:crate::physics::PhysicsContext,
timelines:strafesnet_roblox_bot_file::v0::Block, timelines:strafesnet_roblox_bot_file::v0::Block,
)->Self{ )->Self{
let first=timelines.output_events.first().unwrap();
let last=timelines.output_events.last().unwrap();
Self{ Self{
offset:timelines.output_events[0].time, offset:first.time,
duration:last.time-first.time,
timelines, timelines,
event_id:0, event_id:0,
timer:Timer::from_state(Scaled::identity(),false), timer:Timer::from_state(Scaled::identity(),false),
@ -250,15 +254,23 @@ impl PlayBacker{
_=>(), _=>(),
} }
let simulation_time=self.timer.time(*time); let simulation_time=self.timer.time(*time);
let time_float=simulation_time.get() as f64/Time::ONE_SECOND.get() as f64+self.offset; let mut 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){ loop{
//println!("{}<{}",next_event.time,time_float); match self.timelines.output_events.get(self.event_id+1){
Some(next_event)=>{
if next_event.time<time_float{ if next_event.time<time_float{
self.event_id+=1; self.event_id+=1;
println!("event_id={}",self.event_id);
}else{ }else{
break; break;
} }
},
None=>{
//reset playback
self.event_id=0;
self.offset-=self.duration;
time_float-=self.duration;
},
}
} }
} }
pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{ pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{