mouse_interpolator tweaks

This commit is contained in:
Quaternions 2025-01-15 02:59:34 -08:00
parent 168d6708d1
commit 3413ec8740

View File

@ -86,7 +86,8 @@ impl MouseInterpolator{
} }
} }
} }
fn timeout_mouse(&mut self,time:PhysicsTime){ fn timeout_mouse(&mut self,timeout_time:PhysicsTime){
// the state always changes to unbuffered
let buffer_state=core::mem::replace(&mut self.buffer_state,BufferState::Unbuffered); let buffer_state=core::mem::replace(&mut self.buffer_state,BufferState::Unbuffered);
match buffer_state{ match buffer_state{
BufferState::Unbuffered=>(), BufferState::Unbuffered=>(),
@ -95,23 +96,16 @@ impl MouseInterpolator{
self.push_mouse_and_flush_buffer(TimedInstruction{ self.push_mouse_and_flush_buffer(TimedInstruction{
time:mouse_state.time, time:mouse_state.time,
instruction:MouseInstruction::ReplaceMouse{ instruction:MouseInstruction::ReplaceMouse{
m1:MouseState{pos:mouse_state.pos,time}, m1:MouseState{pos:mouse_state.pos,time:timeout_time},
m0:mouse_state, m0:mouse_state,
}, },
}); });
} }
BufferState::Buffered(_time,mouse_state)=>{ BufferState::Buffered(_time,mouse_state)=>{
// convert to BufferState::Unbuffered // duplicate the currently buffered mouse state but at a later (future, from the physics perspective) time
// use the first instruction which should be a mouse instruction
// to push a ReplaceMouse instruction
// duplicate the current mouse
self.push_mouse_and_flush_buffer(TimedInstruction{ self.push_mouse_and_flush_buffer(TimedInstruction{
// This should be simulation_timer.time(timeout)
// but the timer is not accessible from this scope
// and it's just here to say that the mouse isn't moving anyways.
// I think this is a divide by zero bug, two identical mouse_states will occupy the interpolation state
time:mouse_state.time, time:mouse_state.time,
instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time}), instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:timeout_time}),
}); });
}, },
} }
@ -130,9 +124,13 @@ impl MouseInterpolator{
// push buffered mouse instruction and flush buffer to output // push buffered mouse instruction and flush buffer to output
if self.get_mouse_timedout_at(ins.time).is_some(){ if self.get_mouse_timedout_at(ins.time).is_some(){
// push buffered mouse instruction and flush buffer to output
self.timeout_mouse(ins.instruction.time); self.timeout_mouse(ins.instruction.time);
} }
// replace_with allows the enum variant to safely be replaced from behind a mutable reference
// replace_with allows the enum variant to safely be replaced
// from behind a mutable reference, but a panic in the closure means that
// the entire program terminates rather than completing an unwind.
let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{ let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{
match ins.instruction.instruction{ match ins.instruction.instruction{
Instruction::MoveMouse(pos)=>{ Instruction::MoveMouse(pos)=>{