18 using Clock = std::chrono::steady_clock;
21 explicit FrameTimer(std::uint32_t targetFps = 0) noexcept;
27 [[nodiscard]]
double getDeltaTime() const noexcept {
return _deltaTime; }
29 [[nodiscard]]
double getCurrentFps() const noexcept {
return (_deltaTime > 0.0) ? (1.0 / _deltaTime) : 0.0; }
32 [[nodiscard]]
double getAverageFps() const noexcept {
return (_averageFrameTime > 0.0) ? (1.0 / _averageFrameTime) : 0.0; }
34 [[nodiscard]] std::uint64_t
getFrameCount() const noexcept {
return _frameCount; }
37 [[nodiscard]]
double getTotalTime() const noexcept {
return std::chrono::duration<double>(_previousTime - _startTime).count(); }
40 [[nodiscard]] std::uint32_t
getTargetFps() const noexcept {
return _targetFps; }
43 Clock::time_point _startTime;
44 Clock::time_point _previousTime;
45 Clock::duration _targetFrameTime{};
46 double _deltaTime = 0.0;
47 double _averageFrameTime = 0.0;
48 std::uint64_t _frameCount = 0;
49 std::uint32_t _targetFps = 0;
Measures the frames of a game or render loop, and can cap the frame rate.
Definition FrameTimer.hpp:16
void setTargetFps(std::uint32_t targetFps) noexcept
std::chrono::steady_clock Clock
Definition FrameTimer.hpp:18
double getCurrentFps() const noexcept
Definition FrameTimer.hpp:29
double getDeltaTime() const noexcept
Seconds between the last two ticks.
Definition FrameTimer.hpp:27
void tick() noexcept
Ends a frame, after sleeping until the target frame time if there is one.
double getAverageFps() const noexcept
Frame rate smoothed over the recent frames.
Definition FrameTimer.hpp:32
std::uint32_t getTargetFps() const noexcept
Definition FrameTimer.hpp:40
FrameTimer(std::uint32_t targetFps=0) noexcept
Starts timing; targetFps caps the frame rate, 0 means no cap.
std::uint64_t getFrameCount() const noexcept
Definition FrameTimer.hpp:34
double getTotalTime() const noexcept
Seconds from construction to the last tick.
Definition FrameTimer.hpp:37
Stopwatch, frame timing and date formatting.
Definition DateTime.hpp:8