Minor - Adds target FPS control to engine settings - V14.5.0

Adds functionality to control the target FPS of the engine via the ImGui settings panel.

This includes:
- Adding target FPS variables and accessors in the application class.
- Adding a set_target_fps function to the fps_limiter class.
- Updating the ImGui engine settings panel to include a target FPS setting.
- Modifying the main loop to make use of the fps limiter and the engine target FPS.
This commit is contained in:
2025-10-01 16:58:37 +02:00
parent 0e41fb0ec9
commit 389cde97c2
8 changed files with 88 additions and 60 deletions

View File

@@ -3,11 +3,9 @@
class fps_limiter {
public:
/**
* Builder for fps_limiter class
* This class is used to limit the execution rate of a loop based on a target frames per second (FPS).
* @param target_fps Target frames per second for the limiter. The default is 60.0f FPS.
* Constructor for fps_limiter class
* @param target_fps Target frames per second for the limiter. Default is 60.0f FPS.
*/
explicit fps_limiter(const float target_fps = 60.0f)
: min_delta_(1.0f / target_fps), last_time_(std::chrono::high_resolution_clock::now()) {}
@@ -25,7 +23,17 @@ public:
return false;
}
/**
* Dynamically set the target FPS limit.
* @param target_fps New target frames per second.
*/
void set_target_fps(float target_fps) {
if (target_fps > 0.0f) {
min_delta_ = 1.0f / target_fps;
}
}
private:
float min_delta_;
std::chrono::high_resolution_clock::time_point last_time_;
};
float min_delta_; // Minimum time in seconds between frames
std::chrono::high_resolution_clock::time_point last_time_; // Time point of last allowed execution
};