From f41be177dcf5258fb12c993e1f53a6edf22f385e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 7 Sep 2023 20:03:53 -0700 Subject: [PATCH] brainstorm event model --- src/body.rs | 36 ++++++++++++++++++++++++++++++++---- src/event.rs | 15 ++++++++++----- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/body.rs b/src/body.rs index 353dfdd..a382f91 100644 --- a/src/body.rs +++ b/src/body.rs @@ -64,11 +64,39 @@ impl PhysicsState { } impl crate::event::EventTrait for PhysicsState { - fn next_event(&self) -> Option { + //this little next event function can cache its return value and invalidate the cached value by watching the State. + fn next_event(&self) -> Option { + //JUST POLLING!!! NO MUTATION + let mut best_event: Option = None; + let collect_event = |test_event:Option|{ + match test_event { + Some(unwrap_test_event) => match best_event { + Some(unwrap_best_event) => if unwrap_test_event.time best_event=test_event, + }, + None => (), + } + }; + //check to see if yee need to jump (this is not the way lol) + if self.grounded&&self.jump_trying { + //scroll will be implemented with InputEvent::InstantJump rather than InputEvent::Jump(true) + collect_event(Some(crate::event::EventStruct{ + time:self.time, + event:crate::event::EventEnum::Jump + })); + } //check for collision stop events with curent contacts - //check for collision start events against (every part in the ghamemem!!) - //check to see if yee need to jump + for collision_data in self.contacts.iter() { + collect_event(self.model.predict_collision(collision_data.model)); + } + //check for collision start events (against every part in the game with no optimization!!) + for &model in self.world.models { + collect_event(self.model.predict_collision(&model)); + } //check to see when the next strafe tick is - None + collect_event(self.next_strafe_event()); + best_event } } \ No newline at end of file diff --git a/src/event.rs b/src/event.rs index 2fa2a05..6f45098 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,10 +1,15 @@ +pub struct EventStruct { + pub time: crate::body::TIME, + pub event: EventEnum, +} + pub enum EventEnum { - CollisionStart(crate::body::TIMESTAMP),//,Collideable),//Body::CollisionStart - CollisionEnd(crate::body::TIMESTAMP),//,Collideable),//Body::CollisionEnd - StrafeTick(crate::body::TIMESTAMP), - Jump(crate::body::TIMESTAMP), + CollisionStart,//(Collideable),//Body::CollisionStart + CollisionEnd,//(Collideable),//Body::CollisionEnd + StrafeTick, + Jump, } pub trait EventTrait { - fn next_event(&self) -> Option; + fn next_event(&self) -> Option; } \ No newline at end of file