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

Overlay of the frame metrics, for developers: frames per second, frame times, entities, sprites and draw calls of the frame before, the memory of the process, the game's own lines (its network numbers...), and a bar per frame kept. More...

#include <aegis2d/render/metrics_overlay.hpp>

Public Member Functions

 MetricsOverlay (const MetricsOverlayStyle &style={}) noexcept
 Hidden overlay.
 
bool visible () const noexcept
 Tells whether the overlay is shown.
 
void set_visible (bool visible) noexcept
 Shows or hides the overlay.
 
void toggle () noexcept
 Shows the overlay if hidden, hides it if shown.
 
const MetricsOverlayStyle & style () const noexcept
 Where and how the overlay is drawn.
 
FrameStats game_stats (const IRenderer &renderer) const noexcept
 Counters of the renderer's last finished frame, without the overlay.
 
void draw (IRenderer &renderer, const BitmapFont &font, const FrameMetrics &metrics, std::optional< std::size_t > entities=std::nullopt, std::span< const std::string > lines={})
 Draws the overlay, if shown.
 
std::optional< std::size_t > memory () const noexcept
 Memory of the process the overlay shows.
 

Detailed Description

Overlay of the frame metrics, for developers: frames per second, frame times, entities, sprites and draw calls of the frame before, the memory of the process, the game's own lines (its network numbers...), and a bar per frame kept.

Hidden by default. The game calls draw() once every frame, shown or not, so that the counts leave out the overlay's own sprites and draw calls.

// Each frame:
metrics.tick(render::FrameMetrics::Clock::now());
if (keyboard.pressed(platform::Key::F12)) {
overlay.toggle();
}
renderer.begin_frame(background);
// ... the game's sprites ...
overlay.draw(renderer, font, metrics, registry.size());
renderer.end_frame();
Durations of the last frames, and the frame rate they make.
Definition metrics_overlay.hpp:24
void tick(Clock::time_point now) noexcept
Records the frame that ends at now: the time since the previous tick().
Overlay of the frame metrics, for developers: frames per second, frame times, entities,...
Definition metrics_overlay.hpp:136
void toggle() noexcept
Shows the overlay if hidden, hides it if shown.
void draw(IRenderer &renderer, const BitmapFont &font, const FrameMetrics &metrics, std::optional< std::size_t > entities=std::nullopt, std::span< const std::string > lines={})
Draws the overlay, if shown.

Constructor & Destructor Documentation

◆ MetricsOverlay()

aegis2d::render::MetricsOverlay::MetricsOverlay ( const MetricsOverlayStyle &  style = {})
explicitnoexcept

Hidden overlay.

Parameters
styleWhere and how it is drawn.

Member Function Documentation

◆ draw()

void aegis2d::render::MetricsOverlay::draw ( IRenderer &  renderer,
const BitmapFont &  font,
const FrameMetrics &  metrics,
std::optional< std::size_t >  entities = std::nullopt,
std::span< const std::string >  lines = {} 
)

Draws the overlay, if shown.

Parameters
rendererRenderer in a frame.
fontFont of the text.
metricsFrame times.
entitiesNumber of entities, or nothing for a program without any.
linesThe game's own lines, shown under the others: the numbers of its network connection while it has one, for instance.
Exceptions
std::logic_erroroutside a frame (as IRenderer::draw()).

◆ game_stats()

FrameStats aegis2d::render::MetricsOverlay::game_stats ( const IRenderer &  renderer) const
noexcept

Counters of the renderer's last finished frame, without the overlay.

Parameters
rendererRenderer the overlay is drawn with.
Returns
renderer.stats() less the sprites and draw calls of the overlay's last draw().

◆ memory()

std::optional< std::size_t > aegis2d::render::MetricsOverlay::memory ( ) const
noexcept

Memory of the process the overlay shows.

Asked to the system (core::memory_use()) by draw() while shown, at most every half second.

Returns
The bytes, or nothing before the first draw() shown or if the system does not tell.

◆ set_visible()

void aegis2d::render::MetricsOverlay::set_visible ( bool  visible)
noexcept

Shows or hides the overlay.

Parameters
visibletrue to show it.

◆ style()

const MetricsOverlayStyle & aegis2d::render::MetricsOverlay::style ( ) const
noexcept

Where and how the overlay is drawn.

Returns
The style given to the constructor.

◆ toggle()

void aegis2d::render::MetricsOverlay::toggle ( )
noexcept

Shows the overlay if hidden, hides it if shown.

◆ visible()

bool aegis2d::render::MetricsOverlay::visible ( ) const
noexcept

Tells whether the overlay is shown.

Returns
false by default.

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