From c90ed3fb00a55aa4522bbb3d9094be11a65edc0a Mon Sep 17 00:00:00 2001 From: Skye Terran Date: Mon, 9 Aug 2021 21:27:05 -0700 Subject: [PATCH] fixed timing issue --- src/main.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index aa6fc3e..d82b388 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ fn main() { // create a test physics object let mut test_object = PhysicsObject { location: [0.0, 0.0, 100.0], - velocity: [0.0, 0.0, 0.0], + velocity: [0.0, 5.0, 0.0], gravity_enabled: true }; @@ -36,21 +36,20 @@ fn main() { // update if delta_time.as_millis() as u32 >= UPDATE_INTERVAL { update(delta_time, &mut test_object); - - // DEBUG - println!("Time: {}ms | test_object | Location: {:?} | Velocity: {:?}", time.as_millis(), test_object.location, test_object.velocity); - - // keep track of time - time += delta_time; - + // reset the delta time delta_time = Duration::new(0,0); } - // update the time - delta_time += Instant::now().duration_since(start_time); - + // DEBUG + println!("Time: {}s | test_object | Location: {:?} | Velocity: {:?}", time.as_millis() as f32 / 1000.0, test_object.location, test_object.velocity); + display(delta_time, &test_object); + + // update the time + let end_time = Instant::now().duration_since(start_time); + delta_time += end_time; + time += end_time; } }