pop_buffered_instruction can be accomplished with mem::replace

This commit is contained in:
Quaternions 2025-01-14 03:44:23 -08:00
parent 93277c042b
commit 33ccefc411

View File

@ -194,16 +194,17 @@ impl MouseInterpolator{
match ins{ match ins{
// could check if self.is_first_ready() // could check if self.is_first_ready()
StepInstruction::Pop=>self.physics_timeline.pop_front(), StepInstruction::Pop=>self.physics_timeline.pop_front(),
StepInstruction::Timeout=>replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{ StepInstruction::Timeout=>{
let buffer_state=core::mem::replace(&mut self.buffer_state,BufferState::Unbuffered);
match buffer_state{ match buffer_state{
BufferState::Unbuffered=>(None,BufferState::Unbuffered), BufferState::Unbuffered=>None,
BufferState::Initializing(_time,mouse_state) BufferState::Initializing(_time,mouse_state)
|BufferState::Buffered(_time,mouse_state)=>{ |BufferState::Buffered(_time,mouse_state)=>{
// convert to BufferState::Unbuffered // convert to BufferState::Unbuffered
// use the first instruction which should be a mouse instruction // use the first instruction which should be a mouse instruction
// to push a ReplaceMouse instruction // to push a ReplaceMouse instruction
// duplicate the current mouse // duplicate the current mouse
(Some(TimedInstruction{ Some(TimedInstruction{
// This should be simulation_timer.time(timeout) // 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.
@ -211,10 +212,10 @@ impl MouseInterpolator{
instruction:PhysicsInputInstruction::Mouse( instruction:PhysicsInputInstruction::Mouse(
MouseInstruction::SetNextMouse(mouse_state) MouseInstruction::SetNextMouse(mouse_state)
), ),
}),BufferState::Unbuffered) })
}, },
} }
}), },
} }
} }
} }