RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Time::FrameTimer Class Reference

Measures the frames of a game or render loop, and can cap the frame rate. More...

#include <RST/time/FrameTimer.hpp>

Public Types

using Clock = std::chrono::steady_clock
 

Public Member Functions

 FrameTimer (std::uint32_t targetFps=0) noexcept
 Starts timing; targetFps caps the frame rate, 0 means no cap.
 
void tick () noexcept
 Ends a frame, after sleeping until the target frame time if there is one.
 
double getDeltaTime () const noexcept
 Seconds between the last two ticks.
 
double getCurrentFps () const noexcept
 
double getAverageFps () const noexcept
 Frame rate smoothed over the recent frames.
 
std::uint64_t getFrameCount () const noexcept
 
double getTotalTime () const noexcept
 Seconds from construction to the last tick.
 
void setTargetFps (std::uint32_t targetFps) noexcept
 
std::uint32_t getTargetFps () const noexcept
 

Detailed Description

Measures the frames of a game or render loop, and can cap the frame rate.

while (running) {
frames.tick();
update(frames.getDeltaTime());
}
Measures the frames of a game or render loop, and can cap the frame rate.
Definition FrameTimer.hpp:16

Member Typedef Documentation

◆ Clock

using RST::Time::FrameTimer::Clock = std::chrono::steady_clock

Constructor & Destructor Documentation

◆ FrameTimer()

RST::Time::FrameTimer::FrameTimer ( std::uint32_t  targetFps = 0)
explicitnoexcept

Starts timing; targetFps caps the frame rate, 0 means no cap.

Member Function Documentation

◆ tick()

void RST::Time::FrameTimer::tick ( )
noexcept

Ends a frame, after sleeping until the target frame time if there is one.

◆ getDeltaTime()

double RST::Time::FrameTimer::getDeltaTime ( ) const
inlinenoexcept

Seconds between the last two ticks.

◆ getCurrentFps()

double RST::Time::FrameTimer::getCurrentFps ( ) const
inlinenoexcept

◆ getAverageFps()

double RST::Time::FrameTimer::getAverageFps ( ) const
inlinenoexcept

Frame rate smoothed over the recent frames.

◆ getFrameCount()

std::uint64_t RST::Time::FrameTimer::getFrameCount ( ) const
inlinenoexcept

◆ getTotalTime()

double RST::Time::FrameTimer::getTotalTime ( ) const
inlinenoexcept

Seconds from construction to the last tick.

◆ setTargetFps()

void RST::Time::FrameTimer::setTargetFps ( std::uint32_t  targetFps)
noexcept

◆ getTargetFps()

std::uint32_t RST::Time::FrameTimer::getTargetFps ( ) const
inlinenoexcept

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