diff --git a/src/physics_worker.rs b/src/physics_worker.rs index e95f7ed..ab91cc8 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -29,6 +29,27 @@ pub enum PassthroughInstruction{ pub struct MouseInterpolator{ queue:std::collections::VecDeque>, } +fn drain_queue(physics:&mut crate::physics::PhysicsContext,iterable:impl IntoIterator>){ + 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){ let is_inserting_mouse_instruction=matches!(ins.instruction,InputInstruction::MoveMouse(_)); @@ -59,15 +80,23 @@ impl MouseInterpolator{ _=>if Time::from_millis(10)