FramePacer Class
Controls and maintains a target frame rate through precise timing and pacing. More...
Declaration
Public Member Functions Index
| void | setTargetFps (float fps) |
|
Sets the desired target frame rate. More... | |
| float | getTargetFps () const noexcept |
|
Retrieves the current target frame rate. More... | |
| void | beginFrame () |
|
Marks the beginning of a new frame. More... | |
| FrameStats | sync () |
|
Synchronizes frame timing and returns frame statistics. More... | |
Private Member Attributes Index
| helios::engine::util::time::Stopwatch | stopwatch_ {} |
|
The stopwatch used for high-resolution time measurement. More... | |
| float | targetFps_ = 0.0f |
|
The target frame rate in Frames Per Second (FPS). More... | |
Description
Controls and maintains a target frame rate through precise timing and pacing.
The FramePacer class utilizes a Stopwatch to measure frame execution time and introduces necessary sleep delays to maintain a consistent target frame rate. It returns detailed timing statistics via the FrameStats structure upon synchronization.
The pacing mechanism helps in achieving smoother frame delivery by minimizing jitter, although strict adherence depends on the OS scheduler's precision.
If targetFps is set to 0.0f, no frame pacing is performed, and frames run as fast as the hardware and OS allow (unlocked framerate).
- Usage Example:
Definition at line 46 of file FramePacer.ixx.
Public Member Functions
beginFrame()
| inline |
Marks the beginning of a new frame.
Starts the internal stopwatch to begin measuring the frame's work time. This method must be called at the very beginning of each frame cycle, before any game logic, physics, or rendering operations.
Definition at line 91 of file FramePacer.ixx.
Reference helios::engine::util::time::Stopwatch::start.
getTargetFps()
| inline noexcept |
Retrieves the current target frame rate.
Returns the frame rate target that has been set for pacing, expressed in Frames Per Second (FPS). If the target frame rate is set to 0.0f, frame pacing is disabled, and the frame rate is unlocked.
- Returns
The target frame rate in FPS.
A return value of 0.0f indicates that the frame pacing mechanism is not active.
Definition at line 80 of file FramePacer.ixx.
setTargetFps()
| inline |
Sets the desired target frame rate.
- Parameters
-
fps The target frame rate in Frames Per Second (FPS). Set to 0.0f to disable pacing (unlocked framerate).
Definition at line 65 of file FramePacer.ixx.
Reference helios::registerComponents.
sync()
| inline |
Synchronizes frame timing and returns frame statistics.
Measures the elapsed work time since beginFrame(). If a target FPS is set and the work time is less than the target frame duration, this method sleeps the current thread to meet the target timing.
- Returns
A FrameStats structure containing the total frame time (including wait), the actual work time (CPU processing), and the wait time (idle).
If targetFps is 0.0f or the frame took longer than the target duration, no sleeping occurs, and waitTime in the returned stats will be 0.0f.
Definition at line 111 of file FramePacer.ixx.
References helios::engine::util::time::Stopwatch::elapsedSeconds and helios::registerComponents.
Private Member Attributes
stopwatch_
|
The stopwatch used for high-resolution time measurement.
Definition at line 50 of file FramePacer.ixx.
targetFps_
|
The target frame rate in Frames Per Second (FPS).
Definition at line 55 of file FramePacer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.