diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index 8457394..97cb0b2 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -2,6 +2,7 @@ use strafesnet_common::mouse::MouseState; use strafesnet_common::physics::{ Instruction as PhysicsInputInstruction, TimeInner as PhysicsTimeInner, + Time as PhysicsTime, MouseInstruction, OtherInstruction, }; @@ -85,7 +86,7 @@ impl MouseInterpolator{ } } } - fn timeout(&mut self){ + fn timeout(&mut self,time:PhysicsTime){ let buffer_state=core::mem::replace(&mut self.buffer_state,BufferState::Unbuffered); match buffer_state{ BufferState::Unbuffered=>(), @@ -100,8 +101,8 @@ impl MouseInterpolator{ // 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(mouse_state), + time, + instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time}), }); }, } @@ -120,7 +121,7 @@ impl MouseInterpolator{ // push buffered mouse instruction and flush buffer to output if self.get_timedout_at(ins.time).is_some(){ - self.timeout(); + self.timeout(ins.instruction.time); } // 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|{ @@ -187,11 +188,10 @@ impl MouseInterpolator{ }), } } - // include timestamp and implement InstructionConsumer? - pub fn pop_buffered_instruction(&mut self,ins:StepInstruction)->Option>{ - match ins{ + pub fn pop_buffered_instruction(&mut self,ins:TimedInstruction)->Option>{ + match ins.instruction{ StepInstruction::Pop=>(), - StepInstruction::Timeout=>self.timeout(), + StepInstruction::Timeout=>self.timeout(ins.time), } self.output.pop_front() } @@ -204,7 +204,7 @@ mod test{ fn test(){ let mut interpolator=MouseInterpolator::new(); - let timer=strafesnet_common::timer::Timer::>::unpaused(SessionTime::ZERO,strafesnet_common::physics::Time::from_secs(1000)); + let timer=strafesnet_common::timer::Timer::>::unpaused(SessionTime::ZERO,PhysicsTime::from_secs(1000)); macro_rules! push{ ($time:expr,$ins:expr)=>{ @@ -217,7 +217,11 @@ mod test{ } }); while let Some(ins)=interpolator.buffered_instruction_with_timeout($time){ - let out=interpolator.pop_buffered_instruction(ins.instruction); + let ins_retimed=TimedInstruction{ + time:timer.time(ins.time), + instruction:ins.instruction, + }; + let out=interpolator.pop_buffered_instruction(ins_retimed); println!("out={out:?}"); } }; diff --git a/strafe-client/src/session.rs b/strafe-client/src/session.rs index 96fde2f..fce8439 100644 --- a/strafe-client/src/session.rs +++ b/strafe-client/src/session.rs @@ -176,7 +176,11 @@ impl InstructionConsumer for Session{ type TimeInner=SessionTimeInner; fn process_instruction(&mut self,ins:TimedInstruction){ // ins.time ignored??? - if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(ins.instruction){ + let ins_retimed=TimedInstruction{ + time:self.simulation.timer.time(ins.time), + instruction:ins.instruction, + }; + if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(ins_retimed){ self.simulation.physics.run_input_instruction(instruction); } }