]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
positional audio working
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 3 Oct 2019 14:24:01 +0000 (10:24 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 3 Oct 2019 14:24:01 +0000 (10:24 -0400)
Assets/boing.wav
Assets/jump.wav
src/audio.cpp
src/engine.cpp

index a142197af5b08b65e3fd47a7aa6298a2ca847504..088963d7dcd8bab16529b0109ba3296fc54ef40f 100644 (file)
Binary files a/Assets/boing.wav and b/Assets/boing.wav differ
index 1cd168193198c49f33e6cf0f2c6ccd0b8a0a5859..b9849ab57b6b54e67a8ab866ddf73e8b897bb972 100644 (file)
Binary files a/Assets/jump.wav and b/Assets/jump.wav differ
index 8bb14131d6767625f82f221938f30dab66048920..2f14c975707d7367a2fabd18568451bba6541175 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include "audio.hpp"
+#include "components/Player.hpp"
 
 #include <AL/alut.h>
 #include <iostream>
@@ -55,12 +56,25 @@ void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
 
     if (alutInitWithoutContext(nullptr, nullptr) != AL_TRUE)
         return; // TODO Third uh oh
+
+    ALfloat listenerOri[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
+    alListener3f(AL_POSITION, 0, 0, 0.0f);
+    alListener3f(AL_VELOCITY, 0, 0, 0);
+    alListenerfv(AL_ORIENTATION, listenerOri);
 }
 
-void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities,
+void AudioSystem::update(entityx::EntityManager& entities,
                          [[maybe_unused]] entityx::EventManager& events,
                          [[maybe_unused]] entityx::TimeDelta dt)
-{}
+{
+    entities.each<Player, Position>(
+        []([[maybe_unused]] entityx::Entity e,
+                   [[maybe_unused]] Player& p,
+                   Position &pos)
+        {
+            alListener3f(AL_POSITION, pos.x, pos.y, 0.0f);
+        });
+}
 
 void AudioSystem::receive(const entityx::ComponentAddedEvent<Audio>& cae)
 {
index c6bec279ab65e3bd624216d8f220e8092316c510..dc0c481e1c0a7584e40051f1ec5c1dcd83a8ab94 100644 (file)
@@ -120,6 +120,7 @@ void Engine::logicLoop(void)
             });
         }
 
+        systems.update<AudioSystem>(dt);
         std::this_thread::yield();
     }
 }