diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index 4e38ca0..e24c727 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -28,11 +28,11 @@ enum BufferState{ Buffered(SessionTime,MouseState), } impl BufferState{ - fn next_state(self,ins:DoubleTimedUnbufferedInstruction,physics_timeline:&mut std::collections::VecDeque)->(Option>,Self){ + fn next_state(self,ins:DoubleTimedUnbufferedInstruction)->((Option>,Option>),Self){ let next_state=match self{ BufferState::Unbuffered=>{ if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{ - return (None,BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time})); + return ((None,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time})); } BufferState::Unbuffered }, @@ -40,29 +40,25 @@ impl BufferState{ let timeout=time+MOUSE_TIMEOUT; if timeoutNone, PhysicsUnbufferedInstruction::Other(other_instruction)=>Some(TimedInstruction{ time:ins.instruction.time, instruction:other_instruction, }), }; - (instruction_out,next_state) + ((None,ins_other),next_state) } } pub struct MouseInterpolator{ @@ -143,10 +135,16 @@ impl MouseInterpolator{ // case 3: stop // a mouse event is buffered, but no mouse events have transpired within 10ms // replace_with allows the enum variant to safely be replaced from behind a mutable reference - let ins_inner=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{ - buffer_state.next_state(ins,&mut self.physics_timeline) + let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{ + buffer_state.next_state(ins) }); - if let Some(ins)=ins_inner{ + if let Some(ins)=ins_mouse{ + self.physics_timeline.push_front(TimedInstruction{ + time:ins.time, + instruction:PhysicsInputInstruction::Mouse(ins.instruction), + }); + } + if let Some(ins)=ins_other{ self.physics_timeline.push_back(TimedInstruction{ time:ins.time, instruction:PhysicsInputInstruction::Other(ins.instruction),