From 6898302fa59c260f2005dd96070bdcaa93674de4 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 13 Jan 2025 23:22:18 -0800 Subject: [PATCH] move code to more relevant location --- strafe-client/src/mouse_interpolator.rs | 138 ++++++++++++------------ 1 file changed, 67 insertions(+), 71 deletions(-) diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index e24c727..b46c17d 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -27,76 +27,7 @@ enum BufferState{ Initializing(SessionTime,MouseState), Buffered(SessionTime,MouseState), } -impl BufferState{ - 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,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time})); - } - BufferState::Unbuffered - }, - BufferState::Initializing(time,mouse_state)=>{ - let timeout=time+MOUSE_TIMEOUT; - if timeout{ - // TODO: deduplicate code with above case - let timeout=time+MOUSE_TIMEOUT; - if timeoutNone, - PhysicsUnbufferedInstruction::Other(other_instruction)=>Some(TimedInstruction{ - time:ins.instruction.time, - instruction:other_instruction, - }), - }; - ((None,ins_other),next_state) - } -} + pub struct MouseInterpolator{ buffer_state:BufferState, // double timestamped timeline? @@ -136,7 +67,72 @@ impl MouseInterpolator{ // 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_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{ - buffer_state.next_state(ins) + let next_state=match buffer_state{ + BufferState::Unbuffered=>{ + if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{ + return ((None,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time})); + } + BufferState::Unbuffered + }, + BufferState::Initializing(time,mouse_state)=>{ + let timeout=time+MOUSE_TIMEOUT; + if timeout{ + // TODO: deduplicate code with above case + let timeout=time+MOUSE_TIMEOUT; + if timeoutNone, + PhysicsUnbufferedInstruction::Other(other_instruction)=>Some(TimedInstruction{ + time:ins.instruction.time, + instruction:other_instruction, + }), + }; + ((None,ins_other),next_state) }); if let Some(ins)=ins_mouse{ self.physics_timeline.push_front(TimedInstruction{