Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
AudioSystem.hpp
Go to the documentation of this file.
1
8#ifndef RTYPE_AUDIO_SYSTEM_HPP_
9#define RTYPE_AUDIO_SYSTEM_HPP_
10
11#include "RType/ECS/ISystem.hpp"
15
16#include <SFML/Audio.hpp>
17#include <unordered_map>
18#include <memory>
19
20namespace rtp::client {
21
30class AudioSystem : public ecs::ISystem {
31public:
32 explicit AudioSystem(ecs::Registry& registry);
33 ~AudioSystem() override;
34
39 void update(float dt) override;
40
45 void setMasterVolume(float volume);
46
51 float getMasterVolume() const;
52
57 void setMusicVolume(float volume);
58
63 void setSfxVolume(float volume);
64
68 void stopAllSounds();
69
70private:
75 std::unordered_map<uint32_t, std::unique_ptr<sf::Sound>> _activeSounds;
76 std::unordered_map<std::string, std::unique_ptr<sf::SoundBuffer>> _soundBuffers;
77 std::unordered_map<uint32_t, bool> _loopingSounds;
78 std::unordered_map<uint32_t, float> _soundBaseVolumes;
79 std::unordered_map<uint32_t, bool> _soundIsMusic;
80 uint32_t _nextSoundId;
81
87 sf::SoundBuffer* loadSoundBuffer(const std::string& path);
88
93 void updateAudioSources(float dt);
94
99 void updateSoundEvents(float dt);
100
106
112
117};
118
119} // namespace rtp::client
120
121#endif // !RTYPE_AUDIO_SYSTEM_HPP_
Interface for ECS systems.
System responsible for handling audio playback (music, SFX, ambient)
void setSfxVolume(float volume)
Set SFX volume (affects SoundEvent components)
void updateAudioSources(float dt)
Update all AudioSource components.
ecs::Registry & _registry
void update(float dt) override
Update audio system (called every frame)
void stopAllSounds()
Stop all currently playing sounds.
std::unordered_map< uint32_t, bool > _soundIsMusic
Track if sound is music (true) or SFX (false)
std::unordered_map< uint32_t, float > _soundBaseVolumes
Track base volume (0.0-1.0) for each sound.
void cleanupFinishedSounds()
Remove finished non-looping sounds from tracking.
float getMasterVolume() const
Get current master volume.
std::unordered_map< uint32_t, std::unique_ptr< sf::Sound > > _activeSounds
void setMusicVolume(float volume)
Set music volume (affects AudioSource components)
void updateSoundEvents(float dt)
Update all SoundEvent components.
void playSoundEffect(ecs::components::audio::SoundEvent &soundEvent)
Play a sound effect (one-time)
std::unordered_map< std::string, std::unique_ptr< sf::SoundBuffer > > _soundBuffers
std::unordered_map< uint32_t, bool > _loopingSounds
Track which sounds should loop.
void playAudioSource(ecs::components::audio::AudioSource &audioSource)
Play an AudioSource.
void setMasterVolume(float volume)
Set master volume for all audio.
sf::SoundBuffer * loadSoundBuffer(const std::string &path)
Load or get cached sound buffer.
Abstract base class for all ECS systems.
Definition ISystem.hpp:57
R-Type client namespace.
Component for entities that emit continuous sound (music, loops, ambient)
Component for triggering one-time sound effects (SFX)