forked from StrafesNET/strafe-client
hehehehehe
This commit is contained in:
parent
d898d7cf67
commit
d7dc08092a
@ -29,6 +29,27 @@ pub enum PassthroughInstruction{
|
|||||||
pub struct MouseInterpolator{
|
pub struct MouseInterpolator{
|
||||||
queue:std::collections::VecDeque<TimedInstruction<InputInstruction>>,
|
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{
|
impl MouseInterpolator{
|
||||||
fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction<InputInstruction>){
|
fn handle_instruction(&mut self,physics:&mut crate::physics::PhysicsContext,ins:TimedInstruction<InputInstruction>){
|
||||||
let is_inserting_mouse_instruction=matches!(ins.instruction,InputInstruction::MoveMouse(_));
|
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{
|
_=>if Time::from_millis(10)<ins1.time-ins0.time{
|
||||||
//we have passed more than 10ms of instructions and have not seen a mouse event.
|
//we have passed more than 10ms of instructions and have not seen a mouse event.
|
||||||
let consume_count=self.queue.len()-iter.len();
|
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
|
//run an event to extrapolate no movement from
|
||||||
let last_mouse=physics.get_next_mouse();
|
let last_mouse=physics.get_next_mouse();
|
||||||
physics.run_input_instruction(TimedInstruction{
|
physics.run_input_instruction(TimedInstruction{
|
||||||
time:last_mouse.time,
|
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();
|
iter=self.queue.iter();
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user