aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 16:32:13 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 16:32:13 +0100
commiteefaeb807eb5d0b08353389070bf3d27c3d0d958 (patch)
tree14938c761e14ffa776c68836a1fcbaca1a4c1571 /src/crepe/system
parent30e2b2b0cbb503d83a087d8d326940c3c4bc8fff (diff)
test and debug audio system
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/AudioSystem.cpp28
-rw-r--r--src/crepe/system/AudioSystem.h4
-rw-r--r--src/crepe/system/System.cpp4
3 files changed, 20 insertions, 16 deletions
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) {}