summaryrefslogtreecommitdiff
path: root/gfx-app/src
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-app/src')
-rw-r--r--gfx-app/src/gfx_app.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/gfx-app/src/gfx_app.c b/gfx-app/src/gfx_app.c
index 2d54e3d..a313ce8 100644
--- a/gfx-app/src/gfx_app.c
+++ b/gfx-app/src/gfx_app.c
@@ -30,15 +30,16 @@ static void loop(GfxApp* app) {
30 assert(app); 30 assert(app);
31 assert(app->window); 31 assert(app->window);
32 32
33 const double min_frame_time = 33 const time_delta min_frame_time =
34 app->max_fps > 0 ? 1.0 / (double)(app->max_fps) : 0.0; 34 app->max_fps > 0 ? sec_to_time_delta(1.0 / (double)(app->max_fps)) : 0;
35 const double update_dt = app->update_delta_time; 35 const time_delta update_dt = sec_to_time_delta(app->update_delta_time);
36 double time = 0.0; 36 time_delta time = 0;
37 double time_budget = 0.0; 37 time_delta time_budget = 0;
38 Timer timer = timer_make(); 38 Timer timer = timer_make();
39 39
40 // Warm up the update to initialize the application's state. 40 // Warm up the update to initialize the application's state.
41 (*app->callbacks.update)(app->app_state, time, update_dt); 41 (*app->callbacks.update)(
42 app->app_state, time_delta_to_sec(time), time_delta_to_sec(update_dt));
42 43
43 // Warm up the rendering before entering the main loop. A renderer can 44 // Warm up the rendering before entering the main loop. A renderer can
44 // compile shaders and do other initialization the first time it renders a 45 // compile shaders and do other initialization the first time it renders a
@@ -49,10 +50,13 @@ static void loop(GfxApp* app) {
49 timer_start(&timer); 50 timer_start(&timer);
50 while (!glfwWindowShouldClose(app->window)) { 51 while (!glfwWindowShouldClose(app->window)) {
51 timer_tick(&timer); 52 timer_tick(&timer);
52 time_budget += time_delta_to_sec(timer.delta_time); 53 time_budget += timer.delta_time;
53 54
54 while (time_budget >= update_dt) { 55 while (time_budget >= update_dt) {
55 (*app->callbacks.update)(app->app_state, time, update_dt); 56 (*app->callbacks.update)(
57 app->app_state, time_delta_to_sec(time),
58 time_delta_to_sec(update_dt));
59
56 time += update_dt; 60 time += update_dt;
57 time_budget -= update_dt; 61 time_budget -= update_dt;
58 } 62 }
@@ -63,7 +67,7 @@ static void loop(GfxApp* app) {
63 67
64 const time_point frame_end = time_now(); 68 const time_point frame_end = time_now();
65 const time_delta frame_time = time_diff(timer.last_tick, frame_end); 69 const time_delta frame_time = time_diff(timer.last_tick, frame_end);
66 if (min_frame_time > 0.0 && frame_time < min_frame_time) { 70 if ((min_frame_time > 0) && (frame_time < min_frame_time)) {
67 time_sleep(min_frame_time - frame_time); 71 time_sleep(min_frame_time - frame_time);
68 } 72 }
69 } 73 }