fix pre-pause time leak

This commit is contained in:
Quaternions 2024-08-02 10:35:05 -07:00
parent 500db0a5b9
commit cc6450975c

View File

@ -29,7 +29,7 @@ pub enum Instruction{
} }
pub struct MouseInterpolator{ pub struct MouseInterpolator{
timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>, timeline:std::collections::VecDeque<TimedInstruction<PhysicsInputInstruction>>,
last_mouse_time:Time, last_mouse_time:Time,//this value is pre-transformed to simulation time
mouse_blocking:bool, mouse_blocking:bool,
timer:Timer<Scaled>, timer:Timer<Scaled>,
} }
@ -38,23 +38,23 @@ impl MouseInterpolator{
if self.mouse_blocking{ if self.mouse_blocking{
//tell the game state which is living in the past about its future //tell the game state which is living in the past about its future
self.timeline.push_front(TimedInstruction{ self.timeline.push_front(TimedInstruction{
time:self.timer.time(self.last_mouse_time), time:self.last_mouse_time,
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:m}), instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:m}),
}); });
}else{ }else{
//mouse has just started moving again after being still for longer than 10ms. //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 //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{ self.timeline.push_front(TimedInstruction{
time:self.timer.time(self.last_mouse_time), time:self.last_mouse_time,
instruction:PhysicsInputInstruction::ReplaceMouse( instruction:PhysicsInputInstruction::ReplaceMouse(
MouseState{time:self.timer.time(self.last_mouse_time),pos:physics.get_next_mouse().pos}, MouseState{time:self.last_mouse_time,pos:physics.get_next_mouse().pos},
MouseState{time:self.timer.time(ins.time),pos:m} MouseState{time:self.timer.time(ins.time),pos:m}
), ),
}); });
//delay physics execution until we have an interpolation target //delay physics execution until we have an interpolation target
self.mouse_blocking=true; self.mouse_blocking=true;
} }
self.last_mouse_time=ins.time; self.last_mouse_time=self.timer.time(ins.time);
} }
/// returns the mapped physics input instruction /// returns the mapped physics input instruction
/// may or may not mutate internal state XD! /// may or may not mutate internal state XD!
@ -102,10 +102,10 @@ impl MouseInterpolator{
if Time::from_millis(10)<self.timer.time(ins.time)-physics.get_next_mouse().time{ if Time::from_millis(10)<self.timer.time(ins.time)-physics.get_next_mouse().time{
//push an event to extrapolate no movement from //push an event to extrapolate no movement from
self.timeline.push_front(TimedInstruction{ self.timeline.push_front(TimedInstruction{
time:self.timer.time(self.last_mouse_time), time:self.last_mouse_time,
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:physics.get_next_mouse().pos}), instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:self.timer.time(ins.time),pos:physics.get_next_mouse().pos}),
}); });
self.last_mouse_time=ins.time; self.last_mouse_time=self.timer.time(ins.time);
//stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets. //stop blocking. the mouse is not moving so the physics does not need to live in the past and wait for interpolation targets.
self.mouse_blocking=false; self.mouse_blocking=false;
true true
@ -115,7 +115,7 @@ impl MouseInterpolator{
}else{ }else{
//keep this up to date so that it can be used as a known-timestamp //keep this up to date so that it can be used as a known-timestamp
//that the mouse was Timer<Scaled>not moving when the mouse starts moving again //that the mouse was Timer<Scaled>not moving when the mouse starts moving again
self.last_mouse_time=ins.time; self.last_mouse_time=self.timer.time(ins.time);
true true
} }
} }