|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
System responsible for handling audio playback (music, SFX, ambient) More...
#include <AudioSystem.hpp>
Public Member Functions | |
| AudioSystem (ecs::Registry ®istry) | |
| ~AudioSystem () override | |
| void | update (float dt) override |
| Update audio system (called every frame) | |
| void | setMasterVolume (float volume) |
| Set master volume for all audio. | |
| float | getMasterVolume () const |
| Get current master volume. | |
| void | setMusicVolume (float volume) |
| Set music volume (affects AudioSource components) | |
| void | setSfxVolume (float volume) |
| Set SFX volume (affects SoundEvent components) | |
| void | stopAllSounds () |
| Stop all currently playing sounds. | |
Public Member Functions inherited from rtp::ecs::ISystem | |
| virtual | ~ISystem () noexcept=default |
Private Member Functions | |
| sf::SoundBuffer * | loadSoundBuffer (const std::string &path) |
| Load or get cached sound buffer. | |
| void | updateAudioSources (float dt) |
| Update all AudioSource components. | |
| void | updateSoundEvents (float dt) |
| Update all SoundEvent components. | |
| void | playAudioSource (ecs::components::audio::AudioSource &audioSource) |
| Play an AudioSource. | |
| void | playSoundEffect (ecs::components::audio::SoundEvent &soundEvent) |
| Play a sound effect (one-time) | |
| void | cleanupFinishedSounds () |
| Remove finished non-looping sounds from tracking. | |
Private Attributes | |
| ecs::Registry & | _registry |
| float | _masterVolume |
| float | _musicVolume |
| float | _sfxVolume |
| std::unordered_map< uint32_t, std::unique_ptr< sf::Sound > > | _activeSounds |
| std::unordered_map< std::string, std::unique_ptr< sf::SoundBuffer > > | _soundBuffers |
| std::unordered_map< uint32_t, bool > | _loopingSounds |
| Track which sounds should loop. | |
| std::unordered_map< uint32_t, float > | _soundBaseVolumes |
| Track base volume (0.0-1.0) for each sound. | |
| std::unordered_map< uint32_t, bool > | _soundIsMusic |
| Track if sound is music (true) or SFX (false) | |
| uint32_t | _nextSoundId |
System responsible for handling audio playback (music, SFX, ambient)
Manages two types of audio:
Definition at line 30 of file AudioSystem.hpp.
|
explicit |
Definition at line 13 of file AudioSystem.cpp.
|
override |
Definition at line 16 of file AudioSystem.cpp.
References stopAllSounds().
|
private |
Remove finished non-looping sounds from tracking.
Definition at line 162 of file AudioSystem.cpp.
References _activeSounds, _loopingSounds, _soundBaseVolumes, and _soundIsMusic.
Referenced by updateAudioSources().
| float rtp::client::AudioSystem::getMasterVolume | ( | ) | const |
Get current master volume.
Definition at line 37 of file AudioSystem.cpp.
References _masterVolume.
|
private |
Load or get cached sound buffer.
| path | Path to the audio file |
Definition at line 75 of file AudioSystem.cpp.
References _soundBuffers, and rtp::log::error().
Referenced by playAudioSource(), and playSoundEffect().
|
private |
Play an AudioSource.
| audioSource | The audio source component to play |
Definition at line 132 of file AudioSystem.cpp.
References _activeSounds, _loopingSounds, _masterVolume, _musicVolume, _nextSoundId, _soundBaseVolumes, _soundIsMusic, rtp::ecs::components::audio::AudioSource::audioPath, loadSoundBuffer(), rtp::ecs::components::audio::AudioSource::loop, rtp::ecs::components::audio::AudioSource::pitch, rtp::ecs::components::audio::AudioSource::sourceId, and rtp::ecs::components::audio::AudioSource::volume.
Referenced by updateAudioSources().
|
private |
Play a sound effect (one-time)
| soundEvent | The sound event component to play |
Definition at line 148 of file AudioSystem.cpp.
References _activeSounds, _masterVolume, _nextSoundId, _sfxVolume, _soundBaseVolumes, _soundIsMusic, loadSoundBuffer(), rtp::ecs::components::audio::SoundEvent::pitch, rtp::ecs::components::audio::SoundEvent::soundPath, and rtp::ecs::components::audio::SoundEvent::volume.
Referenced by updateSoundEvents().
| void rtp::client::AudioSystem::setMasterVolume | ( | float | volume | ) |
Set master volume for all audio.
| volume | Volume level (0.0 - 100.0) |
Definition at line 25 of file AudioSystem.cpp.
References _activeSounds, _masterVolume, _musicVolume, _sfxVolume, _soundBaseVolumes, and _soundIsMusic.
| void rtp::client::AudioSystem::setMusicVolume | ( | float | volume | ) |
Set music volume (affects AudioSource components)
| volume | Volume level (0.0 - 100.0) |
Definition at line 41 of file AudioSystem.cpp.
References _activeSounds, _masterVolume, _musicVolume, _soundBaseVolumes, and _soundIsMusic.
| void rtp::client::AudioSystem::setSfxVolume | ( | float | volume | ) |
Set SFX volume (affects SoundEvent components)
| volume | Volume level (0.0 - 100.0) |
Definition at line 53 of file AudioSystem.cpp.
References _activeSounds, _masterVolume, _sfxVolume, _soundBaseVolumes, and _soundIsMusic.
| void rtp::client::AudioSystem::stopAllSounds | ( | ) |
Stop all currently playing sounds.
Definition at line 65 of file AudioSystem.cpp.
References _activeSounds, _loopingSounds, _soundBaseVolumes, and _soundIsMusic.
Referenced by ~AudioSystem(), and rtp::client::Application::changeState().
|
overridevirtual |
Update audio system (called every frame)
| dt | Delta time in seconds |
Implements rtp::ecs::ISystem.
Definition at line 20 of file AudioSystem.cpp.
References updateAudioSources(), and updateSoundEvents().
|
private |
Update all AudioSource components.
| dt | Delta time in seconds |
Definition at line 91 of file AudioSystem.cpp.
References _activeSounds, _registry, cleanupFinishedSounds(), rtp::log::error(), playAudioSource(), and rtp::ecs::Registry::zipView().
Referenced by update().
|
private |
Update all SoundEvent components.
| dt | Delta time in seconds |
Definition at line 116 of file AudioSystem.cpp.
References _registry, rtp::log::error(), rtp::log::info(), playSoundEffect(), and rtp::ecs::Registry::zipView().
Referenced by update().
|
private |
Definition at line 75 of file AudioSystem.hpp.
Referenced by cleanupFinishedSounds(), playAudioSource(), playSoundEffect(), setMasterVolume(), setMusicVolume(), setSfxVolume(), stopAllSounds(), and updateAudioSources().
|
private |
Track which sounds should loop.
Definition at line 77 of file AudioSystem.hpp.
Referenced by cleanupFinishedSounds(), playAudioSource(), and stopAllSounds().
|
private |
Definition at line 72 of file AudioSystem.hpp.
Referenced by getMasterVolume(), playAudioSource(), playSoundEffect(), setMasterVolume(), setMusicVolume(), and setSfxVolume().
|
private |
Definition at line 73 of file AudioSystem.hpp.
Referenced by playAudioSource(), setMasterVolume(), and setMusicVolume().
|
private |
Definition at line 80 of file AudioSystem.hpp.
Referenced by playAudioSource(), and playSoundEffect().
|
private |
Definition at line 71 of file AudioSystem.hpp.
Referenced by updateAudioSources(), and updateSoundEvents().
|
private |
Definition at line 74 of file AudioSystem.hpp.
Referenced by playSoundEffect(), setMasterVolume(), and setSfxVolume().
|
private |
Track base volume (0.0-1.0) for each sound.
Definition at line 78 of file AudioSystem.hpp.
Referenced by cleanupFinishedSounds(), playAudioSource(), playSoundEffect(), setMasterVolume(), setMusicVolume(), setSfxVolume(), and stopAllSounds().
|
private |
Definition at line 76 of file AudioSystem.hpp.
Referenced by loadSoundBuffer().
|
private |
Track if sound is music (true) or SFX (false)
Definition at line 79 of file AudioSystem.hpp.
Referenced by cleanupFinishedSounds(), playAudioSource(), playSoundEffect(), setMasterVolume(), setMusicVolume(), setSfxVolume(), and stopAllSounds().