aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2019-09-30 15:13:37 -0400
committerClyne Sullivan <clyne@bitgloo.com>2019-09-30 15:13:37 -0400
commit7919f7f69b0abd54a6df92f34e1392b84dae3669 (patch)
treeffe5d34abcd09f243c1d5e77b4bb41f282119cdb
parentdf47acd471fde2e837b7c90dfeadc6a77c643f5c (diff)
created base audiosystem
-rw-r--r--Makefile2
-rw-r--r--src/audio.cpp51
-rw-r--r--src/audio.hpp52
3 files changed, 104 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 8d86b40..357d7ff 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ DEPEXT = d
LIBDIR = lib
LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -lluajit -ldl -lGLEW -lGL \
- -lSDL2_image -lSOIL -lfreetype -lalut
+ -lSDL2_image -lSOIL -lfreetype -lopenal -lalut
CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic \
-Wno-class-memaccess -Wno-implicit-fallthrough -m64
diff --git a/src/audio.cpp b/src/audio.cpp
new file mode 100644
index 0000000..7dec4c3
--- /dev/null
+++ b/src/audio.cpp
@@ -0,0 +1,51 @@
+/**
+ * @file audio.cpp
+ * Handles audio loading and playback
+ *
+ * Copyright (C) 2019 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "audio.hpp"
+
+AudioSystem::AudioSystem(void) :
+ device(nullptr, [](ALCdevice *d) { alcCloseDevice(d); }),
+ context(nullptr, [](ALCcontext *c) { alcDestroyContext(c); }) {}
+
+AudioSystem::~AudioSystem(void)
+{
+ // Delete context before device
+ context.get_deleter()(context.get());
+}
+
+void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
+ [[maybe_unused]] entityx::EventManager& events)
+{
+ // Access device
+ device.reset(alcOpenDevice(nullptr));
+ if (!device)
+ return; // TODO Uh oh
+
+ // Create context
+ context.reset(alcCreateContext(device.get(), nullptr));
+ if (!alcMakeContextCurrent(context.get()))
+ return; // TODO Another uh oh
+}
+
+void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities,
+ [[maybe_unused]] entityx::EventManager& events,
+ [[maybe_unused]] entityx::TimeDelta dt)
+{}
+
diff --git a/src/audio.hpp b/src/audio.hpp
new file mode 100644
index 0000000..4d617c7
--- /dev/null
+++ b/src/audio.hpp
@@ -0,0 +1,52 @@
+/**
+ * @file audio.hpp
+ * Handles audio loading and playback
+ *
+ * Copyright (C) 2019 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef SYSTEM_AUDIO_HPP_
+#define SYSTEM_AUDIO_HPP_
+
+#include <AL/alut.h>
+
+#include <entityx/entityx.h>
+
+class AudioSystem : public entityx::System<AudioSystem>
+{
+private:
+ std::unique_ptr<ALCdevice, void (*)(ALCdevice *)> device;
+ std::unique_ptr<ALCcontext, void (*)(ALCcontext *)> context;
+
+public:
+ AudioSystem(void);
+ ~AudioSystem(void);
+
+ /**
+ * Prepares the system for running.
+ */
+ void configure(entityx::EntityManager& entities,
+ entityx::EventManager& events) final;
+
+ /**
+ * Updates the render system.
+ */
+ void update(entityx::EntityManager& entities,
+ entityx::EventManager& events,
+ entityx::TimeDelta dt) final;
+};
+
+#endif // SYSTEM_AUDIO_HPP_
+