From e6771f9e109573c5ce3138842bcebd90f3ef792d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 20 Oct 2017 15:36:35 -0700 Subject: [PATCH] Keep the auxiliary slots' source sends sorted --- src/auxeffectslot.cpp | 22 ++++++++++++++++++++++ src/auxeffectslot.h | 12 ++---------- src/source.cpp | 27 +++++++-------------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/auxeffectslot.cpp b/src/auxeffectslot.cpp index aae901a..c316b57 100644 --- a/src/auxeffectslot.cpp +++ b/src/auxeffectslot.cpp @@ -14,6 +14,28 @@ namespace alure { +static inline bool operator<(const SourceSend &lhs, const SourceSend &rhs) +{ return lhs.mSource < rhs.mSource || (lhs.mSource == rhs.mSource && lhs.mSend < rhs.mSend); } +static inline bool operator==(const SourceSend &lhs, const SourceSend &rhs) +{ return lhs.mSource == rhs.mSource && lhs.mSend == rhs.mSend; } +static inline bool operator!=(const SourceSend &lhs, const SourceSend &rhs) +{ return !(lhs == rhs); } + +void AuxiliaryEffectSlotImpl::addSourceSend(SourceSend source_send) +{ + auto iter = std::lower_bound(mSourceSends.begin(), mSourceSends.end(), source_send); + if(iter == mSourceSends.end() || *iter != source_send) + mSourceSends.insert(iter, source_send); +} + +void AuxiliaryEffectSlotImpl::removeSourceSend(SourceSend source_send) +{ + auto iter = std::lower_bound(mSourceSends.begin(), mSourceSends.end(), source_send); + if(iter != mSourceSends.end() && *iter == source_send) + mSourceSends.erase(iter); +} + + void AuxiliaryEffectSlotImpl::setGain(ALfloat gain) { if(!(gain >= 0.0f && gain <= 1.0f)) diff --git a/src/auxeffectslot.h b/src/auxeffectslot.h index c807b58..a17dab6 100644 --- a/src/auxeffectslot.h +++ b/src/auxeffectslot.h @@ -7,9 +7,6 @@ namespace alure { -inline bool operator==(const SourceSend &lhs, const SourceSend &rhs) -{ return lhs.mSource == rhs.mSource && lhs.mSend == rhs.mSend; } - class AuxiliaryEffectSlotImpl { ContextImpl *const mContext; ALuint mId; @@ -21,13 +18,8 @@ public: : mContext(context), mId(id) { } - void addSourceSend(Source source, ALuint send) - { mSourceSends.emplace_back((SourceSend){source, send}); } - void removeSourceSend(Source source, ALuint send) - { - auto iter = std::find(mSourceSends.cbegin(), mSourceSends.cend(), SourceSend{source, send}); - if(iter != mSourceSends.cend()) mSourceSends.erase(iter); - } + void addSourceSend(SourceSend source_send); + void removeSourceSend(SourceSend source_send); ContextImpl *getContext() { return mContext; } const ALuint &getId() const { return mId; } diff --git a/src/source.cpp b/src/source.cpp index df3603b..52da2dc 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -220,7 +220,7 @@ void SourceImpl::resetProperties() for(auto &i : mEffectSlots) { if(i.second.mSlot) - i.second.mSlot->removeSourceSend(Source(this), i.first); + i.second.mSlot->removeSourceSend({Source(this), i.first}); if(i.second.mFilter) mContext->alDeleteFilters(1, &i.second.mFilter); } @@ -1207,14 +1207,14 @@ void SourceImpl::setAuxiliarySend(AuxiliaryEffectSlot auxslot, ALuint send) if(siter == mEffectSlots.end()) { if(!slot) return; - slot->addSourceSend(Source(this), send); + slot->addSourceSend({Source(this), send}); siter = mEffectSlots.insert(std::make_pair(send, SendProps(slot))).first; } else if(siter->second.mSlot != slot) { - if(slot) slot->addSourceSend(Source(this), send); + if(slot) slot->addSourceSend({Source(this), send}); if(siter->second.mSlot) - siter->second.mSlot->removeSourceSend(Source(this), send); + siter->second.mSlot->removeSourceSend({Source(this), send}); siter->second.mSlot = slot; } @@ -1242,16 +1242,16 @@ void SourceImpl::setAuxiliarySendFilter(AuxiliaryEffectSlot auxslot, ALuint send if(!filterid && !slot) return; - if(slot) slot->addSourceSend(Source(this), send); + if(slot) slot->addSourceSend({Source(this), send}); siter = mEffectSlots.insert(std::make_pair(send, SendProps(slot, filterid))).first; } else { if(siter->second.mSlot != slot) { - if(slot) slot->addSourceSend(Source(this), send); + if(slot) slot->addSourceSend({Source(this), send}); if(siter->second.mSlot) - siter->second.mSlot->removeSourceSend(Source(this), send); + siter->second.mSlot->removeSourceSend({Source(this), send}); siter->second.mSlot = slot; } setFilterParams(siter->second.mFilter, filter); @@ -1269,19 +1269,6 @@ void SourceImpl::release() { stop(); - if(mDirectFilter) - mContext->alDeleteFilters(1, &mDirectFilter); - mDirectFilter = AL_FILTER_NULL; - - for(auto &i : mEffectSlots) - { - if(i.second.mSlot) - i.second.mSlot->removeSourceSend(Source(this), i.first); - if(i.second.mFilter) - mContext->alDeleteFilters(1, &i.second.mFilter); - } - mEffectSlots.clear(); - resetProperties(); mContext->freeSource(this); } -- 2.11.4.GIT