fix timeout timestamp
This commit is contained in:
parent
292df72709
commit
ada34237c9
@ -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<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>{
|
||||
match ins{
|
||||
pub fn pop_buffered_instruction(&mut self,ins:TimedInstruction<StepInstruction,PhysicsTimeInner>)->Option<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>{
|
||||
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::<strafesnet_common::timer::Scaled<SessionTimeInner,PhysicsTimeInner>>::unpaused(SessionTime::ZERO,strafesnet_common::physics::Time::from_secs(1000));
|
||||
let timer=strafesnet_common::timer::Timer::<strafesnet_common::timer::Scaled<SessionTimeInner,PhysicsTimeInner>>::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:?}");
|
||||
}
|
||||
};
|
||||
|
@ -176,7 +176,11 @@ impl InstructionConsumer<StepInstruction> for Session{
|
||||
type TimeInner=SessionTimeInner;
|
||||
fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::TimeInner>){
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user