From 80a4431ee8d9464d4a5f90b6eb1faa50dc6136ae Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 14 Jan 2025 22:16:07 -0800 Subject: [PATCH] test mouse_interpolator --- strafe-client/src/mouse_interpolator.rs | 40 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/strafe-client/src/mouse_interpolator.rs b/strafe-client/src/mouse_interpolator.rs index b6f3f95..7105b50 100644 --- a/strafe-client/src/mouse_interpolator.rs +++ b/strafe-client/src/mouse_interpolator.rs @@ -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), @@ -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::>::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); + } +}