summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-11-08 12:26:43 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-11-08 12:26:43 +0100
commitcdd75000effac0216588766234cfa5b3e8e304d5 (patch)
tree3832063bf12dae9e8b29c9e787d08dc75a9ba704 /src/main.cpp
parentc5a621b3ebeb180d2181df35038ed856714b64e2 (diff)
Frametime-independent dynamics.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp19
1 files changed, 14 insertions, 5 deletions
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;
}