Khaotic Engine Reborn
Loading...
Searching...
No Matches
fps_limiter Class Reference

Public Member Functions

 fps_limiter (const float target_fps=60.0f)
 
bool should_run ()
 

Detailed Description

Definition at line 4 of file fps_limiter.h.

Constructor & Destructor Documentation

◆ fps_limiter()

fps_limiter::fps_limiter ( const float target_fps = 60.0f)
inlineexplicit

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).

Parameters
target_fpsTarget frames per second for the limiter. The default is 60.0f FPS.

Definition at line 12 of file fps_limiter.h.

13 : min_delta_(1.0f / target_fps), last_time_(std::chrono::high_resolution_clock::now()) {}

Member Function Documentation

◆ should_run()

bool fps_limiter::should_run ( )
inline

Function to check if enough time has passed since the last execution.

Returns
True if the time since the last call is greater than or equal to the minimum delta time, otherwise false.

Definition at line 19 of file fps_limiter.h.

19 {
20 const auto now = std::chrono::high_resolution_clock::now();
21 if (const float elapsed = std::chrono::duration<float>(now - last_time_).count(); elapsed >= min_delta_) {
22 last_time_ = now;
23 return true;
24 }
25 return false;
26 }

The documentation for this class was generated from the following file: