hehehehehe

This commit is contained in:
Quaternions 2024-07-30 20:15:39 -07:00
parent d898d7cf67
commit d7dc08092a

View File

@ -29,6 +29,27 @@ pub enum PassthroughInstruction{
pub struct MouseInterpolator{
queue:std::collections::VecDeque<TimedInstruction<InputInstruction>>,
}
fn drain_queue(physics:&mut crate::physics::PhysicsContext,iterable:impl IntoIterator<Item=TimedInstruction<InputInstruction>>){
for ins in iterable{
let physics_input=match &ins.instruction{
InputInstruction::MoveMouse(_)=>panic!("Queue was confirmed to contain no MoveMouse events1"),
&InputInstruction::MoveForward(s)=>PhysicsInputInstruction::SetMoveForward(s),
&InputInstruction::MoveLeft(s)=>PhysicsInputInstruction::SetMoveLeft(s),
&InputInstruction::MoveBack(s)=>PhysicsInputInstruction::SetMoveBack(s),
&InputInstruction::MoveRight(s)=>PhysicsInputInstruction::SetMoveRight(s),
&InputInstruction::MoveUp(s)=>PhysicsInputInstruction::SetMoveUp(s),
&InputInstruction::MoveDown(s)=>PhysicsInputInstruction::SetMoveDown(s),
&InputInstruction::Jump(s)=>PhysicsInputInstruction::SetJump(s),
&InputInstruction::Zoom(s)=>PhysicsInputInstruction::SetZoom(s),
InputInstruction::Reset=>PhysicsInputInstruction::Reset,
InputInstruction::PracticeFly=>PhysicsInputInstruction::PracticeFly,
};
physics.run_input_instruction(TimedInstruction{
time:ins.time,
instruction:physics_input,
});
}
}
impl MouseInterpolator{
fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction<InputInstruction>){
let is_inserting_mouse_instruction=matches!(ins.instruction,InputInstruction::MoveMouse(_));
@ -59,15 +80,23 @@ impl MouseInterpolator{
_=>if Time::from_millis(10)<ins1.time-ins0.time{
//we have passed more than 10ms of instructions and have not seen a mouse event.
let consume_count=self.queue.len()-iter.len();
//drop the iterator so we can consume the queue up to this point
std::mem::drop(iter);
//run an event to extrapolate no movement from
let last_mouse=physics.get_next_mouse();
physics.run_input_instruction(TimedInstruction{
time:last_mouse.time,
instruction:PhysicsInputInstruction::SetNextMouse(MouseState{time:ins1.time,pos:last_mouse.pos}),
instruction:PhysicsInputInstruction::SetNextMouse(
MouseState{time:ins1.time,pos:last_mouse.pos}
),
});
//make a new iterator starting from the new beginning and loop like nothing happened
//drop the iterator so we can consume the queue up to this point
std::mem::drop(iter);
//consume queue up to the scanned point
let mut hot_queue=self.queue.drain(0..consume_count);
//the first element is always the last mouse instruction (last_mouse above)
hot_queue.next();
drain_queue(physics,hot_queue);
//make a new iterator starting from the new beginning
//and continue looping like nothing happened
iter=self.queue.iter();
continue 'outer;
},