diff --git a/engine/physics/src/physics.rs b/engine/physics/src/physics.rs index e14d5d4..85ce37a 100644 --- a/engine/physics/src/physics.rs +++ b/engine/physics/src/physics.rs @@ -556,7 +556,7 @@ impl MoveState{ =>None, } } - fn next_move_instruction(&self,strafe:&Option<gameplay_style::StrafeSettings>,time:Time)->Option<TimedInstruction<InternalInstruction,TimeInner>>{ + fn next_move_instruction(&self,strafe:&Option<gameplay_style::StrafeSettings>,time:Time)->Option<TimedInstruction<InternalInstruction,Time>>{ //check if you have a valid walk state and create an instruction match self{ MoveState::Walk(walk_state)|MoveState::Ladder(walk_state)=>match &walk_state.target{ @@ -784,7 +784,7 @@ impl TouchingState{ }).collect(); crate::push_solve::push_solve(&contacts,acceleration) } - fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector<InternalInstruction,TimeInner>,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,start_time:Time){ + fn predict_collision_end(&self,collector:&mut instruction::InstructionCollector<InternalInstruction,Time>,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,body:&Body,start_time:Time){ // let relative_body=body.relative_to(&Body::ZERO); let relative_body=body; for contact in &self.contacts{ @@ -878,7 +878,7 @@ impl PhysicsState{ fn reset_to_default(&mut self){ *self=Self::default(); } - fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,TimeInner>>{ + fn next_move_instruction(&self)->Option<TimedInstruction<InternalInstruction,Time>>{ self.move_state.next_move_instruction(&self.style.strafe,self.time) } fn cull_velocity(&mut self,data:&PhysicsData,velocity:Planar64Vec3){ @@ -950,21 +950,21 @@ pub struct PhysicsContext<'a>{ // the physics consumes both Instruction and PhysicsInternalInstruction, // but can only emit PhysicsInternalInstruction impl InstructionConsumer<InternalInstruction> for PhysicsContext<'_>{ - type TimeInner=TimeInner; - fn process_instruction(&mut self,ins:TimedInstruction<InternalInstruction,TimeInner>){ + type Time=Time; + fn process_instruction(&mut self,ins:TimedInstruction<InternalInstruction,Time>){ atomic_internal_instruction(&mut self.state,&self.data,ins) } } impl InstructionConsumer<Instruction> for PhysicsContext<'_>{ - type TimeInner=TimeInner; - fn process_instruction(&mut self,ins:TimedInstruction<Instruction,TimeInner>){ + type Time=Time; + fn process_instruction(&mut self,ins:TimedInstruction<Instruction,Time>){ atomic_input_instruction(&mut self.state,&self.data,ins) } } impl InstructionEmitter<InternalInstruction> for PhysicsContext<'_>{ - type TimeInner=TimeInner; + type Time=Time; //this little next instruction function could cache its return value and invalidate the cached value by watching the State. - fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<InternalInstruction,TimeInner>>{ + fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<InternalInstruction,Time>>{ next_instruction_internal(&self.state,&self.data,time_limit) } } @@ -972,7 +972,7 @@ impl PhysicsContext<'_>{ pub fn run_input_instruction( state:&mut PhysicsState, data:&PhysicsData, - instruction:TimedInstruction<Instruction,TimeInner> + instruction:TimedInstruction<Instruction,Time> ){ let mut context=PhysicsContext{state,data}; context.process_exhaustive(instruction.time); @@ -1121,7 +1121,7 @@ impl PhysicsData{ } //this is the one who asks - fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<InternalInstruction,TimeInner>>{ + fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Time)->Option<TimedInstruction<InternalInstruction,Time>>{ //JUST POLLING!!! NO MUTATION let mut collector=instruction::InstructionCollector::new(time_limit); @@ -1651,7 +1651,7 @@ fn collision_end_intersect( } } } -fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<InternalInstruction,TimeInner>){ +fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<InternalInstruction,Time>){ state.time=ins.time; let (should_advance_body,goober_time)=match ins.instruction{ InternalInstruction::CollisionStart(_,dt) @@ -1747,7 +1747,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim } } -fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<Instruction,TimeInner>){ +fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction<Instruction,Time>){ state.time=ins.time; let should_advance_body=match ins.instruction{ //the body may as well be a quantum wave function diff --git a/engine/session/src/mouse_interpolator.rs b/engine/session/src/mouse_interpolator.rs index a6f4b0e..b992deb 100644 --- a/engine/session/src/mouse_interpolator.rs +++ b/engine/session/src/mouse_interpolator.rs @@ -5,13 +5,13 @@ use strafesnet_common::physics::{ TimeInner as PhysicsTimeInner, Time as PhysicsTime, }; -use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; +use strafesnet_common::session::Time as SessionTime; use strafesnet_common::instruction::{InstructionConsumer,InstructionEmitter,TimedInstruction}; -type TimedSelfInstruction=TimedInstruction<Instruction,PhysicsTimeInner>; -type DoubleTimedSelfInstruction=TimedInstruction<TimedSelfInstruction,SessionTimeInner>; +type TimedSelfInstruction=TimedInstruction<Instruction,PhysicsTime>; +type DoubleTimedSelfInstruction=TimedInstruction<TimedSelfInstruction,SessionTime>; -type TimedPhysicsInstruction=TimedInstruction<PhysicsInstruction,PhysicsTimeInner>; +type TimedPhysicsInstruction=TimedInstruction<PhysicsInstruction,PhysicsTime>; const MOUSE_TIMEOUT:SessionTime=SessionTime::from_millis(10); @@ -89,14 +89,14 @@ pub struct MouseInterpolator{ // Maybe MouseInterpolator manipulation is better expressed using impls // and called from Instruction trait impls in session impl InstructionConsumer<TimedSelfInstruction> for MouseInterpolator{ - type TimeInner=SessionTimeInner; + type Time=SessionTime; fn process_instruction(&mut self,ins:DoubleTimedSelfInstruction){ self.push_unbuffered_input(ins.time,ins.instruction.time,ins.instruction.instruction.into()) } } impl InstructionEmitter<StepInstruction> for MouseInterpolator{ - type TimeInner=SessionTimeInner; - fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,Self::TimeInner>>{ + type Time=SessionTime; + fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,Self::Time>>{ self.buffered_instruction_with_timeout(time_limit) } } @@ -108,7 +108,7 @@ impl MouseInterpolator{ output:std::collections::VecDeque::new(), } } - fn push_mouse_and_flush_buffer(&mut self,ins:TimedInstruction<MouseInstruction,PhysicsTimeInner>){ + fn push_mouse_and_flush_buffer(&mut self,ins:TimedInstruction<MouseInstruction,PhysicsTime>){ self.buffer.push_front(TimedInstruction{ time:ins.time, instruction:BufferedInstruction::Mouse(ins.instruction).into(), @@ -219,7 +219,7 @@ impl MouseInterpolator{ } } } - fn buffered_instruction_with_timeout(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,SessionTimeInner>>{ + fn buffered_instruction_with_timeout(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,SessionTime>>{ match self.get_mouse_timedout_at(time_limit){ Some(timeout)=>Some(TimedInstruction{ time:timeout, @@ -232,7 +232,7 @@ impl MouseInterpolator{ }), } } - pub fn pop_buffered_instruction(&mut self,ins:TimedInstruction<StepInstruction,PhysicsTimeInner>)->Option<TimedPhysicsInstruction>{ + pub fn pop_buffered_instruction(&mut self,ins:TimedInstruction<StepInstruction,PhysicsTime>)->Option<TimedPhysicsInstruction>{ match ins.instruction{ StepInstruction::Pop=>(), StepInstruction::Timeout=>self.timeout_mouse(ins.time), @@ -244,6 +244,7 @@ impl MouseInterpolator{ #[cfg(test)] mod test{ use super::*; + use strafesnet_common::session::TimeInner as SessionTimeInner; #[test] fn test(){ let mut interpolator=MouseInterpolator::new(); diff --git a/engine/session/src/session.rs b/engine/session/src/session.rs index c5f6329..e7959b3 100644 --- a/engine/session/src/session.rs +++ b/engine/session/src/session.rs @@ -88,11 +88,11 @@ impl Simulation{ #[derive(Default)] pub struct Recording{ - instructions:Vec<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>, + instructions:Vec<TimedInstruction<PhysicsInputInstruction,PhysicsTime>>, } impl Recording{ pub fn new( - instructions:Vec<TimedInstruction<PhysicsInputInstruction,PhysicsTimeInner>>, + instructions:Vec<TimedInstruction<PhysicsInputInstruction,PhysicsTime>>, )->Self{ Self{instructions} } @@ -207,8 +207,8 @@ impl Session{ // Session emits DoStep impl InstructionConsumer<Instruction<'_>> for Session{ - type TimeInner=SessionTimeInner; - fn process_instruction(&mut self,ins:TimedInstruction<Instruction,Self::TimeInner>){ + type Time=SessionTime; + fn process_instruction(&mut self,ins:TimedInstruction<Instruction,Self::Time>){ // repetitive procedure macro macro_rules! run_mouse_interpolator_instruction{ ($instruction:expr)=>{ @@ -425,8 +425,8 @@ impl InstructionConsumer<Instruction<'_>> for Session{ } } impl InstructionConsumer<StepInstruction> for Session{ - type TimeInner=SessionTimeInner; - fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::TimeInner>){ + type Time=SessionTime; + fn process_instruction(&mut self,ins:TimedInstruction<StepInstruction,Self::Time>){ let time=self.simulation.timer.time(ins.time); if let Some(instruction)=self.mouse_interpolator.pop_buffered_instruction(ins.set_time(time)){ //record @@ -436,8 +436,8 @@ impl InstructionConsumer<StepInstruction> for Session{ } } impl InstructionEmitter<StepInstruction> for Session{ - type TimeInner=SessionTimeInner; - fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,Self::TimeInner>>{ + type Time=SessionTime; + fn next_instruction(&self,time_limit:SessionTime)->Option<TimedInstruction<StepInstruction,Self::Time>>{ self.mouse_interpolator.next_instruction(time_limit) } } diff --git a/lib/common/src/instruction.rs b/lib/common/src/instruction.rs index b2e2709..8aab3ca 100644 --- a/lib/common/src/instruction.rs +++ b/lib/common/src/instruction.rs @@ -1,13 +1,11 @@ -use crate::integer::Time; - #[derive(Clone,Debug)] pub struct TimedInstruction<I,T>{ - pub time:Time<T>, + pub time:T, pub instruction:I, } impl<I,T> TimedInstruction<I,T>{ #[inline] - pub fn set_time<TimeInner>(self,new_time:Time<TimeInner>)->TimedInstruction<I,TimeInner>{ + pub fn set_time<T2>(self,new_time:T2)->TimedInstruction<I,T2>{ TimedInstruction{ time:new_time, instruction:self.instruction, @@ -17,21 +15,21 @@ impl<I,T> TimedInstruction<I,T>{ /// Ensure all emitted instructions are processed before consuming external instructions pub trait InstructionEmitter<I>{ - type TimeInner; - fn next_instruction(&self,time_limit:Time<Self::TimeInner>)->Option<TimedInstruction<I,Self::TimeInner>>; + type Time; + fn next_instruction(&self,time_limit:Self::Time)->Option<TimedInstruction<I,Self::Time>>; } /// Apply an atomic state update pub trait InstructionConsumer<I>{ - type TimeInner; - fn process_instruction(&mut self,instruction:TimedInstruction<I,Self::TimeInner>); + type Time; + fn process_instruction(&mut self,instruction:TimedInstruction<I,Self::Time>); } /// If the object produces its own instructions, allow exhaustively feeding them back in -pub trait InstructionFeedback<I,T>:InstructionEmitter<I,TimeInner=T>+InstructionConsumer<I,TimeInner=T> +pub trait InstructionFeedback<I,T>:InstructionEmitter<I,Time=T>+InstructionConsumer<I,Time=T> where - Time<T>:Copy, + T:Copy, { #[inline] - fn process_exhaustive(&mut self,time_limit:Time<T>){ + fn process_exhaustive(&mut self,time_limit:T){ while let Some(instruction)=self.next_instruction(time_limit){ self.process_instruction(instruction); } @@ -39,27 +37,27 @@ pub trait InstructionFeedback<I,T>:InstructionEmitter<I,TimeInner=T>+Instruction } impl<I,T,X> InstructionFeedback<I,T> for X where - Time<T>:Copy, - X:InstructionEmitter<I,TimeInner=T>+InstructionConsumer<I,TimeInner=T>, + T:Copy, + X:InstructionEmitter<I,Time=T>+InstructionConsumer<I,Time=T>, {} //PROPER PRIVATE FIELDS!!! pub struct InstructionCollector<I,T>{ - time:Time<T>, + time:T, instruction:Option<I>, } impl<I,T> InstructionCollector<I,T> - where Time<T>:Copy+PartialOrd, + where T:Copy+PartialOrd, { #[inline] - pub const fn new(time:Time<T>)->Self{ + pub const fn new(time:T)->Self{ Self{ time, instruction:None } } #[inline] - pub const fn time(&self)->Time<T>{ + pub const fn time(&self)->T{ self.time } #[inline] diff --git a/lib/snf/src/bot.rs b/lib/snf/src/bot.rs index 22312cf..bea0519 100644 --- a/lib/snf/src/bot.rs +++ b/lib/snf/src/bot.rs @@ -6,7 +6,7 @@ use strafesnet_common::physics::Time; const VERSION:u32=0; -type TimedPhysicsInstruction=strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction,strafesnet_common::physics::TimeInner>; +type TimedPhysicsInstruction=strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction,strafesnet_common::physics::Time>; #[derive(Debug)] pub enum Error{ diff --git a/lib/snf/src/newtypes/physics.rs b/lib/snf/src/newtypes/physics.rs index 2d849af..b1cb808 100644 --- a/lib/snf/src/newtypes/physics.rs +++ b/lib/snf/src/newtypes/physics.rs @@ -1,7 +1,7 @@ use super::integer::Time; use super::common::{bool_from_u8,bool_into_u8}; -type TimedPhysicsInstruction=strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction,strafesnet_common::physics::TimeInner>; +type TimedPhysicsInstruction=strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction,strafesnet_common::physics::Time>; #[binrw::binrw] #[brw(little)] diff --git a/strafe-client/src/app.rs b/strafe-client/src/app.rs index 23d28e4..07fe600 100644 --- a/strafe-client/src/app.rs +++ b/strafe-client/src/app.rs @@ -1,16 +1,16 @@ use crate::window::Instruction; use strafesnet_common::integer; use strafesnet_common::instruction::TimedInstruction; -use strafesnet_common::session::TimeInner as SessionTimeInner; +use strafesnet_common::session::Time as SessionTime; pub struct App<'a>{ root_time:std::time::Instant, - window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>, + window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>, } impl<'a> App<'a>{ pub fn new( root_time:std::time::Instant, - window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>, + window_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>, )->App<'a>{ Self{ root_time, diff --git a/strafe-client/src/physics_worker.rs b/strafe-client/src/physics_worker.rs index 4b18740..63ce68f 100644 --- a/strafe-client/src/physics_worker.rs +++ b/strafe-client/src/physics_worker.rs @@ -6,7 +6,7 @@ use strafesnet_session::session::{ }; use strafesnet_common::instruction::{TimedInstruction,InstructionConsumer}; use strafesnet_common::physics::Time as PhysicsTime; -use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; +use strafesnet_common::session::Time as SessionTime; use strafesnet_common::timer::Timer; pub enum Instruction{ @@ -23,7 +23,7 @@ pub fn new<'a>( mut graphics_worker:crate::compat_worker::INWorker<'a,crate::graphics_worker::Instruction>, directories:Directories, user_settings:settings::UserSettings, -)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{ +)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>{ let physics=strafesnet_physics::physics::PhysicsState::default(); let timer=Timer::unpaused(SessionTime::ZERO,PhysicsTime::ZERO); let simulation=Simulation::new(timer,physics); @@ -32,7 +32,7 @@ pub fn new<'a>( directories, simulation, ); - crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{ + crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTime>|{ // excruciating pain macro_rules! run_session_instruction{ ($time:expr,$instruction:expr)=>{ diff --git a/strafe-client/src/window.rs b/strafe-client/src/window.rs index d22685d..fb205c4 100644 --- a/strafe-client/src/window.rs +++ b/strafe-client/src/window.rs @@ -1,5 +1,5 @@ use strafesnet_common::instruction::TimedInstruction; -use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner}; +use strafesnet_common::session::Time as SessionTime; use strafesnet_common::physics::{MiscInstruction,SetControlInstruction}; use crate::file::LoadFormat; use crate::physics_worker::Instruction as PhysicsWorkerInstruction; @@ -17,7 +17,7 @@ struct WindowContext<'a>{ mouse_pos:glam::DVec2, screen_size:glam::UVec2, window:&'a winit::window::Window, - physics_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<PhysicsWorkerInstruction,SessionTimeInner>>, + physics_thread:crate::compat_worker::QNWorker<'a,TimedInstruction<PhysicsWorkerInstruction,SessionTime>>, } impl WindowContext<'_>{ @@ -223,7 +223,7 @@ impl WindowContext<'_>{ pub fn worker<'a>( window:&'a winit::window::Window, setup_context:crate::setup::SetupContext<'a>, -)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTimeInner>>{ +)->crate::compat_worker::QNWorker<'a,TimedInstruction<Instruction,SessionTime>>{ // WindowContextSetup::new #[cfg(feature="user-install")] let directories=Directories::user().unwrap(); @@ -252,7 +252,7 @@ pub fn worker<'a>( }; //WindowContextSetup::into_worker - crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTimeInner>|{ + crate::compat_worker::QNWorker::new(move |ins:TimedInstruction<Instruction,SessionTime>|{ match ins.instruction{ Instruction::WindowEvent(window_event)=>{ window_context.window_event(ins.time,window_event);