diff --git a/lib/common/src/instruction.rs b/lib/common/src/instruction.rs index cefc580..d1d6e36 100644 --- a/lib/common/src/instruction.rs +++ b/lib/common/src/instruction.rs @@ -6,16 +6,32 @@ pub struct TimedInstruction{ pub instruction:I, } -pub trait InstructionEmitter{ - type Instruction; +/// Ensure all emitted instructions are processed before consuming external instructions +pub trait InstructionEmitter{ type TimeInner; - fn next_instruction(&self,time_limit:Time)->Option>; + fn next_instruction(&self,time_limit:Time)->Option>; } -pub trait InstructionConsumer{ - type Instruction; +/// Apply an atomic state update +pub trait InstructionConsumer{ type TimeInner; - fn process_instruction(&mut self, instruction:TimedInstruction); + fn process_instruction(&mut self,instruction:TimedInstruction); } +/// If the object produces its own instructions, allow exhaustively feeding them back in +pub trait InstructionFeedback:InstructionEmitter+InstructionConsumer + where + Time:Copy, +{ + fn process_exhaustive(&mut self,time_limit:Time){ + while let Some(instruction)=self.next_instruction(time_limit){ + self.process_instruction(instruction); + } + } +} +impl InstructionFeedback for X + where + Time:Copy, + X:InstructionEmitter+InstructionConsumer, +{} //PROPER PRIVATE FIELDS!!! pub struct InstructionCollector{ diff --git a/strafe-client/src/physics.rs b/strafe-client/src/physics.rs index 8f75b92..924954e 100644 --- a/strafe-client/src/physics.rs +++ b/strafe-client/src/physics.rs @@ -9,7 +9,7 @@ use strafesnet_common::gameplay_attributes::{self,CollisionAttributesId}; use strafesnet_common::gameplay_modes::{self,StageId}; use strafesnet_common::gameplay_style::{self,StyleModifiers}; use strafesnet_common::controls_bitflag::Controls; -use strafesnet_common::instruction::{self,InstructionEmitter,InstructionConsumer,TimedInstruction}; +use strafesnet_common::instruction::{self,InstructionEmitter,InstructionConsumer,InstructionFeedback,TimedInstruction}; use strafesnet_common::integer::{self,vec3,mat3,Planar64,Planar64Vec3,Planar64Mat3,Angle32,Ratio64Vec2}; pub use strafesnet_common::physics::{Time,TimeInner}; use gameplay::ModeState; @@ -935,16 +935,21 @@ pub struct PhysicsContext{ state:PhysicsState,//this captures the entire state of the physics. data:PhysicsData,//data currently loaded into memory which is needded for physics to run, but is not part of the state. } -//the physics consumes the generic PhysicsInstruction, but can only emit the more narrow PhysicsInternalInstruction -impl instruction::InstructionConsumer for PhysicsContext{ - type Instruction=PhysicsInstruction; +// the physics consumes both PhysicsInputInstruction and PhysicsInternalInstruction, +// but can only emit PhysicsInternalInstruction +impl InstructionConsumer for PhysicsContext{ type TimeInner=TimeInner; - fn process_instruction(&mut self,ins:TimedInstruction){ - atomic_state_update(&mut self.state,&self.data,ins) + fn process_instruction(&mut self,ins:TimedInstruction){ + atomic_internal_instruction(&mut self.state,&self.data,ins) } } -impl instruction::InstructionEmitter for PhysicsContext{ - type Instruction=PhysicsInternalInstruction; +impl InstructionConsumer for PhysicsContext{ + type TimeInner=TimeInner; + fn process_instruction(&mut self,ins:TimedInstruction){ + atomic_input_instruction(&mut self.state,&self.data,ins) + } +} +impl InstructionEmitter for PhysicsContext{ type TimeInner=TimeInner; //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>{ @@ -1104,24 +1109,9 @@ impl PhysicsContext{ println!("Physics Objects: {}",model_count); } - //tickless gaming - fn run_internal_exhaustive(&mut self,time_limit:Time){ - //prepare is ommitted - everything is done via instructions. - while let Some(instruction)=self.next_instruction(time_limit){//collect - //process - self.process_instruction(TimedInstruction{ - time:instruction.time, - instruction:PhysicsInstruction::Internal(instruction.instruction), - }); - //write hash lol - } - } pub fn run_input_instruction(&mut self,instruction:TimedInstruction){ - self.run_internal_exhaustive(instruction.time); - self.process_instruction(TimedInstruction{ - time:instruction.time, - instruction:PhysicsInstruction::Input(instruction.instruction), - }); + self.process_exhaustive(instruction.time); + self.process_instruction(instruction); } } @@ -1881,26 +1871,6 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI } } - fn atomic_state_update(state:&mut PhysicsState,data:&PhysicsData,ins:TimedInstruction){ - match &ins.instruction{ - PhysicsInstruction::Input(PhysicsInputInstruction::Idle) - |PhysicsInstruction::Input(PhysicsInputInstruction::SetNextMouse(_)) - |PhysicsInstruction::Input(PhysicsInputInstruction::ReplaceMouse(_,_)) - |PhysicsInstruction::Internal(PhysicsInternalInstruction::StrafeTick) - |PhysicsInstruction::Internal(PhysicsInternalInstruction::ReachWalkTargetVelocity)=>(), - _=>println!("{}|{:?}",ins.time,ins.instruction), - } - if ins.time(), - PhysicsInstruction::Internal(instruction)=>atomic_internal_instruction(state,data,TimedInstruction{time:ins.time,instruction}), - PhysicsInstruction::Input(instruction)=>atomic_input_instruction(state,data,TimedInstruction{time:ins.time,instruction}), - } - } - #[cfg(test)] mod test{ use strafesnet_common::integer::{vec3::{self,int as int3},mat3};