From 6482f3995baf9515158d999db925ef35158cfba5 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 2 May 2026 14:35:43 -0700 Subject: Throttle rendering to reduce CPU usage --- simloop/include/simloop.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'simloop/include/simloop.h') 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 @@ #include -typedef uint64_t simloop_time_t; +typedef uint64_t simloop_time_t; ///< Time delta in nanoseconds. typedef struct SimloopArgs { int update_fps; ///< Update frame rate. Must be >0. @@ -11,13 +11,12 @@ typedef struct SimloopArgs { typedef struct SimloopOut { uint64_t frame; ///< Frame counter. - 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. - 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. + simloop_time_t throttle; ///< Render throttle if max render fps is given. + double percent_frame; ///< Percent progress between this frame and + ///< the next. Used for smooth animation. + bool should_update; ///< Whether the simulation should update. } SimloopOut; typedef struct SimloopTimeline { @@ -26,12 +25,10 @@ typedef struct SimloopTimeline { } SimloopTimeline; typedef struct Simloop { - simloop_time_t clock; ///< Tracks simulation time. - uint64_t frame; ///< Frame counter, number of updates done. - SimloopTimeline update; ///< Update timeline. - SimloopTimeline render; ///< Render timeline. - double percent_frame; - bool first_iter; + simloop_time_t clock; ///< Tracks simulation time. + uint64_t frame; ///< Frame counter, number of updates done. + SimloopTimeline update; ///< Update timeline. + simloop_time_t render_ddt; ///< Desired render delta time. } Simloop; /// Create a simulation loop. -- cgit v1.2.3