aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/AudioSystem.cpp17
-rw-r--r--src/crepe/system/AudioSystem.h21
2 files changed, 35 insertions, 3 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp
index 97cf966..0f943be 100644
--- a/src/crepe/system/AudioSystem.cpp
+++ b/src/crepe/system/AudioSystem.cpp
@@ -1,6 +1,5 @@
#include "AudioSystem.h"
-#include "../api/AudioSource.h"
#include "../manager/ComponentManager.h"
#include "../manager/ResourceManager.h"
#include "../types.h"
@@ -13,12 +12,24 @@ void AudioSystem::update() {
ResourceManager & resource_manager = this->mediator.resource_manager;
RefVector<AudioSource> components = component_manager.get_components_by_type<AudioSource>();
- for (auto component_ref : components) {
- AudioSource & component = component_ref.get();
+ 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>();
+ auto & data = component.private_data.get<ComponentPrivate>();
// TODO: lots of state diffing
+
+
+ this->update_private(component, data);
}
}
+void AudioSystem::update_private(const AudioSource & component, ComponentPrivate & data) {
+ data.last_active = component.active;
+ data.last_loop = component.loop;
+ data.last_playing = component.playing;
+ data.last_volume = component.volume;
+}
+
diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h
index e037f51..7f41fda 100644
--- a/src/crepe/system/AudioSystem.h
+++ b/src/crepe/system/AudioSystem.h
@@ -1,6 +1,7 @@
#pragma once
#include "../facade/SoundContext.h"
+#include "../api/AudioSource.h"
#include "System.h"
@@ -12,6 +13,26 @@ public:
void update() override;
private:
+ /**
+ * \brief Private data stored by AudioSystem on AudioSource component
+ */
+ 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;
+ };
+
+ void update_private(const AudioSource & component, ComponentPrivate & data);
+
+private:
SoundContext context {};
};