forked from StrafesNET/strafe-project
maintain replay state according to real time
This commit is contained in:
parent
d2002383cb
commit
713b235816
@ -106,6 +106,26 @@ impl Replay{
|
|||||||
simulation,
|
simulation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn advance(&mut self,time_limit:SessionTime){
|
||||||
|
let mut time=self.simulation.timer.time(time_limit);
|
||||||
|
loop{
|
||||||
|
if let Some(ins)=self.recording.instructions.get(self.last_instruction_id){
|
||||||
|
if ins.time<time{
|
||||||
|
self.simulation.physics.run_input_instruction(ins.clone());
|
||||||
|
self.last_instruction_id+=1;
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// loop playback
|
||||||
|
self.last_instruction_id=0;
|
||||||
|
// No need to reset physics because the very first instruction is 'Reset'
|
||||||
|
let new_time=self.recording.instructions.first().map_or(PhysicsTime::ZERO,|ins|ins.time);
|
||||||
|
self.simulation.timer.set_time(time_limit,new_time);
|
||||||
|
time=new_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Hash,PartialEq,Eq)]
|
#[derive(Clone,Copy,Hash,PartialEq,Eq)]
|
||||||
@ -229,7 +249,8 @@ impl InstructionConsumer<Instruction<'_>> for Session{
|
|||||||
recording.instructions.extend(self.recording.instructions.iter().cloned());
|
recording.instructions.extend(self.recording.instructions.iter().cloned());
|
||||||
|
|
||||||
// create timer starting at first instruction (or zero if the list is empty)
|
// create timer starting at first instruction (or zero if the list is empty)
|
||||||
let timer=Timer::unpaused(ins.time,recording.instructions.first().map_or(PhysicsTime::ZERO,|ins|ins.time));
|
let new_time=recording.instructions.first().map_or(PhysicsTime::ZERO,|ins|ins.time);
|
||||||
|
let timer=Timer::unpaused(ins.time,new_time);
|
||||||
|
|
||||||
// create default physics state
|
// create default physics state
|
||||||
let simulation=Simulation::new(timer,Default::default());
|
let simulation=Simulation::new(timer,Default::default());
|
||||||
@ -261,6 +282,10 @@ impl InstructionConsumer<Instruction<'_>> for Session{
|
|||||||
},
|
},
|
||||||
Instruction::Idle=>{
|
Instruction::Idle=>{
|
||||||
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Idle);
|
run_mouse_interpolator_instruction!(MouseInterpolatorInstruction::Idle);
|
||||||
|
// this just refreshes the replays
|
||||||
|
for replay in self.replays.values_mut(){
|
||||||
|
replay.advance(ins.time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user