diff --git a/src/body.rs b/src/body.rs index f3f1d1f..60aeb5f 100644 --- a/src/body.rs +++ b/src/body.rs @@ -1,5 +1,12 @@ use crate::event::EventStruct; +pub enum PhysicsEvent { + CollisionStart(RelativeCollision), + CollisionEnd(RelativeCollision), + StrafeTick, + Jump, +} + pub struct Body { pub position: glam::Vec3,//I64 where 2^32 = 1 u pub velocity: glam::Vec3,//I64 where 2^32 = 1 u/s @@ -206,28 +213,28 @@ impl PhysicsState { self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32) } - fn next_strafe_event(&self) -> Option { + fn next_strafe_event(&self) -> Option> { return Some(EventStruct{ time:(self.time*self.strafe_tick_num/self.strafe_tick_den+1)*self.strafe_tick_den/self.strafe_tick_num, - event:crate::event::EventEnum::StrafeTick + event:PhysicsEvent::StrafeTick }); } - fn next_walk_event(&self) -> Option { + fn next_walk_event(&self) -> Option> { //check if you are accelerating towards a walk target velocity and create an event 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::EventTrait for PhysicsState { +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 { + fn next_event(&self) -> Option> { //JUST POLLING!!! NO MUTATION let mut best = crate::event::EventCollector::new(); //autohop (already pressing spacebar; the signal to begin trying to jump is different) @@ -235,7 +242,7 @@ impl crate::event::EventTrait for PhysicsState { //scroll will be implemented with InputEvent::Jump(true) but it blocks setting self.jump_trying=true best.collect(Some(EventStruct{ time:self.time, - event:crate::event::EventEnum::Jump + event:PhysicsEvent::Jump })); } //check for collision stop events with curent contacts diff --git a/src/event.rs b/src/event.rs index 37fcf30..893039f 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,29 +1,22 @@ -pub struct EventStruct { +pub struct EventStruct { pub time: crate::body::TIME, - pub event: EventEnum, + pub event: E, } -pub enum EventEnum { - CollisionStart(crate::body::RelativeCollision),//Body::CollisionStart - CollisionEnd(crate::body::RelativeCollision),//Body::CollisionEnd - StrafeTick, - Jump, -} - -pub trait EventTrait { - fn next_event(&self) -> Option; +pub trait EventEmitter { + fn next_event(&self) -> Option>; } //PROPER PRIVATE FIELDS!!! -pub struct EventCollector { - event: Option, +pub struct EventCollector { + event: Option>, } -impl EventCollector { +impl EventCollector { pub fn new() -> Self { Self{event:None} } - pub fn collect(&mut self,test_event:Option){ + 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 (), } } - pub fn event(self) -> Option { + pub fn event(self) -> Option> { //STEAL EVENT AND DESTROY EVENTCOLLECTOR return self.event }