aboutsummaryrefslogtreecommitdiff
path: root/simloop/src
diff options
context:
space:
mode:
Diffstat (limited to 'simloop/src')
-rw-r--r--simloop/src/simloop.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/simloop/src/simloop.c b/simloop/src/simloop.c
index aa2b6b7..606f5ed 100644
--- a/simloop/src/simloop.c
+++ b/simloop/src/simloop.c
@@ -19,6 +19,7 @@ Simloop simloop_make(const SimloopArgs* args) {
19 .last_step = args->timer->start_time}, 19 .last_step = args->timer->start_time},
20 .timer = args->timer, 20 .timer = args->timer,
21 .first_iter = true, 21 .first_iter = true,
22 .updates_since_last_render = false,
22 }; 23 };
23} 24}
24 25
@@ -57,11 +58,19 @@ void simloop_update(Simloop* sim, SimloopOut* out) {
57 assert(sim); 58 assert(sim);
58 assert(out); 59 assert(out);
59 60
60 out->should_update = step_update(sim, &sim->update); 61 // Simulation update.
61 out->should_render = 62 const bool updated = step_update(sim, &sim->update);
62 step_render(sim, &sim->render) || 63 out->should_update = updated;
64 sim->updates_since_last_render = sim->updates_since_last_render || updated;
65 // Simulation render.
66 const bool rendered =
67 (sim->updates_since_last_render && step_render(sim, &sim->render)) ||
63 (sim->first_iter); // Trigger an initial render on the first frame. 68 (sim->first_iter); // Trigger an initial render on the first frame.
64 sim->frame += (out->should_update ? 1 : 0); 69 out->should_render = rendered;
70 sim->updates_since_last_render =
71 sim->updates_since_last_render && !out->should_render;
72 // Loop state update.
73 sim->frame += (updated ? 1 : 0);
65 sim->first_iter = false; 74 sim->first_iter = false;
66 out->frame = sim->frame; 75 out->frame = sim->frame;
67 out->render_elapsed = time_elapsed(sim, sim->render.last_step); 76 out->render_elapsed = time_elapsed(sim, sim->render.last_step);