write pop_buffered_instruction

This commit is contained in:
Quaternions 2025-01-11 01:38:45 -08:00
parent 92c30c3b87
commit 9095215cad

View File

@ -16,8 +16,8 @@ type DoubleTimedUnbufferedInstruction=TimedInstruction<PhysicsTimedUnbufferedIns
const MOUSE_TIMEOUT:SessionTime=SessionTime::from_millis(10); const MOUSE_TIMEOUT:SessionTime=SessionTime::from_millis(10);
pub enum StepInstruction{ pub enum StepInstruction{
Other, Pop,
ReplaceMouse, Timeout,
} }
#[derive(Clone)] #[derive(Clone)]
@ -68,7 +68,7 @@ impl BufferState{
if timeout<ins.time{ if timeout<ins.time{
// duplicate the current mouse // duplicate the current mouse
physics_timeline.push_front(TimedInstruction{ physics_timeline.push_front(TimedInstruction{
// This should be simulation_timer.time(time) // This should be simulation_timer.time(timeout)
// but the timer is not accessible from this scope // but the timer is not accessible from this scope
// and it's just here to say that the mouse isn't moving anyways. // and it's just here to say that the mouse isn't moving anyways.
time:ins.instruction.time, time:ins.instruction.time,
@ -164,7 +164,7 @@ impl MouseInterpolator{
match &self.buffer_state{ match &self.buffer_state{
BufferState::Unbuffered=>self.physics_timeline.front().map(|_|TimedInstruction{ BufferState::Unbuffered=>self.physics_timeline.front().map(|_|TimedInstruction{
time:time_limit, time:time_limit,
instruction:StepInstruction::Other, instruction:StepInstruction::Pop,
}), }),
BufferState::Initializing(time,_mouse_state) BufferState::Initializing(time,_mouse_state)
|BufferState::Buffered(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 // if the mouse has stopped moving for over 10ms, emit DoStepReplaceMouse at that exact timestamp
Some(TimedInstruction{ Some(TimedInstruction{
time:timeout, time:timeout,
instruction:StepInstruction::ReplaceMouse, instruction:StepInstruction::Timeout,
}) })
}else if self.is_first_ready(){ }else if self.is_first_ready(){
// emit Step // emit Step
@ -181,7 +181,7 @@ impl MouseInterpolator{
// this timestamp should not matter // this timestamp should not matter
// verify this and potentially emit a different type using the enum only // verify this and potentially emit a different type using the enum only
time:time_limit, time:time_limit,
instruction:StepInstruction::Other, instruction:StepInstruction::Pop,
}) })
}else{ }else{
None None
@ -191,20 +191,28 @@ impl MouseInterpolator{
} }
pub fn pop_buffered_instruction(&mut self,ins:StepInstruction)->Option<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>{ pub fn pop_buffered_instruction(&mut self,ins:StepInstruction)->Option<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>{
match ins{ match ins{
StepInstruction::Other=>{ // could check if self.is_first_ready()
// if the last instruction is a mouse instruction, StepInstruction::Pop=>self.physics_timeline.pop_front(),
// then the buffer is in the process of flushing. StepInstruction::Timeout=>match &self.buffer_state{
// pop and return the first event. BufferState::Unbuffered=>None,
// if the first instruction is a mouse instruction, BufferState::Initializing(time,mouse_state)
// then events are being buffered to wait for another |BufferState::Buffered(time,mouse_state)=>{
// mouse instruction as an interpolation target // convert to BufferState::Unbuffered
}, // use the first instruction which should be a mouse instruction
StepInstruction::ReplaceMouse=>{ // to push a ReplaceMouse instruction
// convert to BufferState::Unbuffered // duplicate the current mouse
// use the first instruction which should be a mouse instruction self.buffer_state=BufferState::Unbuffered;
// to push a ReplaceMouse instruction 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
} }
} }