FramePacer.ixx File
Module defining the FramePacer class for frame rate control and timing synchronization. More...
Included Headers
#include <memory>
#include <thread>
#include <chrono>
#include <cassert>
#include <helios.engine.tooling.FrameStats>
#include <helios.engine.util.time.Stopwatch>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | tooling |
Classes Index
| class | FramePacer |
|
Controls and maintains a target frame rate through precise timing and pacing. More... | |
Description
Module defining the FramePacer class for frame rate control and timing synchronization.
File Listing
The file content with the documentation metadata removed is:
17export namespace helios::engine::tooling {
46 class FramePacer {
50 helios::engine::util::time::Stopwatch stopwatch_{};
65 void setTargetFps(float fps) {
66 targetFps_ = fps;
80 [[nodiscard]] float getTargetFps() const noexcept {
91 void beginFrame() {
92 stopwatch_.start();
111 [[nodiscard]] FrameStats sync() {
112 float workTime = stopwatch_.elapsedSeconds();
118 float targetTime = 1.0f / targetFps_;
119 if (targetTime > workTime) {
120 auto requestedWaitTime = targetTime - workTime;
121 auto sleepDuration = std::chrono::duration<float>(requestedWaitTime);
122 std::this_thread::sleep_for(sleepDuration);
123 totalTime = stopwatch_.elapsedSeconds();
128 return FrameStats{ totalTime, workTime, waitTime };
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.