diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 6aca31e..e7c278c 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -27,14 +27,33 @@ pub enum PassthroughInstruction{ //Graphics(crate::graphics_worker::Instruction), } pub struct MouseInterpolator{ - queue:std::collections::VecDeque>, + queue:std::collections::VecDeque>, } impl MouseInterpolator{ - fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:InputInstruction,time:Time){ - //design is completely inverted - //immediately add the instruction to the queue - //if there are two mouse instructions or more than 10ms between the first and last - //processs dems instructions + fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction){ + self.queue.push_back(ins); + //We just pushed an element. + //The first element is guaranteed to exist. + let t0=self.queue[0].time; + let mut iter=self.queue.iter(); + //find a mouse input + let mouse0=None; + iter.take_while(|&ins|{ + match ins.instruction{ + InputInstruction::MoveMouse(m)=>{ + mouse0=Some(m); + false + }, + _=>{ + //TODO: 10mspassthrough_instruction, Instruction::Interpolate(input_instruction)=>{ - interpolator.handle_instruction(&mut physics,input_instruction,ins.time); + interpolator.handle_instruction(&mut physics,TimedInstruction{ + instruction:input_instruction, + time:ins.time, + }); return; }, };