Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
sound_cues.hpp
Go to the documentation of this file.
1
3#pragma once
4
9#include <aegis2d/render/export.hpp>
11
12#include <cstddef>
13#include <optional>
14#include <span>
15#include <string>
16#include <string_view>
17#include <vector>
18
19namespace aegis2d::render {
20
22struct SoundCue {
24 std::string caption;
27 std::optional<Vec2> source = std::nullopt;
29 Color color{.r = 1.0F, .g = 1.0F, .b = 1.0F, .a = 1.0F};
31 float seconds = 2.0F;
32};
33
35struct ShownCue {
39 float left = 0.0F;
40};
41
57class AEGIS2D_RENDER_EXPORT SoundCues {
58public:
60 static constexpr float fade = 0.5F;
61
65 explicit SoundCues(bool enabled = false, std::size_t limit = 4) noexcept;
66
69 void set_enabled(bool enabled) noexcept;
70
73 [[nodiscard]] bool enabled() const noexcept;
74
79 void show(SoundCue cue);
80
83 void update(float seconds) noexcept;
84
87 [[nodiscard]] std::span<const ShownCue> shown() const noexcept;
88
96 std::vector<Rect> draw(IRenderer& renderer, const BitmapFont& font, const Rect& screen,
97 const TextStyle& style) const;
98
102 void save(core::Config& settings, std::string_view path) const;
103
109 void load(const core::Config& settings, std::string_view path);
110
111private:
112 bool enabled_;
113 std::size_t limit_;
114 std::vector<ShownCue> shown_;
115};
116
117} // namespace aegis2d::render
Text drawn with a bitmap font, through the sprite batcher.
Monospaced font whose glyphs are cells of a texture, drawn as sprites.
Definition bitmap_font.hpp:68
What the game draws with, whatever the graphics API behind it.
Definition renderer.hpp:81
Captions and direction arrows for the sounds a deaf or hard-of-hearing player, or anyone playing mute...
Definition sound_cues.hpp:57
SoundCues(bool enabled=false, std::size_t limit=4) noexcept
Creates the cues, with none shown.
RGBA color used by the renderer.
JSON configuration with dotted-path lookups, which can be changed and saved.
Vector and matrix types of the engine (GLM behind engine names).
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
Definition endpoint.hpp:85
Backend-independent renderer interface and the sprite it draws.
RGBA color with components in [0, 1].
Definition color.hpp:10
float r
Red component.
Definition color.hpp:12
Axis-aligned rectangle.
Definition renderer.hpp:20
A cue on screen and the time it has left.
Definition sound_cues.hpp:35
SoundCue cue
The cue as given to SoundCues::show().
Definition sound_cues.hpp:37
float left
Seconds before it disappears.
Definition sound_cues.hpp:39
What an important sound tells the player, shown while it plays.
Definition sound_cues.hpp:22
float seconds
How long the cue stays, in seconds; it fades out during the last half second.
Definition sound_cues.hpp:31
std::string caption
Short caption, such as "Enemy incoming" or "Low life".
Definition sound_cues.hpp:24
std::optional< Vec2 > source
Where the sound comes from, in logical pixels; nothing for a sound with no place (an alarm,...
Definition sound_cues.hpp:27
Color color
Color of the caption.
Definition sound_cues.hpp:29
How a text is drawn.
Definition bitmap_font.hpp:49