diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index 8b26fe1..b447990 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -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); match buffer_state{ BufferState::Unbuffered=>(), @@ -95,23 +96,16 @@ impl MouseInterpolator{ self.push_mouse_and_flush_buffer(TimedInstruction{ time:mouse_state.time, instruction:MouseInstruction::ReplaceMouse{ - m1:MouseState{pos:mouse_state.pos,time}, + m1:MouseState{pos:mouse_state.pos,time:timeout_time}, m0:mouse_state, }, }); } BufferState::Buffered(_time,mouse_state)=>{ - // convert to BufferState::Unbuffered - // use the first instruction which should be a mouse instruction - // to push a ReplaceMouse instruction - // duplicate the current mouse + // duplicate the currently buffered mouse state but at a later (future, from the physics perspective) time 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, - 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 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); } - // 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|{ match ins.instruction.instruction{ Instruction::MoveMouse(pos)=>{