done ish
This commit is contained in:
parent
d7dc08092a
commit
b376c03bde
@ -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)<ins1.time-ins0.time{
|
||||
_=>if Time::from_millis(10)<ins1.time-t0{
|
||||
//we have passed more than 10ms of instructions and have not seen a mouse event.
|
||||
let consume_count=self.queue.len()-iter.len();
|
||||
//run an event to extrapolate no movement from
|
||||
@ -109,7 +126,7 @@ impl MouseInterpolator{
|
||||
time:physics.get_next_mouse().time,
|
||||
instruction:PhysicsInputInstruction::ReplaceMouse(
|
||||
physics.get_next_mouse().clone(),
|
||||
MouseState{time:ins0.time,pos:*mouse0}
|
||||
MouseState{time:t0,pos:mouse0}
|
||||
),
|
||||
});
|
||||
}
|
||||
@ -142,6 +159,7 @@ impl MouseInterpolator{
|
||||
None=>{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user