wip tickless events

This commit is contained in:
Quaternions 2023-09-07 18:35:49 -07:00
parent 6cfdb495ae
commit 9428929a99
3 changed files with 19 additions and 4 deletions

View File

@ -19,6 +19,7 @@ pub type TIMESTAMP = i64;
const CONTROL_JUMP:u32 = 0b01000000;//temp const CONTROL_JUMP:u32 = 0b01000000;//temp
impl PhysicsState { impl PhysicsState {
//delete this, we are tickless gamers
pub fn run(&mut self, time: TIMESTAMP, control_dir: glam::Vec3, controls: u32){ pub fn run(&mut self, time: TIMESTAMP, control_dir: glam::Vec3, controls: u32){
let target_tick = (time/10_000_000) as u32;//100t let target_tick = (time/10_000_000) as u32;//100t
//the game code can run for 1 month before running out of ticks //the game code can run for 1 month before running out of ticks
@ -55,8 +56,19 @@ impl PhysicsState {
self.body.time=target_tick as TIMESTAMP*10_000_000; self.body.time=target_tick as TIMESTAMP*10_000_000;
} }
//delete this
pub fn extrapolate_position(&self, time: TIMESTAMP) -> glam::Vec3 { pub fn extrapolate_position(&self, time: TIMESTAMP) -> glam::Vec3 {
let dt=(time-self.body.time) as f64/1_000_000_000f64; let dt=(time-self.body.time) as f64/1_000_000_000f64;
self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32) self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32)
} }
} }
impl crate::event::EventTrait for PhysicsState {
fn next_event(&self) -> Option<crate::event::EventEnum> {
//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
//check to see when the next strafe tick is
None
}
}

View File

@ -1,8 +1,10 @@
enum EventEnum { pub enum EventEnum {
//Body::CollisionStart CollisionStart(crate::body::TIMESTAMP),//,Collideable),//Body::CollisionStart
//Body::CollisionEnd CollisionEnd(crate::body::TIMESTAMP),//,Collideable),//Body::CollisionEnd
StrafeTick(crate::body::TIMESTAMP),
Jump(crate::body::TIMESTAMP),
} }
pub trait EventTrait { pub trait EventTrait {
fn next_event() -> EventEnum; fn next_event(&self) -> Option<EventEnum>;
} }

View File

@ -1,2 +1,3 @@
pub mod framework; pub mod framework;
pub mod body; pub mod body;
pub mod event;