aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2019-09-30 15:29:49 -0400
committerClyne Sullivan <clyne@bitgloo.com>2019-09-30 15:29:49 -0400
commitbebc6e955114a0907c43df9a9c00f22b1f743446 (patch)
tree5a31e0f31727d69a978fcce9abd12551cdce4cea /src/audio.cpp
parent7919f7f69b0abd54a6df92f34e1392b84dae3669 (diff)
created Audio component
Diffstat (limited to 'src/audio.cpp')
-rw-r--r--src/audio.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/audio.cpp b/src/audio.cpp
index 7dec4c3..975cfce 100644
--- a/src/audio.cpp
+++ b/src/audio.cpp
@@ -27,12 +27,16 @@ AudioSystem::AudioSystem(void) :
AudioSystem::~AudioSystem(void)
{
// Delete context before device
- context.get_deleter()(context.get());
+ context.reset();
+ device.reset();
}
void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
- [[maybe_unused]] entityx::EventManager& events)
+ entityx::EventManager& events)
{
+ events.subscribe<entityx::ComponentAddedEvent<Audio>>(*this);
+ events.subscribe<entityx::ComponentRemovedEvent<Audio>>(*this);
+
// Access device
device.reset(alcOpenDevice(nullptr));
if (!device)
@@ -49,3 +53,13 @@ void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities,
[[maybe_unused]] entityx::TimeDelta dt)
{}
+void AudioSystem::receive(const entityx::ComponentAddedEvent<Audio>& cae)
+{
+ alGenSources(1, const_cast<ALuint*>(&cae.component->source));
+}
+
+void AudioSystem::receive(const entityx::ComponentRemovedEvent<Audio>& cae)
+{
+ alDeleteSources(1, &cae.component->source);
+}
+