From b376c03bdedd03188d983baaa1596ed84a18baf2 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 30 Jul 2024 20:33:22 -0700 Subject: [PATCH] done ish --- src/physics_worker.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/physics_worker.rs b/src/physics_worker.rs index ab91cc8..25fbc08 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -62,22 +62,39 @@ impl MouseInterpolator{ match iter.next(){ Some(ins0)=>{ let physics_input=match &ins0.instruction{ - InputInstruction::MoveMouse(mouse0)=>{ + &InputInstruction::MoveMouse(mut mouse0)=>{ //mouse instruction found. //enter a new loop with different behaviour //we have to wait for the next mouse event //so there is a before and after interpolation target + //write down ins0.time to appease the borrow checker + let mut t0=ins0.time; 'inner:loop{ match iter.next(){ - Some(ins1)=>match ins1.instruction{ - InputInstruction::MoveMouse(mouse1)=>{ + Some(ins1)=>match &ins1.instruction{ + &InputInstruction::MoveMouse(mouse1)=>{ //we found two mouse events to interpolate between let consume_count=self.queue.len()-iter.len()-1;//don't consume the mouse1 instruction //fire off a mouse instruction + physics.run_input_instruction(TimedInstruction{ + time:t0, + instruction:PhysicsInputInstruction::SetNextMouse( + MouseState{time:ins1.time,pos:mouse1} + ), + }); + //update inner loop state + mouse0=mouse1; + t0=ins1.time; //drain and handle the elements from the front - break 'outer; + std::mem::drop(iter); + let mut hot_queue=self.queue.drain(0..consume_count); + hot_queue.next(); + drain_queue(physics,hot_queue); + iter=self.queue.iter(); + //keep looking for another mouse instruction in the inner loop + continue 'inner; }, - _=>if Time::from_millis(10)if Time::from_millis(10){ //if mouse0 is never found and the loop ends, we can drain the entire queue //because we are not waiting for mouse events. + drain_queue(physics,self.queue.drain(..)); break 'outer; } }