pre-transform timestamps

This commit is contained in:
Quaternions 2024-08-02 10:28:19 -07:00
parent 2d8f677501
commit 971e83e392

View File

@ -38,16 +38,16 @@ impl MouseInterpolator{
if self.mouse_blocking{
//tell the game state which is living in the past about its future
self.timeline.push_front(TimedInstruction{
time:self.last_mouse_time,
time:self.timer.time(self.last_mouse_time),
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:m}),
});
}else{
//mouse has just started moving again after being still for longer than 10ms.
//replace the entire mouse interpolation state to avoid an intermediate state with identical m0.t m1.t timestamps which will divide by zero
self.timeline.push_front(TimedInstruction{
time:self.last_mouse_time,
time:self.timer.time(self.last_mouse_time),
instruction:PhysicsInputInstruction::ReplaceMouse(
MouseState{time:self.last_mouse_time,pos:physics.get_next_mouse().pos},
MouseState{time:self.timer.time(self.last_mouse_time),pos:physics.get_next_mouse().pos},
MouseState{time:self.timer.time(ins.time),pos:m}
),
});
@ -102,7 +102,7 @@ impl MouseInterpolator{
if Time::from_millis(10)<self.timer.time(ins.time)-physics.get_next_mouse().time{
//push an event to extrapolate no movement from
self.timeline.push_front(TimedInstruction{
time:self.last_mouse_time,
time:self.timer.time(self.last_mouse_time),
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:physics.get_next_mouse().pos}),
});
self.last_mouse_time=ins.time;
@ -124,7 +124,7 @@ impl MouseInterpolator{
if let Some(phys_input)=phys_input_option{
//non-mouse event
self.timeline.push_back(TimedInstruction{
time:ins.time,
time:self.timer.time(ins.time),
instruction:phys_input,
});
@ -136,11 +136,8 @@ impl MouseInterpolator{
}
}
fn empty_queue(&mut self,physics:&mut crate::physics::PhysicsContext){
while let Some(TimedInstruction{time,instruction})=self.timeline.pop_front(){
physics.run_input_instruction(TimedInstruction{
time:self.timer.time(time),
instruction,
});
while let Some(ins)=self.timeline.pop_front(){
physics.run_input_instruction(ins);
}
}
fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:&TimedInstruction<Instruction>){