diff options
| author | 3gg <3gg@shellblade.net> | 2026-05-02 14:35:43 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2026-05-02 14:35:43 -0700 |
| commit | 6482f3995baf9515158d999db925ef35158cfba5 (patch) | |
| tree | 17d274b78038c7a06ce0afe9f30d7416fa9f07ef /simloop/include | |
| parent | 48422e313b31b79d76dd8f027b4d934994168859 (diff) | |
Throttle rendering to reduce CPU usage
Diffstat (limited to 'simloop/include')
| -rw-r--r-- | simloop/include/simloop.h | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/simloop/include/simloop.h b/simloop/include/simloop.h index 4e3ed20..6a83b23 100644 --- a/simloop/include/simloop.h +++ b/simloop/include/simloop.h | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | #include <stdint.h> | 3 | #include <stdint.h> |
| 4 | 4 | ||
| 5 | typedef uint64_t simloop_time_t; | 5 | typedef uint64_t simloop_time_t; ///< Time delta in nanoseconds. |
| 6 | 6 | ||
| 7 | typedef struct SimloopArgs { | 7 | typedef struct SimloopArgs { |
| 8 | int update_fps; ///< Update frame rate. Must be >0. | 8 | int update_fps; ///< Update frame rate. Must be >0. |
| @@ -11,13 +11,12 @@ typedef struct SimloopArgs { | |||
| 11 | 11 | ||
| 12 | typedef struct SimloopOut { | 12 | typedef struct SimloopOut { |
| 13 | uint64_t frame; ///< Frame counter. | 13 | uint64_t frame; ///< Frame counter. |
| 14 | simloop_time_t render_elapsed; ///< Amount of time elapsed in the rendering. | ||
| 15 | simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. | 14 | simloop_time_t update_elapsed; ///< Amount of time elapsed in the simulation. |
| 16 | simloop_time_t update_dt; ///< Delta time for simulation updates. | 15 | simloop_time_t update_dt; ///< Delta time for simulation updates. |
| 17 | double percent_frame; ///< Percent progress between this frame and | 16 | simloop_time_t throttle; ///< Render throttle if max render fps is given. |
| 18 | ///< the next. Used for smooth animation. | 17 | double percent_frame; ///< Percent progress between this frame and |
| 19 | bool should_update; ///< Whether the simulation should update. | 18 | ///< the next. Used for smooth animation. |
| 20 | bool should_render; ///< Whether the simulation should be rendered. | 19 | bool should_update; ///< Whether the simulation should update. |
| 21 | } SimloopOut; | 20 | } SimloopOut; |
| 22 | 21 | ||
| 23 | typedef struct SimloopTimeline { | 22 | typedef struct SimloopTimeline { |
| @@ -26,12 +25,10 @@ typedef struct SimloopTimeline { | |||
| 26 | } SimloopTimeline; | 25 | } SimloopTimeline; |
| 27 | 26 | ||
| 28 | typedef struct Simloop { | 27 | typedef struct Simloop { |
| 29 | simloop_time_t clock; ///< Tracks simulation time. | 28 | simloop_time_t clock; ///< Tracks simulation time. |
| 30 | uint64_t frame; ///< Frame counter, number of updates done. | 29 | uint64_t frame; ///< Frame counter, number of updates done. |
| 31 | SimloopTimeline update; ///< Update timeline. | 30 | SimloopTimeline update; ///< Update timeline. |
| 32 | SimloopTimeline render; ///< Render timeline. | 31 | simloop_time_t render_ddt; ///< Desired render delta time. |
| 33 | double percent_frame; | ||
| 34 | bool first_iter; | ||
| 35 | } Simloop; | 32 | } Simloop; |
| 36 | 33 | ||
| 37 | /// Create a simulation loop. | 34 | /// Create a simulation loop. |
