aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-29 20:35:17 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-29 20:35:17 +0100
commite4be73051a68b552c44280bbe9836dd4f02972d8 (patch)
treea2d0dbad0255a9da7c58f74c7479a39fcccd34db /src/crepe/system
parent693355f55193cb2ea4c29616073227e37665afc1 (diff)
audio system kinda working
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/AudioSystem.cpp30
-rw-r--r--src/crepe/system/AudioSystem.h2
2 files changed, 25 insertions, 7 deletions
diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp
index 191dbbb..98aff58 100644
--- a/src/crepe/system/AudioSystem.cpp
+++ b/src/crepe/system/AudioSystem.cpp
@@ -20,6 +20,7 @@ void AudioSystem::update() {
if (component.private_data.empty()) {
auto & data = component.private_data.set<ComponentPrivate>();
this->update_last(component, data);
+ data.last_playing = false; // always start
}
auto & data = component.private_data.get<ComponentPrivate>();
@@ -29,18 +30,35 @@ void AudioSystem::update() {
}
}
-void AudioSystem::diff_update(AudioSource & component, const ComponentPrivate & data, Sound & resource) {
+void AudioSystem::diff_update(AudioSource & component, 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;
- if (update_active)
- if (component.rewind) {
- component.playing = false;
- // this->context.rewind(resource, data.handle);
+ if (update_active) {
+ if (component.active) {
+ update_playing = true;
+ if (component.play_on_awake)
+ component.playing = true;
+ } else {
+ this->context.stop(data.handle);
+ return;
+ }
+ }
+ if (!component.active) return;
+ if (update_playing) {
+ if (component.playing) data.handle = this->context.play(resource);
+ else this->context.stop(data.handle);
+ } else {
+ component.playing = this->context.get_playing(data.handle);
+ }
+ if (update_volume) {
+ this->context.set_volume(resource, data.handle, component.volume);
+ }
+ if (update_loop) {
+ this->context.set_loop(resource, data.handle, component.loop);
}
-
}
void AudioSystem::update_last(const AudioSource & component, ComponentPrivate & data) {
diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h
index 4650178..3404878 100644
--- a/src/crepe/system/AudioSystem.h
+++ b/src/crepe/system/AudioSystem.h
@@ -34,7 +34,7 @@ private:
void update_last(const AudioSource & component, ComponentPrivate & data);
- void diff_update(AudioSource & component, const ComponentPrivate & data, Sound & resource);
+ void diff_update(AudioSource & component, ComponentPrivate & data, Sound & resource);
private:
SoundContext context {};