|
Aegis2D
Modular C++26 2D game engine for networked games
|
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. | |
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.
|
explicitnoexcept |
Creates the cues, with none shown.
| enabled | Whether the option is on. |
| limit | Most cues shown at once; a new cue past it replaces the oldest. |
| 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.
| renderer | Renderer in a frame. |
| font | Font of the captions. |
| screen | Area to draw in, usually the whole screen. |
| style | Scale and layer of the captions (their color comes from each cue). |
| std::logic_error | outside a frame (as IRenderer::draw()). |
|
noexcept |
Tells whether the option is on.
| 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.
| settings | Settings read with platform::read_settings() or core::Config. |
| path | Dotted path given to 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.
| settings | Settings to update, then saved with core::Config::save(). |
| path | Dotted path of the value, such as "accessibility.sound_cues". |
|
noexcept |
Turns the option on or off; turning it off removes the cues shown.
| enabled | The player's choice. |
| 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.
| cue | What to show; a duration that is not positive shows nothing. |
|
noexcept |
Cues on screen, oldest first.
|
noexcept |
Moves the cues forward in time and removes those that ended.
| seconds | Time since the last update. |
|
staticconstexpr |
Time over which a cue fades out before it disappears, in seconds.