From 896a6ef5959043db5463637d84ed524ae7bade1e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 11 Apr 2026 16:35:25 -0700 Subject: Render only if there was an update --- simloop/src/simloop.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'simloop/src') 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) { .last_step = args->timer->start_time}, .timer = args->timer, .first_iter = true, + .updates_since_last_render = false, }; } @@ -57,11 +58,19 @@ void simloop_update(Simloop* sim, SimloopOut* out) { assert(sim); assert(out); - out->should_update = step_update(sim, &sim->update); - out->should_render = - step_render(sim, &sim->render) || + // Simulation update. + const bool updated = step_update(sim, &sim->update); + out->should_update = updated; + sim->updates_since_last_render = sim->updates_since_last_render || updated; + // Simulation render. + const bool rendered = + (sim->updates_since_last_render && step_render(sim, &sim->render)) || (sim->first_iter); // Trigger an initial render on the first frame. - sim->frame += (out->should_update ? 1 : 0); + out->should_render = rendered; + sim->updates_since_last_render = + sim->updates_since_last_render && !out->should_render; + // Loop state update. + sim->frame += (updated ? 1 : 0); sim->first_iter = false; out->frame = sim->frame; out->render_elapsed = time_elapsed(sim, sim->render.last_step); -- cgit v1.2.3