6#include <aegis2d/audio/export.hpp>
70 template <
typename Event>
72 play_on<Event>(sound, [](
const Event& ) {
return true; }, options);
82 template <
typename Event,
typename Filter>
83 requires std::predicate<Filter&, const Event&> && std::copy_constructible<Filter>
85 const std::size_t rule = add_rule(sound, options);
87 subscriptions_.push_back(events_.get().subscribe<Event>(
88 [
this, rule, filter = std::move(filter)](
const Event& event)
mutable {
100 [[nodiscard]]
std::
size_t rules() const noexcept;
107 std::chrono::steady_clock::time_point last{};
111 void trigger(std::size_t rule);
113 std::reference_wrapper<AudioDevice> device_;
114 std::reference_wrapper<core::EventBus> events_;
115 std::vector<Rule> rules_;
116 std::vector<core::SubscriptionId> subscriptions_;
Audio output: sounds loaded once, then played on a channel, on top of SDL3.
The default audio output and the sounds it plays.
Definition audio.hpp:54
Plays sounds when events are published on an event bus, so gameplay code never calls audio.
Definition event_sounds.hpp:51
EventSounds & operator=(EventSounds &&)=delete
EventSounds(const EventSounds &)=delete
EventSounds(EventSounds &&)=delete
void play_on(SoundId sound, const SoundOptions &options={})
Plays a sound each time an Event is published.
Definition event_sounds.hpp:71
void clear() noexcept
Removes every rule from the bus.
EventSounds & operator=(const EventSounds &)=delete
EventSounds(AudioDevice &device, core::EventBus &events) noexcept
Creates an EventSounds with no rule.
void play_on(SoundId sound, Filter filter, const SoundOptions &options={})
Plays a sound each time an Event that filter accepts is published.
Definition event_sounds.hpp:84
~EventSounds()
Removes every rule from the bus.
Lets systems react to events without knowing who sends them.
Definition event_bus.hpp:31
Typed publish/subscribe event bus with immediate dispatch.
Sound effects and music on top of SDL3 (client only).
Definition audio.hpp:17
Channel
Group of sounds whose volume is set together.
Definition audio.hpp:28
@ Effects
Short sounds of the game: shots, explosions, menus.
std::size_t SoundId
Identifier of a sound loaded by an AudioDevice, given by AudioDevice::load().
Definition audio.hpp:36
Definition endpoint.hpp:85
How EventSounds plays the sound of an event.
Definition event_sounds.hpp:19
std::chrono::milliseconds min_interval
Shortest time between two starts of the sound by this rule: events published sooner are not heard aga...
Definition event_sounds.hpp:25
Channel channel
Channel of the sound, hence its volume.
Definition event_sounds.hpp:21