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

Captions and direction arrows for the sounds a deaf or hard-of-hearing player, or anyone playing muted, would miss. More...

#include <aegis2d/render/sound_cues.hpp>

Public Member Functions

 SoundCues (bool enabled=false, std::size_t limit=4) noexcept
 Creates the cues, with none shown.
 
void set_enabled (bool enabled) noexcept
 Turns the option on or off; turning it off removes the cues shown.
 
bool enabled () const noexcept
 Tells whether the option is on.
 
void show (SoundCue cue)
 Shows a cue, unless the option is off.
 
void update (float seconds) noexcept
 Moves the cues forward in time and removes those that ended.
 
std::span< const ShownCue > shown () const noexcept
 Cues on screen, oldest first.
 
std::vector< Rect > draw (IRenderer &renderer, const BitmapFont &font, const Rect &screen, const TextStyle &style) const
 Draws the cues, each over a dark backdrop.
 
void save (core::Config &settings, std::string_view path) const
 Writes whether the option is on into the player's settings.
 
void load (const core::Config &settings, std::string_view path)
 Reads whether the option is on, as written by save().
 

Static Public Attributes

static constexpr float fade = 0.5F
 Time over which a cue fades out before it disappears, in seconds.
 

Detailed Description

Captions and direction arrows for the sounds a deaf or hard-of-hearing player, or anyone playing muted, would miss.

The game calls show() each time it plays an important sound, whatever the volume, then update() and draw() each frame. A cue with a source is drawn on the edge of the screen nearest to it, with an arrow pointing to it ("Enemy incoming >" on the right edge); a cue without one is a caption at the bottom center, the newest lowest. Cues never overlap, and a caption shown again is refreshed instead of repeated. Off by default: the player turns it on in the settings.

audio.play(spawn_sound);
cues.show({.caption = "Enemy incoming", .source = enemy_position});
...
cues.update(frame_seconds);
cues.draw(renderer, font, screen, text_size.apply({.scale = 2.0F, .layer = 200}));

Constructor & Destructor Documentation

◆ SoundCues()

aegis2d::render::SoundCues::SoundCues ( bool  enabled = false,
std::size_t  limit = 4 
)
explicitnoexcept

Creates the cues, with none shown.

Parameters
enabledWhether the option is on.
limitMost cues shown at once; a new cue past it replaces the oldest.

Member Function Documentation

◆ draw()

std::vector< Rect > aegis2d::render::SoundCues::draw ( IRenderer &  renderer,
const BitmapFont &  font,
const Rect &  screen,
const TextStyle &  style 
) const

Draws the cues, each over a dark backdrop.

Parameters
rendererRenderer in a frame.
fontFont of the captions.
screenArea to draw in, usually the whole screen.
styleScale and layer of the captions (their color comes from each cue).
Returns
The rectangle of each cue drawn, in the order of shown().
Exceptions
std::logic_erroroutside a frame (as IRenderer::draw()).

◆ enabled()

bool aegis2d::render::SoundCues::enabled ( ) const
noexcept

Tells whether the option is on.

Returns
The last value given to the constructor or to set_enabled().

◆ load()

void aegis2d::render::SoundCues::load ( const core::Config &  settings,
std::string_view  path 
)

Reads whether the option is on, as written by save().

A missing value keeps the option; one that is not a boolean is logged and kept.

Parameters
settingsSettings read with platform::read_settings() or core::Config.
pathDotted path given to save().

◆ save()

void aegis2d::render::SoundCues::save ( core::Config &  settings,
std::string_view  path 
) const

Writes whether the option is on into the player's settings.

Parameters
settingsSettings to update, then saved with core::Config::save().
pathDotted path of the value, such as "accessibility.sound_cues".

◆ set_enabled()

void aegis2d::render::SoundCues::set_enabled ( bool  enabled)
noexcept

Turns the option on or off; turning it off removes the cues shown.

Parameters
enabledThe player's choice.

◆ show()

void aegis2d::render::SoundCues::show ( SoundCue  cue)

Shows a cue, unless the option is off.

A cue with the caption of one already shown replaces it (new source, full time), so a repeated sound does not stack.

Parameters
cueWhat to show; a duration that is not positive shows nothing.

◆ shown()

std::span< const ShownCue > aegis2d::render::SoundCues::shown ( ) const
noexcept

Cues on screen, oldest first.

Returns
A view valid until the next call of a non-const function.

◆ update()

void aegis2d::render::SoundCues::update ( float  seconds)
noexcept

Moves the cues forward in time and removes those that ended.

Parameters
secondsTime since the last update.

Member Data Documentation

◆ fade

constexpr float aegis2d::render::SoundCues::fade = 0.5F
staticconstexpr

Time over which a cue fades out before it disappears, in seconds.


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