diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index 4957ac9..ad107a3 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -31,8 +31,70 @@ pub enum StepInstruction{ ReplaceMouse, } +#[derive(Clone)] +enum BufferState{ + Unbuffered, + Initializing(SessionTime,MouseState), + Buffered(SessionTime,MouseState), +} +impl BufferState{ + fn next_state(&self,ins:DoubleTimedUnbufferedInstruction,physics_timeline:&mut std::collections::VecDeque)->Self{ + match self{ + BufferState::Unbuffered=>{ + if let UnbufferedInputInstruction::MoveMouse(pos)=ins.instruction.instruction{ + return BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time}); + } + }, + BufferState::Initializing(time,mouse_state)=>{ + let timeout=*time+MOUSE_TIMEOUT; + if timeout{ + let timeout=*time+MOUSE_TIMEOUT; + if timeout, + buffer_state:BufferState, // double timestamped timeline? physics_timeline:std::collections::VecDeque, } @@ -53,13 +115,23 @@ impl InstructionEmitter for MouseInterpolator{ impl MouseInterpolator{ pub fn new()->MouseInterpolator{ MouseInterpolator{ - last_mouse_state:MouseState::default(), + buffer_state:BufferState::Unbuffered, physics_timeline:std::collections::VecDeque::new(), } } pub fn push_unbuffered_input(&mut self,ins:DoubleTimedUnbufferedInstruction){ // new input // if there is zero instruction buffered, it means the mouse is not moving + // case 1: unbuffered + // no mouse event is buffered + // - ins is mouse event? change to buffered + // - ins other -> write to timeline + // case 2: buffered + // a mouse event is buffered, and exists within the last 10ms + // case 3: stop + // a mouse event is buffered, but no mouse events have transpired within 10ms + // TODO: remove clone + self.buffer_state=self.buffer_state.next_state(ins,&mut self.physics_timeline); } fn is_first_ready(&self)->bool{ // if the last instruction is a ReplaceMouse instruction