From 79eaccb01ba768ac949825c73cbe96bcbd7cf105 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 5 Dec 2016 06:37:22 -0800 Subject: [PATCH] Add a method to retrieve a buffer's name This is the name it was cached with, not the actual filename if any resourceNotFound handler provided an alternative. --- include/AL/alure2.h | 3 +++ src/buffer.h | 8 ++++++-- src/context.cpp | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/AL/alure2.h b/include/AL/alure2.h index 818dfb8..449dca1 100644 --- a/include/AL/alure2.h +++ b/include/AL/alure2.h @@ -589,6 +589,9 @@ public: */ virtual BufferLoadStatus getLoadStatus() = 0; + /** Retrieves the name the buffer was created with. */ + virtual const String &getName() const = 0; + /** Queries if the buffer is in use and can't be removed. */ virtual bool isInUse() const = 0; }; diff --git a/src/buffer.h b/src/buffer.h index 3dc6c43..29ad532 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -31,11 +31,13 @@ class ALBuffer : public Buffer { Vector mSources; + String mName; + public: - ALBuffer(ALContext *context, ALuint id, ALuint freq, ChannelConfig config, SampleType type, bool preloaded) + ALBuffer(ALContext *context, ALuint id, ALuint freq, ChannelConfig config, SampleType type, bool preloaded, const String &name) : mContext(context), mId(id), mFrequency(freq), mChannelConfig(config), mSampleType(type), mLoadStatus(preloaded ? BufferLoadStatus::Ready : BufferLoadStatus::Pending), - mIsLoaded(preloaded) + mIsLoaded(preloaded), mName(name) { } virtual ~ALBuffer() { } @@ -70,6 +72,8 @@ public: BufferLoadStatus getLoadStatus() override final; + const String &getName() const override final { return mName; } + bool isInUse() const override final { return (mSources.size() > 0); } }; diff --git a/src/context.cpp b/src/context.cpp index b1e6e33..f78e617 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -529,7 +529,7 @@ Buffer *ALContext::getBuffer(const String &name) if(alGetError() != AL_NO_ERROR) throw std::runtime_error("Failed to buffer data"); - ALBuffer *buffer = new ALBuffer(this, bid, srate, chans, type, true); + ALBuffer *buffer = new ALBuffer(this, bid, srate, chans, type, true, name); return mBuffers.insert(std::make_pair(name, buffer)).first->second; } catch(...) { @@ -561,7 +561,7 @@ Buffer *ALContext::getBufferAsync(const String &name) if(alGetError() != AL_NO_ERROR) throw std::runtime_error("Failed to buffer data"); - ALBuffer *buffer = new ALBuffer(this, bid, srate, chans, type, false); + ALBuffer *buffer = new ALBuffer(this, bid, srate, chans, type, false, name); if(mThread.get_id() == std::thread::id()) mThread = std::thread(std::mem_fn(&ALContext::backgroundProc), this); -- 2.11.4.GIT