From af39f2e08b0503db723ae707a5c7278d8c85f812 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Oct 2019 20:50:28 -0400 Subject: Audio component loading, getting ready to play --- Assets/jump.wav | Bin 0 -> 303194 bytes Scripts/init.lua | 3 +++ src/audio.cpp | 25 +++++++++++++++++++++++++ src/audio.hpp | 3 +++ src/components/Audio.hpp | 17 +++++++++++++---- src/engine.cpp | 2 ++ src/script.cpp | 10 ++++++++++ 7 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 Assets/jump.wav diff --git a/Assets/jump.wav b/Assets/jump.wav new file mode 100644 index 0000000..1cd1681 Binary files /dev/null and b/Assets/jump.wav differ diff --git a/Scripts/init.lua b/Scripts/init.lua index ec9e350..ea5a833 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -37,6 +37,9 @@ player = { }, Physics = 0, Name = "bord", + Audio = { + file = "Assets/jump.wav" + }, hellotrue = true, hellofalse = false, Render = { diff --git a/src/audio.cpp b/src/audio.cpp index 975cfce..8bb1413 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -20,13 +20,19 @@ #include "audio.hpp" +#include +#include + AudioSystem::AudioSystem(void) : device(nullptr, [](ALCdevice *d) { alcCloseDevice(d); }), context(nullptr, [](ALCcontext *c) { alcDestroyContext(c); }) {} AudioSystem::~AudioSystem(void) { + alutExit(); + // Delete context before device + alcMakeContextCurrent(nullptr); context.reset(); device.reset(); } @@ -46,6 +52,9 @@ void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities, context.reset(alcCreateContext(device.get(), nullptr)); if (!alcMakeContextCurrent(context.get())) return; // TODO Another uh oh + + if (alutInitWithoutContext(nullptr, nullptr) != AL_TRUE) + return; // TODO Third uh oh } void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities, @@ -56,10 +65,26 @@ void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities, void AudioSystem::receive(const entityx::ComponentAddedEvent