can't stand the idea of 10 nanoseconds less than 66 ticks per second

This commit is contained in:
Quaternions 2023-09-08 12:27:45 -07:00
parent 6caa273623
commit 54bf0358d6
2 changed files with 7 additions and 5 deletions

View File

@ -10,7 +10,8 @@ pub struct PhysicsState {
pub body: Body,
//pub contacts: Vec<RelativeCollision>,
pub time: TIME,
pub strafe_tick_period: TIME,
pub strafe_tick_num: TIME,
pub strafe_tick_den: TIME,
pub tick: u32,
pub mv: f32,
pub walkspeed: f32,
@ -26,7 +27,7 @@ const CONTROL_JUMP:u32 = 0b01000000;//temp
impl PhysicsState {
//delete this, we are tickless gamers
pub fn run(&mut self, time: TIME, control_dir: glam::Vec3, controls: u32){
let target_tick = (time/self.strafe_tick_period) as u32;//100t
let target_tick = (time*self.strafe_tick_num/self.strafe_tick_den) as u32;
//the game code can run for 1 month before running out of ticks
while self.tick<target_tick {
self.tick += 1;
@ -58,7 +59,7 @@ impl PhysicsState {
}
}
self.body.time=target_tick as TIME*self.strafe_tick_period;
self.body.time=target_tick as TIME*self.strafe_tick_den/self.strafe_tick_num;
}
//delete this
@ -69,7 +70,7 @@ impl PhysicsState {
fn next_strafe_event(&self) -> Option<EventStruct> {
return Some(EventStruct{
time:(self.time/self.strafe_tick_period+1)*self.strafe_tick_period,
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
});
}

View File

@ -299,7 +299,8 @@ impl strafe_client::framework::Example for Skybox {
},
time: 0,
tick: 0,
strafe_tick_period: 1_000_000_000/100,//100t
strafe_tick_num: 100,//100t
strafe_tick_den: 1_000_000_000,
gravity: glam::Vec3::new(0.0,-100.0,0.0),
friction: 90.0,
mv: 2.7,