Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::FrameMetrics Class Reference

Durations of the last frames, and the frame rate they make. More...

#include <aegis2d/render/metrics_overlay.hpp>

Public Types

using Clock = std::chrono::steady_clock
 Clock of tick().
 

Public Member Functions

void tick (Clock::time_point now) noexcept
 Records the frame that ends at now: the time since the previous tick().
 
void record (double seconds) noexcept
 Records a frame of a given duration; the oldest one is dropped when full.
 
void clear () noexcept
 Forgets every frame and the last tick().
 
std::size_t size () const noexcept
 Number of frames kept.
 
double frame_ms (std::size_t index) const
 Duration of a frame kept.
 
double last_ms () const noexcept
 Duration of the newest frame.
 
double average_ms () const noexcept
 Mean duration of the frames kept.
 
double worst_ms () const noexcept
 Longest of the frames kept.
 
double fps () const noexcept
 Frames per second over the last second.
 

Static Public Attributes

static constexpr std::size_t capacity = 120
 Number of frames kept: two seconds at 60 frames per second.
 

Detailed Description

Durations of the last frames, and the frame rate they make.

The game calls tick() once a frame; the metrics keep the last capacity frames, oldest first.

Member Typedef Documentation

◆ Clock

using aegis2d::render::FrameMetrics::Clock = std::chrono::steady_clock

Clock of tick().

Member Function Documentation

◆ average_ms()

double aegis2d::render::FrameMetrics::average_ms ( ) const
noexcept

Mean duration of the frames kept.

Returns
In milliseconds; 0 without any frame.

◆ clear()

void aegis2d::render::FrameMetrics::clear ( )
noexcept

Forgets every frame and the last tick().

◆ fps()

double aegis2d::render::FrameMetrics::fps ( ) const
noexcept

Frames per second over the last second.

Returns
The newest frames that make up one second (all of them if they make less), divided by their total duration; 0 without any frame or time.

◆ frame_ms()

double aegis2d::render::FrameMetrics::frame_ms ( std::size_t  index) const

Duration of a frame kept.

Parameters
index0 for the oldest, size() - 1 for the newest.
Returns
Its duration in milliseconds.
Exceptions
std::out_of_rangeif index is not below size().

◆ last_ms()

double aegis2d::render::FrameMetrics::last_ms ( ) const
noexcept

Duration of the newest frame.

Returns
In milliseconds; 0 without any frame.

◆ record()

void aegis2d::render::FrameMetrics::record ( double  seconds)
noexcept

Records a frame of a given duration; the oldest one is dropped when full.

Parameters
secondsDuration of the frame; a negative or not finite one counts as 0.

◆ size()

std::size_t aegis2d::render::FrameMetrics::size ( ) const
noexcept

Number of frames kept.

Returns
From 0 to capacity.

◆ tick()

void aegis2d::render::FrameMetrics::tick ( Clock::time_point  now)
noexcept

Records the frame that ends at now: the time since the previous tick().

The first call only starts counting.

Parameters
nowTime of the call, such as Clock::now().

◆ worst_ms()

double aegis2d::render::FrameMetrics::worst_ms ( ) const
noexcept

Longest of the frames kept.

Returns
In milliseconds; 0 without any frame.

Member Data Documentation

◆ capacity

constexpr std::size_t aegis2d::render::FrameMetrics::capacity = 120
staticconstexpr

Number of frames kept: two seconds at 60 frames per second.


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