test mouse_interpolator

This commit is contained in:
Quaternions 2025-01-14 22:16:07 -08:00
parent 80424cf24c
commit 80a4431ee8

View File

@ -1,7 +1,6 @@
use strafesnet_common::mouse::MouseState;
use strafesnet_common::physics::{
Instruction as PhysicsInputInstruction,
Time as PhysicsTime,
TimeInner as PhysicsTimeInner,
MouseInstruction,
OtherInstruction,
@ -27,7 +26,7 @@ pub enum StepInstruction{
Timeout,
}
#[derive(Clone)]
#[derive(Clone,Debug)]
enum BufferState{
Unbuffered,
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);
}
}