diff options
| author | 3gg <3gg@shellblade.net> | 2026-04-20 18:03:09 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-04-20 18:03:09 -0700 |
| commit | dadaf61c45d675f0e8b88fbc231748ad8247a736 (patch) | |
| tree | e37af6f9accaa6b68ab76344ee4caa0ef6056a5d /simloop/include/simloop.h | |
| parent | 5125d6788f7765a14fbcdeb6d4f6f67742c98596 (diff) | |
Percent frame interpolation factor for smooth animation
Diffstat (limited to 'simloop/include/simloop.h')
| -rw-r--r-- | simloop/include/simloop.h | 17 |
1 files changed, 11 insertions, 6 deletions
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 @@ | |||
| 5 | * simulation must be updated and/or the result rendered. | 5 | * simulation must be updated and/or the result rendered. |
| 6 | * | 6 | * |
| 7 | * The simulation is updated at a fixed time step given a desired frame rate. | 7 | * The simulation is updated at a fixed time step given a desired frame rate. |
| 8 | * Rendering frame rate can likewise be capped or be unlimited. In any case, the | 8 | * Rendering frame rate can likewise be capped or be unlimited. |
| 9 | * loop guarantees that the same frame is not rendered twice. | 9 | * In any case, an interpolation factor is computed for smooth animation between |
| 10 | * updates. | ||
| 11 | * The implementation also guarantees that the same frame is not rendered twice | ||
| 12 | * if time does not advance. | ||
| 10 | * | 13 | * |
| 11 | * Generally, the simulation's update logic should be able to keep up with the | 14 | * Generally, the simulation's update logic should be able to keep up with the |
| 12 | * requested frame rate; it is the application's responsibility to ensure this. | 15 | * requested frame rate; it is the application's responsibility to ensure this. |
| 13 | * Should the update logic not be able to keep up, then the loop requests a | 16 | * Should the update logic not be able to keep up, then the loop requests a |
| 14 | * single update per iteration, effectively "degrading" to match the update | 17 | * single update per iteration, effectively "degrading" to match the update |
| 15 | * logic frame rate, and giving the update logic a chance to catch up with | 18 | * logic frame rate, giving the update logic a chance to catch up with |
| 16 | * subsequent loop iterations. | 19 | * subsequent loop iterations. |
| 17 | * | 20 | * |
| 18 | * Under a variable time delta, the loop could simply update the simulation | 21 | * Under a variable time delta, the loop could simply update the simulation |
| @@ -57,8 +60,10 @@ typedef struct SimloopOut { | |||
| 57 | simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. | 60 | simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. |
| 58 | simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. | 61 | simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. |
| 59 | simloop_time_t update_dt; ///< Delta time for simulation updates. | 62 | simloop_time_t update_dt; ///< Delta time for simulation updates. |
| 60 | bool should_update; ///< Whether the simulation should update. | 63 | double percent_frame; ///< Percent progress between this frame and |
| 61 | bool should_render; ///< Whether the simulation should be rendered. | 64 | ///< the next. Used for smooth animation. |
| 65 | bool should_update; ///< Whether the simulation should update. | ||
| 66 | bool should_render; ///< Whether the simulation should be rendered. | ||
| 62 | } SimloopOut; | 67 | } SimloopOut; |
| 63 | 68 | ||
| 64 | typedef struct SimloopTimeline { | 69 | typedef struct SimloopTimeline { |
| @@ -71,8 +76,8 @@ typedef struct Simloop { | |||
| 71 | uint64_t frame; ///< Frame counter, number of updates done. | 76 | uint64_t frame; ///< Frame counter, number of updates done. |
| 72 | SimloopTimeline update; ///< Update timeline. | 77 | SimloopTimeline update; ///< Update timeline. |
| 73 | SimloopTimeline render; ///< Render timeline. | 78 | SimloopTimeline render; ///< Render timeline. |
| 79 | double percent_frame; | ||
| 74 | bool first_iter; | 80 | bool first_iter; |
| 75 | bool updates_since_last_render; | ||
| 76 | } Simloop; | 81 | } Simloop; |
| 77 | 82 | ||
| 78 | /// Create a simulation loop. | 83 | /// Create a simulation loop. |
