diff options
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/facade/SoundContext.h | 8 | ||||
-rw-r--r-- | src/crepe/system/AudioSystem.cpp | 28 | ||||
-rw-r--r-- | src/crepe/system/AudioSystem.h | 4 | ||||
-rw-r--r-- | src/crepe/system/System.cpp | 4 |
4 files changed, 24 insertions, 20 deletions
diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h index 91d3fe9..c651cd5 100644 --- a/src/crepe/facade/SoundContext.h +++ b/src/crepe/facade/SoundContext.h @@ -24,10 +24,10 @@ public: SoundContext & operator=(const SoundContext &) = delete; SoundContext & operator=(SoundContext &&) = delete; - Sound::Handle play(Sound & resource); - void stop(Sound::Handle &); - void set_volume(Sound &, Sound::Handle &, float); - void set_loop(Sound &, Sound::Handle &, bool); + virtual Sound::Handle play(Sound & resource); + virtual void stop(Sound::Handle &); + virtual void set_volume(Sound &, Sound::Handle &, float); + virtual void set_loop(Sound &, Sound::Handle &, bool); private: SoLoud::Soloud engine; diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index b105a4d..84a101a 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -29,39 +29,43 @@ void AudioSystem::update() { } void AudioSystem::diff_update(AudioSource & component, ComponentPrivate & data, Sound & resource) { - bool update_volume = component.volume != data.last_volume; - bool update_loop = component.loop != data.last_loop; - bool update_active = component.active != data.last_active; + SoundContext & context = this->get_context(); - if (update_active) { + if (component.active != data.last_active) { if (component.active) { component.oneshot_play = component.play_on_awake; } else { - this->context.stop(data.handle); + context.stop(data.handle); return; } } if (!component.active) return; + if (component.oneshot_play) { - data.handle = this->context.play(resource); + data.handle = context.play(resource); component.oneshot_play = false; } if (component.oneshot_stop) { - this->context.stop(data.handle); + context.stop(data.handle); component.oneshot_stop = false; } - if (update_volume) { - this->context.set_volume(resource, data.handle, component.volume); + if (component.volume != data.last_volume) { + context.set_volume(resource, data.handle, component.volume); } - if (update_loop) { - this->context.set_loop(resource, data.handle, component.loop); + if (component.loop != data.last_loop) { + context.set_loop(resource, data.handle, component.loop); } } 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_volume = component.volume; } +SoundContext & AudioSystem::get_context() { + if (this->context.empty()) + this->context.set<SoundContext>(); + return this->context.get<SoundContext>(); +} + diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h index dee82f6..a004c60 100644 --- a/src/crepe/system/AudioSystem.h +++ b/src/crepe/system/AudioSystem.h @@ -35,8 +35,10 @@ private: void diff_update(AudioSource & component, ComponentPrivate & data, Sound & resource); +protected: + virtual SoundContext & get_context(); private: - SoundContext context {}; + Private context; }; } // namespace crepe diff --git a/src/crepe/system/System.cpp b/src/crepe/system/System.cpp index f68549b..ecc740d 100644 --- a/src/crepe/system/System.cpp +++ b/src/crepe/system/System.cpp @@ -1,7 +1,5 @@ -#include "../util/Log.h" - #include "System.h" using namespace crepe; -System::System(const Mediator & mediator) : mediator(mediator) { dbg_trace(); } +System::System(const Mediator & mediator) : mediator(mediator) {} |