test mouse_interpolator
This commit is contained in:
parent
80424cf24c
commit
80a4431ee8
@ -1,7 +1,6 @@
|
|||||||
use strafesnet_common::mouse::MouseState;
|
use strafesnet_common::mouse::MouseState;
|
||||||
use strafesnet_common::physics::{
|
use strafesnet_common::physics::{
|
||||||
Instruction as PhysicsInputInstruction,
|
Instruction as PhysicsInputInstruction,
|
||||||
Time as PhysicsTime,
|
|
||||||
TimeInner as PhysicsTimeInner,
|
TimeInner as PhysicsTimeInner,
|
||||||
MouseInstruction,
|
MouseInstruction,
|
||||||
OtherInstruction,
|
OtherInstruction,
|
||||||
@ -27,7 +26,7 @@ pub enum StepInstruction{
|
|||||||
Timeout,
|
Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Debug)]
|
||||||
enum BufferState{
|
enum BufferState{
|
||||||
Unbuffered,
|
Unbuffered,
|
||||||
Initializing(SessionTime,MouseState<PhysicsTimeInner>),
|
Initializing(SessionTime,MouseState<PhysicsTimeInner>),
|
||||||
@ -226,3 +225,40 @@ impl MouseInterpolator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test{
|
||||||
|
use super::*;
|
||||||
|
#[test]
|
||||||
|
fn test(){
|
||||||
|
let mut interpolator=MouseInterpolator::new();
|
||||||
|
|
||||||
|
let timer=strafesnet_common::timer::Timer::<strafesnet_common::timer::Scaled<SessionTimeInner,PhysicsTimeInner>>::unpaused(SessionTime::ZERO,strafesnet_common::physics::Time::from_secs(1000));
|
||||||
|
|
||||||
|
macro_rules! push{
|
||||||
|
($time:expr,$ins:expr)=>{
|
||||||
|
println!("in={:?}",$ins);
|
||||||
|
interpolator.push_unbuffered_input(TimedInstruction{
|
||||||
|
time:$time,
|
||||||
|
instruction:TimedInstruction{
|
||||||
|
time:timer.time($time),
|
||||||
|
instruction:$ins,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
while let Some(ins)=interpolator.buffered_instruction_with_timeout($time){
|
||||||
|
let out=interpolator.pop_buffered_instruction(ins.instruction);
|
||||||
|
println!("out={out:?}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// test each buffer_state transition
|
||||||
|
let mut t=SessionTime::ZERO;
|
||||||
|
push!(t,Instruction::MoveMouse(glam::ivec2(0,0)));
|
||||||
|
t+=SessionTime::from_millis(5);
|
||||||
|
push!(t,Instruction::MoveMouse(glam::ivec2(0,0)));
|
||||||
|
t+=SessionTime::from_millis(5);
|
||||||
|
push!(t,Instruction::MoveMouse(glam::ivec2(0,0)));
|
||||||
|
t+=SessionTime::from_millis(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user