From dadaf61c45d675f0e8b88fbc231748ad8247a736 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 20 Apr 2026 18:03:09 -0700 Subject: Percent frame interpolation factor for smooth animation --- simloop/include/simloop.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'simloop/include/simloop.h') diff --git a/simloop/include/simloop.h b/simloop/include/simloop.h index c5a0372..7774c35 100644 --- a/simloop/include/simloop.h +++ b/simloop/include/simloop.h @@ -5,14 +5,17 @@ * simulation must be updated and/or the result rendered. * * The simulation is updated at a fixed time step given a desired frame rate. - * Rendering frame rate can likewise be capped or be unlimited. In any case, the - * loop guarantees that the same frame is not rendered twice. + * Rendering frame rate can likewise be capped or be unlimited. + * In any case, an interpolation factor is computed for smooth animation between + * updates. + * The implementation also guarantees that the same frame is not rendered twice + * if time does not advance. * * Generally, the simulation's update logic should be able to keep up with the * requested frame rate; it is the application's responsibility to ensure this. * Should the update logic not be able to keep up, then the loop requests a * single update per iteration, effectively "degrading" to match the update - * logic frame rate, and giving the update logic a chance to catch up with + * logic frame rate, giving the update logic a chance to catch up with * subsequent loop iterations. * * Under a variable time delta, the loop could simply update the simulation @@ -57,8 +60,10 @@ typedef struct SimloopOut { simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. simloop_time_t update_dt; ///< Delta time for simulation updates. - bool should_update; ///< Whether the simulation should update. - bool should_render; ///< Whether the simulation should be rendered. + double percent_frame; ///< Percent progress between this frame and + ///< the next. Used for smooth animation. + bool should_update; ///< Whether the simulation should update. + bool should_render; ///< Whether the simulation should be rendered. } SimloopOut; typedef struct SimloopTimeline { @@ -71,8 +76,8 @@ typedef struct Simloop { uint64_t frame; ///< Frame counter, number of updates done. SimloopTimeline update; ///< Update timeline. SimloopTimeline render; ///< Render timeline. + double percent_frame; bool first_iter; - bool updates_since_last_render; } Simloop; /// Create a simulation loop. -- cgit v1.2.3