From cdd75000effac0216588766234cfa5b3e8e304d5 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 8 Nov 2017 12:26:43 +0100 Subject: Frametime-independent dynamics. --- src/main.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 1059cb6..f6a2de5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,8 @@ int main() render::state_t render(&window); game::state_t game; interface::state_t interface(&window, &game); + size_t frame = 0; + double before = NAN; window.setVerticalSyncEnabled(false); @@ -29,21 +31,28 @@ int main() game.start(); while (1) { - double now = (nano_clock() - t0) * 1.0e-9; + double now = (nano_clock() - t0) * 1.0e-9, dt; - game.tick(now); - interface.tick(); + if (frame) + dt = now - before; + else + dt = 0.01; + + game.tick(now, dt); + interface.tick(dt); if (!window.isOpen()) break; window.clear(); - render.begin_frame(now); + render.begin_frame(now, dt); render.render(&game); interface.render_to(&render); render.end_frame(); + + before = now; + frame++; } game.stop(); - return 0; } -- cgit