From 9095215cad58eb0b36ef113a76dbb832d2ff4f52 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 11 Jan 2025 01:38:45 -0800 Subject: [PATCH] write pop_buffered_instruction --- strafe-client/src/mouse_interpolator.rs | 46 +++++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index d5e36de..fc8d388 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -16,8 +16,8 @@ type DoubleTimedUnbufferedInstruction=TimedInstructionself.physics_timeline.front().map(|_|TimedInstruction{ time:time_limit, - instruction:StepInstruction::Other, + instruction:StepInstruction::Pop, }), BufferState::Initializing(time,_mouse_state) |BufferState::Buffered(time,_mouse_state)=>{ @@ -173,7 +173,7 @@ impl MouseInterpolator{ // if the mouse has stopped moving for over 10ms, emit DoStepReplaceMouse at that exact timestamp Some(TimedInstruction{ time:timeout, - instruction:StepInstruction::ReplaceMouse, + instruction:StepInstruction::Timeout, }) }else if self.is_first_ready(){ // emit Step @@ -181,7 +181,7 @@ impl MouseInterpolator{ // this timestamp should not matter // verify this and potentially emit a different type using the enum only time:time_limit, - instruction:StepInstruction::Other, + instruction:StepInstruction::Pop, }) }else{ None @@ -191,20 +191,28 @@ impl MouseInterpolator{ } pub fn pop_buffered_instruction(&mut self,ins:StepInstruction)->Option>{ match ins{ - StepInstruction::Other=>{ - // if the last instruction is a mouse instruction, - // then the buffer is in the process of flushing. - // pop and return the first event. - // if the first instruction is a mouse instruction, - // then events are being buffered to wait for another - // mouse instruction as an interpolation target - }, - StepInstruction::ReplaceMouse=>{ - // convert to BufferState::Unbuffered - // use the first instruction which should be a mouse instruction - // to push a ReplaceMouse instruction + // could check if self.is_first_ready() + StepInstruction::Pop=>self.physics_timeline.pop_front(), + StepInstruction::Timeout=>match &self.buffer_state{ + BufferState::Unbuffered=>None, + BufferState::Initializing(time,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 + self.buffer_state=BufferState::Unbuffered; + Some(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. + time:ins.instruction.time, + instruction:PhysicsInputInstruction::Mouse( + MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:ins.instruction.time}) + ), + }) + }, }, } - None } }