]> git.localhorst.tv Git - blank.git/blobdiff - src/audio/audio.cpp
block sounds depending on block type
[blank.git] / src / audio / audio.cpp
index 93569f0cda2bbc694d484ef3e6553a1ca26b6fd4..a223e05a496d7e4889be4f02cb73ce626fb764b4 100644 (file)
@@ -1,6 +1,10 @@
 #include "ALError.hpp"
 #include "Audio.hpp"
 #include "Sound.hpp"
+#include "SoundBank.hpp"
+
+#include "../app/Assets.hpp"
+#include "../shared/ResourceIndex.hpp"
 
 #include <algorithm>
 #include <alut.h>
@@ -148,11 +152,7 @@ int Audio::NextFree() noexcept {
 Sound::Sound()
 : handle(AL_NONE)
 , duration(0) {
-       alGenBuffers(1, &handle);
-       ALenum err = alGetError();
-       if (err != AL_NO_ERROR) {
-               throw ALError(err, "alGenBuffers");
-       }
+
 }
 
 Sound::Sound(const char *file)
@@ -176,18 +176,19 @@ Sound::~Sound() {
                ALenum err = alGetError();
                if (err != AL_NO_ERROR) {
                        std::cerr << "warning: alDeleteBuffers failed with " << al_error_string(err) << std::endl;
-                       //throw ALError(err, "alDeleteBuffers");
                }
        }
 }
 
 Sound::Sound(Sound &&other)
-: handle(other.handle) {
+: handle(other.handle)
+, duration(other.duration) {
        other.handle = AL_NONE;
 }
 
 Sound &Sound::operator =(Sound &&other) {
        std::swap(handle, other.handle);
+       std::swap(duration, other.duration);
        return *this;
 }
 
@@ -195,4 +196,18 @@ void Sound::Bind(ALuint src) const {
        alSourcei(src, AL_BUFFER, handle);
 }
 
+
+SoundBank::SoundBank()
+: sounds() {
+
+}
+
+void SoundBank::Load(const AssetLoader &loader, const ResourceIndex &index) {
+       sounds.clear();
+       sounds.resize(index.Size());
+       for (const auto &entry : index.Entries()) {
+               sounds[entry.second] = loader.LoadSound(entry.first);
+       }
+}
+
 }