move code to more relevant location
This commit is contained in:
parent
52bbaaddc7
commit
6898302fa5
@ -27,76 +27,7 @@ enum BufferState{
|
|||||||
Initializing(SessionTime,MouseState<PhysicsTimeInner>),
|
Initializing(SessionTime,MouseState<PhysicsTimeInner>),
|
||||||
Buffered(SessionTime,MouseState<PhysicsTimeInner>),
|
Buffered(SessionTime,MouseState<PhysicsTimeInner>),
|
||||||
}
|
}
|
||||||
impl BufferState{
|
|
||||||
fn next_state(self,ins:DoubleTimedUnbufferedInstruction)->((Option<TimedInstruction<MouseInstruction,PhysicsTimeInner>>,Option<TimedInstruction<OtherInstruction,PhysicsTimeInner>>),Self){
|
|
||||||
let next_state=match self{
|
|
||||||
BufferState::Unbuffered=>{
|
|
||||||
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
|
||||||
return ((None,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time}));
|
|
||||||
}
|
|
||||||
BufferState::Unbuffered
|
|
||||||
},
|
|
||||||
BufferState::Initializing(time,mouse_state)=>{
|
|
||||||
let timeout=time+MOUSE_TIMEOUT;
|
|
||||||
if timeout<ins.time{
|
|
||||||
// duplicate the current mouse
|
|
||||||
let ins_mouse=TimedInstruction{
|
|
||||||
// This should be simulation_timer.time(time)
|
|
||||||
// but the timer is not accessible from this scope
|
|
||||||
// and it's just here to say that the mouse isn't moving anyways.
|
|
||||||
time:ins.instruction.time,
|
|
||||||
instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:ins.instruction.time}),
|
|
||||||
};
|
|
||||||
return ((Some(ins_mouse),None),BufferState::Unbuffered);
|
|
||||||
}
|
|
||||||
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
|
||||||
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
|
|
||||||
let ins_mouse=TimedInstruction{
|
|
||||||
time:mouse_state.time,
|
|
||||||
instruction:MouseInstruction::ReplaceMouse{
|
|
||||||
s0:mouse_state,
|
|
||||||
s1:next_mouse_state.clone(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
|
|
||||||
}
|
|
||||||
BufferState::Initializing(time,mouse_state)
|
|
||||||
},
|
|
||||||
BufferState::Buffered(time,mouse_state)=>{
|
|
||||||
// TODO: deduplicate code with above case
|
|
||||||
let timeout=time+MOUSE_TIMEOUT;
|
|
||||||
if timeout<ins.time{
|
|
||||||
// duplicate the current mouse
|
|
||||||
let ins_mouse=TimedInstruction{
|
|
||||||
// This should be simulation_timer.time(timeout)
|
|
||||||
// but the timer is not accessible from this scope
|
|
||||||
// and it's just here to say that the mouse isn't moving anyways.
|
|
||||||
time:ins.instruction.time,
|
|
||||||
instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:ins.instruction.time}),
|
|
||||||
};
|
|
||||||
return ((Some(ins_mouse),None),BufferState::Unbuffered);
|
|
||||||
}
|
|
||||||
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
|
||||||
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
|
|
||||||
let ins_mouse=TimedInstruction{
|
|
||||||
time:ins.instruction.time,
|
|
||||||
instruction:MouseInstruction::SetNextMouse(next_mouse_state.clone()),
|
|
||||||
};
|
|
||||||
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
|
|
||||||
}
|
|
||||||
BufferState::Buffered(time,mouse_state)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
let ins_other=match ins.instruction.instruction{
|
|
||||||
PhysicsUnbufferedInstruction::MoveMouse(_)=>None,
|
|
||||||
PhysicsUnbufferedInstruction::Other(other_instruction)=>Some(TimedInstruction{
|
|
||||||
time:ins.instruction.time,
|
|
||||||
instruction:other_instruction,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
((None,ins_other),next_state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub struct MouseInterpolator{
|
pub struct MouseInterpolator{
|
||||||
buffer_state:BufferState,
|
buffer_state:BufferState,
|
||||||
// double timestamped timeline?
|
// double timestamped timeline?
|
||||||
@ -136,7 +67,72 @@ impl MouseInterpolator{
|
|||||||
// a mouse event is buffered, but no mouse events have transpired within 10ms
|
// a mouse event is buffered, but no mouse events have transpired within 10ms
|
||||||
// replace_with allows the enum variant to safely be replaced from behind a mutable reference
|
// replace_with allows the enum variant to safely be replaced from behind a mutable reference
|
||||||
let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{
|
let (ins_mouse,ins_other)=replace_with::replace_with_or_abort_and_return(&mut self.buffer_state,|buffer_state|{
|
||||||
buffer_state.next_state(ins)
|
let next_state=match buffer_state{
|
||||||
|
BufferState::Unbuffered=>{
|
||||||
|
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
||||||
|
return ((None,None),BufferState::Initializing(ins.time,MouseState{pos,time:ins.instruction.time}));
|
||||||
|
}
|
||||||
|
BufferState::Unbuffered
|
||||||
|
},
|
||||||
|
BufferState::Initializing(time,mouse_state)=>{
|
||||||
|
let timeout=time+MOUSE_TIMEOUT;
|
||||||
|
if timeout<ins.time{
|
||||||
|
// duplicate the current mouse
|
||||||
|
let ins_mouse=TimedInstruction{
|
||||||
|
// This should be simulation_timer.time(time)
|
||||||
|
// but the timer is not accessible from this scope
|
||||||
|
// and it's just here to say that the mouse isn't moving anyways.
|
||||||
|
time:ins.instruction.time,
|
||||||
|
instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:ins.instruction.time}),
|
||||||
|
};
|
||||||
|
return ((Some(ins_mouse),None),BufferState::Unbuffered);
|
||||||
|
}
|
||||||
|
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
||||||
|
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
|
||||||
|
let ins_mouse=TimedInstruction{
|
||||||
|
time:mouse_state.time,
|
||||||
|
instruction:MouseInstruction::ReplaceMouse{
|
||||||
|
s0:mouse_state,
|
||||||
|
s1:next_mouse_state.clone(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
|
||||||
|
}
|
||||||
|
BufferState::Initializing(time,mouse_state)
|
||||||
|
},
|
||||||
|
BufferState::Buffered(time,mouse_state)=>{
|
||||||
|
// TODO: deduplicate code with above case
|
||||||
|
let timeout=time+MOUSE_TIMEOUT;
|
||||||
|
if timeout<ins.time{
|
||||||
|
// duplicate the current mouse
|
||||||
|
let ins_mouse=TimedInstruction{
|
||||||
|
// This should be simulation_timer.time(timeout)
|
||||||
|
// but the timer is not accessible from this scope
|
||||||
|
// and it's just here to say that the mouse isn't moving anyways.
|
||||||
|
time:ins.instruction.time,
|
||||||
|
instruction:MouseInstruction::SetNextMouse(MouseState{pos:mouse_state.pos,time:ins.instruction.time}),
|
||||||
|
};
|
||||||
|
return ((Some(ins_mouse),None),BufferState::Unbuffered);
|
||||||
|
}
|
||||||
|
if let PhysicsUnbufferedInstruction::MoveMouse(pos)=ins.instruction.instruction{
|
||||||
|
let next_mouse_state=MouseState{pos,time:ins.instruction.time};
|
||||||
|
let ins_mouse=TimedInstruction{
|
||||||
|
time:ins.instruction.time,
|
||||||
|
instruction:MouseInstruction::SetNextMouse(next_mouse_state.clone()),
|
||||||
|
};
|
||||||
|
return ((Some(ins_mouse),None),BufferState::Buffered(ins.time,next_mouse_state));
|
||||||
|
}
|
||||||
|
BufferState::Buffered(time,mouse_state)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let ins_other=match ins.instruction.instruction{
|
||||||
|
PhysicsUnbufferedInstruction::MoveMouse(_)=>None,
|
||||||
|
PhysicsUnbufferedInstruction::Other(other_instruction)=>Some(TimedInstruction{
|
||||||
|
time:ins.instruction.time,
|
||||||
|
instruction:other_instruction,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
((None,ins_other),next_state)
|
||||||
});
|
});
|
||||||
if let Some(ins)=ins_mouse{
|
if let Some(ins)=ins_mouse{
|
||||||
self.physics_timeline.push_front(TimedInstruction{
|
self.physics_timeline.push_front(TimedInstruction{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user