rename last_instruction_id to next_instruction_id

This commit is contained in:
Quaternions 2025-01-18 01:31:45 -08:00
parent b45b92c627
commit 40ea0e6c7d

View File

@ -99,7 +99,7 @@ impl Recording{
} }
} }
pub struct Replay{ pub struct Replay{
last_instruction_id:usize, next_instruction_id:usize,
recording:Recording, recording:Recording,
simulation:Simulation, simulation:Simulation,
} }
@ -109,7 +109,7 @@ impl Replay{
simulation:Simulation, simulation:Simulation,
)->Self{ )->Self{
Self{ Self{
last_instruction_id:0, next_instruction_id:0,
recording, recording,
simulation, simulation,
} }
@ -117,16 +117,16 @@ impl Replay{
pub fn advance(&mut self,physics_data:&PhysicsData,time_limit:SessionTime){ pub fn advance(&mut self,physics_data:&PhysicsData,time_limit:SessionTime){
let mut time=self.simulation.timer.time(time_limit); let mut time=self.simulation.timer.time(time_limit);
loop{ loop{
if let Some(ins)=self.recording.instructions.get(self.last_instruction_id){ if let Some(ins)=self.recording.instructions.get(self.next_instruction_id){
if ins.time<time{ if ins.time<time{
PhysicsContext::run_input_instruction(&mut self.simulation.physics,physics_data,ins.clone()); PhysicsContext::run_input_instruction(&mut self.simulation.physics,physics_data,ins.clone());
self.last_instruction_id+=1; self.next_instruction_id+=1;
}else{ }else{
break; break;
} }
}else{ }else{
// loop playback // loop playback
self.last_instruction_id=0; self.next_instruction_id=0;
// No need to reset physics because the very first instruction is 'Reset' // 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); let new_time=self.recording.instructions.first().map_or(PhysicsTime::ZERO,|ins|ins.time);
self.simulation.timer.set_time(time_limit,new_time); self.simulation.timer.set_time(time_limit,new_time);
@ -340,7 +340,7 @@ impl InstructionConsumer<Instruction<'_>> for Session{
let time=replay.simulation.timer.time(ins.time+SessionTime::from_secs(5)); let time=replay.simulation.timer.time(ins.time+SessionTime::from_secs(5));
replay.simulation.timer.set_time(ins.time,time); replay.simulation.timer.set_time(ins.time,time);
// resimulate the entire playback lol // resimulate the entire playback lol
replay.last_instruction_id=0; replay.next_instruction_id=0;
}, },
} }
}, },