aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/AudioSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system/AudioSystem.cpp')
-rw-r--r--src/crepe/system/AudioSystem.cpp29
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;