diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-30 15:08:57 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-30 15:08:57 +0100 |
commit | 30e2b2b0cbb503d83a087d8d326940c3c4bc8fff (patch) | |
tree | e7332b214587a336a130b01e83ad368388fca516 /src/crepe/system/AudioSystem.cpp | |
parent | e4be73051a68b552c44280bbe9836dd4f02972d8 (diff) |
fix audio system implementation
Diffstat (limited to 'src/crepe/system/AudioSystem.cpp')
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index 98aff58..b105a4d 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -13,14 +13,12 @@ void AudioSystem::update() { RefVector<AudioSource> components = component_manager.get_components_by_type<AudioSource>(); for (AudioSource & component : components) { - if (!component.active) continue; - Sound & resource = resource_manager.get<Sound>(component.source); if (component.private_data.empty()) { auto & data = component.private_data.set<ComponentPrivate>(); this->update_last(component, data); - data.last_playing = false; // always start + data.last_active = false; } auto & data = component.private_data.get<ComponentPrivate>(); @@ -31,27 +29,26 @@ void AudioSystem::update() { } void AudioSystem::diff_update(AudioSource & component, ComponentPrivate & data, Sound & resource) { - bool update_playing = component.playing != data.last_playing; bool update_volume = component.volume != data.last_volume; bool update_loop = component.loop != data.last_loop; bool update_active = component.active != data.last_active; if (update_active) { if (component.active) { - update_playing = true; - if (component.play_on_awake) - component.playing = true; + component.oneshot_play = component.play_on_awake; } else { this->context.stop(data.handle); return; } } if (!component.active) return; - if (update_playing) { - if (component.playing) data.handle = this->context.play(resource); - else this->context.stop(data.handle); - } else { - component.playing = this->context.get_playing(data.handle); + if (component.oneshot_play) { + data.handle = this->context.play(resource); + component.oneshot_play = false; + } + if (component.oneshot_stop) { + this->context.stop(data.handle); + component.oneshot_stop = false; } if (update_volume) { this->context.set_volume(resource, data.handle, component.volume); @@ -63,8 +60,8 @@ void AudioSystem::diff_update(AudioSource & component, ComponentPrivate & data, void AudioSystem::update_last(const AudioSource & component, ComponentPrivate & data) { data.last_active = component.active; + if (!component.active) return; data.last_loop = component.loop; - data.last_playing = component.playing; data.last_volume = component.volume; } |