diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-29 17:30:45 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-29 17:30:45 +0100 |
commit | 693355f55193cb2ea4c29616073227e37665afc1 (patch) | |
tree | 37d2bd3e916b909fbac58ae836e8001166edf384 /src/crepe/system/AudioSystem.cpp | |
parent | c59d460f12e1393e0ddbaaa1c6f5522eb12f8ff9 (diff) |
more audio system WIP
Diffstat (limited to 'src/crepe/system/AudioSystem.cpp')
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index 0f943be..191dbbb 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -15,18 +15,35 @@ void AudioSystem::update() { for (AudioSource & component : components) { if (!component.active) continue; - Sound & sound = resource_manager.get<Sound>(component.source); - if (component.private_data.empty()) - component.private_data.set<ComponentPrivate>(); + 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); + } auto & data = component.private_data.get<ComponentPrivate>(); - // TODO: lots of state diffing + this->diff_update(component, data, resource); + + this->update_last(component, data); + } +} + +void AudioSystem::diff_update(AudioSource & component, const 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; - this->update_private(component, data); + if (update_active) + if (component.rewind) { + component.playing = false; + // this->context.rewind(resource, data.handle); } + } -void AudioSystem::update_private(const AudioSource & component, ComponentPrivate & data) { +void AudioSystem::update_last(const AudioSource & component, ComponentPrivate & data) { data.last_active = component.active; data.last_loop = component.loop; data.last_playing = component.playing; |