nCine::FrameTimer class

Tracks per-frame timing and computes the average FPS and frame time multiplier.

Call AddFrame() once per rendered frame to measure the interval since the previous one. The class derives the last frame duration, a periodically updated average FPS, and a time multiplier (GetTimeMult()) expressing how long the last frame took relative to the nominal frame time, used to keep updates frame-rate independent.

Public static variables

static float FramesPerSecond constexpr
Nominal frames per second.
static float SecondsPerFrame constexpr
Nominal seconds per frame.

Constructors, destructors, conversion operators

FrameTimer(float logInterval, float avgInterval)
Constructor.

Public functions

void AddFrame()
Adds a frame to the counter and calculates the interval since the previous one.
void Suspend()
Starts counting the suspension time.
auto Resume() -> TimeStamp
Drifts the timers by the duration of the last suspension and resumes counting.
auto GetTotalNumberFrames() const -> std::uint32_t
Returns the total number of frames counted.
auto GetLastFrameDuration() const -> float
Returns the duration in seconds between the last two calls to AddFrame().
auto GetFrameDuration() const -> float
Returns the duration in seconds since the last call to AddFrame().
auto GetFrameDurationAsTicks() const -> std::uint64_t
Returns the duration in ticks since the last call to AddFrame().
auto GetAverageFps() const -> float
Returns the average FPS measured over the averaging interval.
auto GetTimeMult() const -> float
Returns the factor expressing how long the last frame took relative to the nominal frame time.

Function documentation

nCine::FrameTimer::FrameTimer(float logInterval, float avgInterval)

Constructor.

Parameters
logInterval Seconds between two logging events
avgInterval Seconds between two average FPS calculations

TimeStamp nCine::FrameTimer::Resume()

Drifts the timers by the duration of the last suspension and resumes counting.

Returns Time stamp holding the duration of the last suspension