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