implement looping
This commit is contained in:
parent
d04a5e4625
commit
89d51c60f4
@ -225,6 +225,7 @@ struct PlayBacker{
|
||||
//"Simulation"
|
||||
event_id:usize,
|
||||
offset:f64,
|
||||
duration:f64,
|
||||
timer:Timer<Scaled>,
|
||||
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<time_float{
|
||||
self.event_id+=1;
|
||||
println!("event_id={}",self.event_id);
|
||||
}else{
|
||||
break;
|
||||
let mut time_float=simulation_time.get() as f64/Time::ONE_SECOND.get() as f64+self.offset;
|
||||
loop{
|
||||
match self.timelines.output_events.get(self.event_id+1){
|
||||
Some(next_event)=>{
|
||||
if next_event.time<time_float{
|
||||
self.event_id+=1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
},
|
||||
None=>{
|
||||
//reset playback
|
||||
self.event_id=0;
|
||||
self.offset-=self.duration;
|
||||
time_float-=self.duration;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user