diff options
Diffstat (limited to 'src/crepe/system/AudioSystem.cpp')
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index 191dbbb..98aff58 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -20,6 +20,7 @@ void AudioSystem::update() { if (component.private_data.empty()) { auto & data = component.private_data.set<ComponentPrivate>(); this->update_last(component, data); + data.last_playing = false; // always start } auto & data = component.private_data.get<ComponentPrivate>(); @@ -29,18 +30,35 @@ void AudioSystem::update() { } } -void AudioSystem::diff_update(AudioSource & component, const ComponentPrivate & data, Sound & resource) { +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.rewind) { - component.playing = false; - // this->context.rewind(resource, data.handle); + if (update_active) { + if (component.active) { + update_playing = true; + if (component.play_on_awake) + component.playing = true; + } 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 (update_volume) { + this->context.set_volume(resource, data.handle, component.volume); + } + if (update_loop) { + this->context.set_loop(resource, data.handle, component.loop); } - } void AudioSystem::update_last(const AudioSource & component, ComponentPrivate & data) { |