]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
created base audiosystem
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 30 Sep 2019 19:13:37 +0000 (15:13 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 30 Sep 2019 19:13:37 +0000 (15:13 -0400)
Makefile
src/audio.cpp [new file with mode: 0644]
src/audio.hpp [new file with mode: 0644]

index 8d86b408d30cff85374f87781be49f8c761ad0e5..357d7ff031756130386fa992dab1af920a5d4c81 100644 (file)
--- 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 (file)
index 0000000..7dec4c3
--- /dev/null
@@ -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 (file)
index 0000000..4d617c7
--- /dev/null
@@ -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_
+