diff --git a/src/body.rs b/src/body.rs index 6730de6..5d02a11 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,6 +1,6 @@ -use crate::event::EventStruct; +use crate::instruction::TimedInstruction; -pub enum PhysicsEvent { +pub enum PhysicsInstruction { CollisionStart(RelativeCollision), CollisionEnd(RelativeCollision), StrafeTick, @@ -198,7 +198,7 @@ impl PhysicsState { if applied_friction*applied_friction Option> { - return Some(EventStruct{ + fn next_strafe_instruction(&self) -> Option> { + return Some(TimedInstruction{ time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num, - event:PhysicsEvent::StrafeTick + instruction:PhysicsInstruction::StrafeTick }); } - fn next_walk_event(&self) -> Option> { - //check if you are accelerating towards a walk target velocity and create an event + fn next_walk_instruction(&self) -> Option> { + //check if you are accelerating towards a walk target velocity and create an instruction return None; } - fn predict_collision_end(&self,model:&Model) -> Option> { + fn predict_collision_end(&self,model:&Model) -> Option> { None } - fn predict_collision_start(&self,model:&Model) -> Option> { + fn predict_collision_start(&self,model:&Model) -> Option> { None } } -impl crate::event::EventEmitter for PhysicsState { - //this little next event function can cache its return value and invalidate the cached value by watching the State. - fn next_event(&self) -> Option> { +impl crate::instruction::InstructionEmitter for PhysicsState { + //this little next instruction function can cache its return value and invalidate the cached value by watching the State. + fn next_instruction(&self) -> Option> { //JUST POLLING!!! NO MUTATION - let mut best = crate::event::EventCollector::new(); + let mut best = crate::instruction::InstructionCollector::new(); //autohop (already pressing spacebar; the signal to begin trying to jump is different) if self.grounded&&self.jump_trying { - //scroll will be implemented with InputEvent::Jump(true) but it blocks setting self.jump_trying=true - best.collect(Some(EventStruct{ + //scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true + best.collect(Some(TimedInstruction{ time:self.time, - event:PhysicsEvent::Jump + instruction:PhysicsInstruction::Jump })); } - //check for collision stop events with curent contacts + //check for collision stop instructions with curent contacts for collision_data in self.contacts.iter() { best.collect(self.predict_collision_end(self.models_cringe_clone.get(collision_data.model as usize).unwrap())); } - //check for collision start events (against every part in the game with no optimization!!) + //check for collision start instructions (against every part in the game with no optimization!!) for model in &self.models_cringe_clone { best.collect(self.predict_collision_start(model)); } if self.grounded { //walk maintenance - best.collect(self.next_walk_event()); + best.collect(self.next_walk_instruction()); }else{ //check to see when the next strafe tick is - best.collect(self.next_strafe_event()); + best.collect(self.next_strafe_instruction()); } - best.event() + best.instruction() } } -impl crate::event::EventConsumer for PhysicsState { - fn process_event(&mut self, event:EventStruct) { +impl crate::instruction::InstructionConsumer for PhysicsState { + fn process_instruction(&mut self, instruction:TimedInstruction) { // } } \ No newline at end of file diff --git a/src/event.rs b/src/event.rs index 11e48e3..f45efe9 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,37 +1,37 @@ -pub struct EventStruct { +pub struct TimedInstruction { pub time: crate::body::TIME, - pub event: E, + pub instruction: I, } -pub trait EventEmitter { - fn next_event(&self) -> Option>; +pub trait InstructionEmitter { + fn next_instruction(&self) -> Option>; } -pub trait EventConsumer { - fn process_event(&mut self, event:EventStruct); +pub trait InstructionConsumer { + fn process_instruction(&mut self, instruction:TimedInstruction); } //PROPER PRIVATE FIELDS!!! -pub struct EventCollector { - event: Option>, +pub struct InstructionCollector { + instruction: Option>, } -impl EventCollector { +impl InstructionCollector { pub fn new() -> Self { - Self{event:None} + Self{instruction:None} } - pub fn collect(&mut self,test_event:Option>){ - match &test_event { - Some(unwrap_test_event) => match &self.event { - Some(unwrap_best_event) => if unwrap_test_event.time>){ + match &instruction { + Some(unwrap_instruction) => match &self.instruction { + Some(unwrap_best_instruction) => if unwrap_instruction.time self.event=test_event, + None => self.instruction=instruction, }, None => (), } } - pub fn event(self) -> Option> { - //STEAL EVENT AND DESTROY EVENTCOLLECTOR - return self.event + pub fn instruction(self) -> Option> { + //STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR + return self.instruction } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b229c53..fd9d95a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ pub mod framework; pub mod body; -pub mod event; +pub mod instruction;