diff options
author | Chris Robinson <[email protected]> | 2019-01-09 18:29:22 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-09 18:29:22 -0800 |
commit | e7d77f5caa424597ab8023f92f00bfa50f8b78f8 (patch) | |
tree | c6a4796a02dd0e3349ab697f108335ce22794a47 /Alc | |
parent | 30184613a53c9eb013fee10403aa9cd97d4ea5e1 (diff) |
Use a vector for ALeffectslotArray
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 20 | ||||
-rw-r--r-- | Alc/alcontext.h | 2 | ||||
-rw-r--r-- | Alc/alu.cpp | 15 |
3 files changed, 16 insertions, 21 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index e2ac0bce..ca13e911 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2324,22 +2324,16 @@ static ALvoid InitContext(ALCcontext *Context) ALeffectslotArray *auxslots; //Validate Context - if(Context->DefaultSlot) + if(!Context->DefaultSlot) + auxslots = new ALeffectslotArray{}; + else { - static constexpr int count{1}; /* Allocate twice as much space for effect slots so the mixer has a * place to sort them. */ - auxslots = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN, - FAM_SIZE(ALeffectslotArray, slot, count*2))); - auxslots->count = count; - auxslots->slot[0] = Context->DefaultSlot.get(); - } - else - { - auxslots = static_cast<ALeffectslotArray*>(al_calloc(DEF_ALIGN, - sizeof(ALeffectslotArray))); - auxslots->count = 0; + auxslots = new ALeffectslotArray{}; + auxslots->reserve(2); + auxslots->push_back(Context->DefaultSlot.get()); } Context->ActiveAuxSlots.store(auxslots, std::memory_order_relaxed); @@ -2418,7 +2412,7 @@ ALCcontext::~ALCcontext() } TRACE("Freed " SZFMT " AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); - al_free(ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)); + delete ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed); DefaultSlot = nullptr; count = std::count_if(EffectSlotList.cbegin(), EffectSlotList.cend(), diff --git a/Alc/alcontext.h b/Alc/alcontext.h index fa16859e..dc9ada55 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -26,7 +26,6 @@ struct ALlistenerProps; struct ALvoiceProps; struct ALeffectslotProps; struct ALvoice; -struct ALeffectslotArray; struct RingBuffer; enum class DistanceModel { @@ -108,6 +107,7 @@ struct ALCcontext { std::atomic<ALsizei> VoiceCount{0}; ALsizei MaxVoices{0}; + using ALeffectslotArray = al::vector<ALeffectslot*>; std::atomic<ALeffectslotArray*> ActiveAuxSlots{nullptr}; std::thread EventThread; diff --git a/Alc/alu.cpp b/Alc/alu.cpp index 42e31b88..55e4e5c7 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -28,6 +28,7 @@ #include <cmath> #include <limits> +#include <numeric> #include <algorithm> #include <functional> @@ -1437,9 +1438,9 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) { bool cforce{CalcContextParams(ctx)}; bool force{CalcListenerParams(ctx) || cforce}; - std::for_each(slots->slot, slots->slot+slots->count, - [ctx,cforce,&force](ALeffectslot *slot) -> void - { force |= CalcEffectSlotParams(slot, ctx, cforce); } + force = std::accumulate(slots->begin(), slots->end(), force, + [ctx,cforce](bool force, ALeffectslot *slot) -> bool + { return CalcEffectSlotParams(slot, ctx, cforce) | force; } ); std::for_each(ctx->Voices, ctx->Voices+ctx->VoiceCount.load(std::memory_order_acquire), @@ -1463,7 +1464,7 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) ProcessParamUpdates(ctx, auxslots); /* Clear auxiliary effect slot mixing buffers. */ - std::for_each(auxslots->slot, auxslots->slot+auxslots->count, + std::for_each(auxslots->begin(), auxslots->end(), [SamplesToDo](ALeffectslot *slot) -> void { std::for_each(slot->WetBuffer, slot->WetBuffer+slot->NumChannels, @@ -1491,9 +1492,9 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) ); /* Process effects. */ - if(auxslots->count < 1) return; - auto slots = auxslots->slot; - auto slots_end = slots + auxslots->count; + if(auxslots->size() < 1) return; + auto slots = auxslots->data(); + auto slots_end = slots + auxslots->size(); /* First sort the slots into scratch storage, so that effects come before * their effect target (or their targets' target). |