From 693355f55193cb2ea4c29616073227e37665afc1 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 29 Nov 2024 17:30:45 +0100 Subject: more audio system WIP --- src/crepe/system/AudioSystem.cpp | 29 +++++++++++++++++++++++------ src/crepe/system/AudioSystem.h | 26 +++++++++++++++----------- 2 files changed, 38 insertions(+), 17 deletions(-) (limited to 'src/crepe/system') 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(component.source); - if (component.private_data.empty()) - component.private_data.set(); + Sound & resource = resource_manager.get(component.source); + + if (component.private_data.empty()) { + auto & data = component.private_data.set(); + this->update_last(component, data); + } auto & data = component.private_data.get(); - // 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; diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h index 7f41fda..4650178 100644 --- a/src/crepe/system/AudioSystem.h +++ b/src/crepe/system/AudioSystem.h @@ -1,6 +1,7 @@ #pragma once #include "../facade/SoundContext.h" +#include "../facade/Sound.h" #include "../api/AudioSource.h" #include "System.h" @@ -18,19 +19,22 @@ private: */ struct ComponentPrivate { //! This sample's voice handle - SoLoud::handle handle; - - //! Value of \c active after last system update - bool last_active = false; - //! Value of \c playing after last system update - bool last_playing = false; - //! Value of \c volume after last system update - float last_volume = 1.0; - //! Value of \c loop after last system update - bool last_loop = false; + Sound::Handle handle; + + /** + * \name State diffing variables + * \{ + */ + typeof(AudioSource::active) last_active; + typeof(AudioSource::playing) last_playing; + typeof(AudioSource::volume) last_volume; + typeof(AudioSource::loop) last_loop; + //! \} }; - void update_private(const AudioSource & component, ComponentPrivate & data); + void update_last(const AudioSource & component, ComponentPrivate & data); + + void diff_update(AudioSource & component, const ComponentPrivate & data, Sound & resource); private: SoundContext context {}; -- cgit v1.2.3