Commit da5bd9fd authored by Luke Jones's avatar Luke Jones

Fix the timestep for game update properly

parent 55c6bc27
Pipeline #63180579 passed with stages
in 6 minutes and 9 seconds
Subproject commit c6192a8fee8d5fb484b8a103aac37f710b25fa58
Subproject commit 9b14610784eef600d2c3a802b85712de3780466f
......@@ -40,7 +40,7 @@ pub fn player(
world
.entities
.add_part::<Physics>(ent, Physics::new(1.0, 0.2, 0.5));
.add_part::<Physics>(ent, Physics::new(1.0, 0.2, 0.999));
let mut binds = Bindings::new();
binds.initialize();
......
......@@ -90,7 +90,6 @@ pub fn integrate(entity: usize, entities: &mut Entities, dt: f32) {
if let Ok(position) = posmap.get_part_mut(entity) {
// update linear position
position.pos += velocity.vel * dt;
//*position += *velocity * dt + physics.acceleration * dt * dt * 0.5;
};
if let Ok(velocity) = vmap.get_part_mut(entity) {
......
......@@ -43,7 +43,12 @@ impl<'surface> Game<'surface> {
.build()
.unwrap();
let canvas = window.into_canvas().accelerated().build().unwrap();
let canvas = window
.into_canvas()
.accelerated()
.present_vsync()
.build()
.unwrap();
let view_width = (y / 3) * 4;
let view_x = (x - view_width) / 2;
......
......@@ -48,8 +48,7 @@ pub fn main() {
let mut game = game::Game::new(&mut sdl_ctx, 1600, 1200);
const FPS: u128 = 1000 / 60; //FPS 60
const MS_PER_UPDATE: f32 = 2.0;
const MS_PER_UPDATE: f32 = 4.0;
let mut last_tick = timer.ticks();
let mut this_tick;
let mut lag = 0.0;
......@@ -64,10 +63,10 @@ pub fn main() {
last_tick = this_tick;
while lag >= MS_PER_UPDATE {
// between 0.001 and 0.005
game.update(lag * 0.01);
game.update(MS_PER_UPDATE * 0.01);
lag -= MS_PER_UPDATE;
}
game.render(lag);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment