Plays sounds when events are published on an event bus, so gameplay code never calls audio.
More...
#include <aegis2d/audio/event_sounds.hpp>
Plays sounds when events are published on an event bus, so gameplay code never calls audio.
Gameplay publishes what happens (shmup::ShotFired, ecs::Explosion, ecs::LifeLost...) on a core::EventBus; the game says once, at startup, which sound each event plays:
});
The default audio output and the sounds it plays.
Definition audio.hpp:54
SoundId load(const std::filesystem::path &path)
Loads a sound from a WAV file.
Plays sounds when events are published on an event bus, so gameplay code never calls audio.
Definition event_sounds.hpp:51
void play_on(SoundId sound, const SoundOptions &options={})
Plays a sound each time an Event is published.
Definition event_sounds.hpp:71
Lets systems react to events without knowing who sends them.
Definition event_bus.hpp:31
std::filesystem::path asset_path(const std::filesystem::path &relative)
Path of one asset.
An entity whose health reached zero blows up: an enemy shot down, or a player that loses a life.
Definition events.hpp:31
A player who lost a life during the tick.
Definition lives.hpp:17
An entity fired: one shot leaves it during the tick.
Definition weapons.hpp:85
Each play_on() adds a rule: the event type, the sound, an optional filter and SoundOptions. Several rules can listen to the same event type. A sound that SDL cannot start is skipped with a warning in the log: a sound never stops the game. The rules are removed from the bus when the EventSounds is destroyed, so it must not outlive the bus or the device; use it from the game thread, like the bus.
◆ EventSounds() [1/3]
Creates an EventSounds with no rule.
- Parameters
-
| device | Device that plays the sounds. |
| events | Bus the events are published on. |
◆ EventSounds() [2/3]
◆ EventSounds() [3/3]
| aegis2d::audio::EventSounds::EventSounds |
( |
EventSounds && |
| ) |
|
|
delete |
◆ ~EventSounds()
| aegis2d::audio::EventSounds::~EventSounds |
( |
| ) |
|
Removes every rule from the bus.
◆ clear()
| void aegis2d::audio::EventSounds::clear |
( |
| ) |
|
|
noexcept |
Removes every rule from the bus.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ play_on() [1/2]
template<typename Event >
Plays a sound each time an Event is published.
- Template Parameters
-
| Event | Event type, as published on the bus. |
- Parameters
-
| sound | Identifier returned by AudioDevice::load(). |
| options | Channel and shortest time between two starts. |
- Exceptions
-
| std::out_of_range | if sound was not loaded. |
◆ play_on() [2/2]
template<typename Event , typename Filter >
requires std::predicate<Filter&, const Event&> && std::copy_constructible<Filter>
| void aegis2d::audio::EventSounds::play_on |
( |
SoundId |
sound, |
|
|
Filter |
filter, |
|
|
const SoundOptions & |
options = {} |
|
) |
| |
|
inline |
Plays a sound each time an Event that filter accepts is published.
- Template Parameters
-
| Event | Event type, as published on the bus. |
- Parameters
-
| sound | Identifier returned by AudioDevice::load(). |
| filter | Copyable callable taking the event and returning true to play the sound, e.g. only for the shots of enemies. |
| options | Channel and shortest time between two starts. |
- Exceptions
-
| std::out_of_range | if sound was not loaded. |
◆ rules()
| std::size_t aegis2d::audio::EventSounds::rules |
( |
| ) |
const |
|
noexcept |
Number of rules.
- Returns
- The play_on() calls since the creation or the last clear().
The documentation for this class was generated from the following file: