From 362979cefb413e04dd4698d282779436e0a86bbc Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 18 Nov 2018 22:45:55 -0800 Subject: Use a normal vector for effect sublists --- OpenAL32/Include/alMain.h | 7 ++--- OpenAL32/alAuxEffectSlot.cpp | 9 +++--- OpenAL32/alEffect.cpp | 72 ++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 48 deletions(-) (limited to 'OpenAL32') diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 38c0471b..8a85f141 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -514,10 +514,9 @@ typedef struct BufferSubList { } BufferSubList; typedef struct EffectSubList { - ALuint64 FreeMask; - struct ALeffect *Effects; /* 64 */ + ALuint64 FreeMask{0u}; + struct ALeffect *Effects{nullptr}; /* 64 */ } EffectSubList; -TYPEDEF_VECTOR(EffectSubList, vector_EffectSubList) typedef struct FilterSubList { ALuint64 FreeMask; @@ -609,7 +608,7 @@ struct ALCdevice_struct { almtx_t BufferLock; // Map of Effects for this device - vector_EffectSubList EffectList{}; + al::vector EffectList; almtx_t EffectLock; // Map of Filters for this device diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index 6a0cc34c..fc4b4d1b 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -87,16 +87,15 @@ static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) { - EffectSubList *sublist; ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= VECTOR_SIZE(device->EffectList))) + if(UNLIKELY(lidx >= device->EffectList.size())) return nullptr; - sublist = &VECTOR_ELEM(device->EffectList, lidx); - if(UNLIKELY(sublist->FreeMask & (U64(1)<EffectList[lidx]; + if(UNLIKELY(sublist.FreeMask & (U64(1)<Effects + slidx; + return sublist.Effects + slidx; } diff --git a/OpenAL32/alEffect.cpp b/OpenAL32/alEffect.cpp index 4f25b5f4..54cfad67 100644 --- a/OpenAL32/alEffect.cpp +++ b/OpenAL32/alEffect.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include "AL/al.h" #include "AL/alc.h" @@ -58,16 +60,15 @@ static void InitEffectParams(ALeffect *effect, ALenum type); static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) { - EffectSubList *sublist; ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= VECTOR_SIZE(device->EffectList))) - return NULL; - sublist = &VECTOR_ELEM(device->EffectList, lidx); - if(UNLIKELY(sublist->FreeMask & (U64(1)<Effects + slidx; + if(UNLIKELY(lidx >= device->EffectList.size())) + return nullptr; + EffectSubList &sublist = device->EffectList[lidx]; + if(UNLIKELY(sublist.FreeMask & (U64(1)<Device; - EffectSubList *sublist, *subend; - ALeffect *effect = NULL; - ALsizei lidx = 0; - ALsizei slidx; - almtx_lock(&device->EffectLock); - sublist = VECTOR_BEGIN(device->EffectList); - subend = VECTOR_END(device->EffectList); - for(;sublist != subend;++sublist) + + auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(), + [](const EffectSubList &entry) noexcept -> bool + { return entry.FreeMask != 0; } + ); + + auto lidx = std::distance(device->EffectList.begin(), sublist); + ALeffect *effect{nullptr}; + ALsizei slidx{0}; + if(LIKELY(sublist != device->EffectList.end())) { - if(sublist->FreeMask) - { - slidx = CTZ64(sublist->FreeMask); - effect = sublist->Effects + slidx; - break; - } - ++lidx; + slidx = CTZ64(sublist->FreeMask); + effect = sublist->Effects + slidx; } - if(UNLIKELY(!effect)) + else { - const EffectSubList empty_sublist = { 0, NULL }; /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(VECTOR_SIZE(device->EffectList) >= 1<<25)) + if(UNLIKELY(device->EffectList.size() >= 1<<25)) { almtx_unlock(&device->EffectLock); alSetError(context, AL_OUT_OF_MEMORY, "Too many effects allocated"); return NULL; } - lidx = (ALsizei)VECTOR_SIZE(device->EffectList); - VECTOR_PUSH_BACK(device->EffectList, empty_sublist); - sublist = &VECTOR_BACK(device->EffectList); + device->EffectList.emplace_back(); + sublist = device->EffectList.end() - 1; sublist->FreeMask = ~U64(0); sublist->Effects = static_cast(al_calloc(16, sizeof(ALeffect)*64)); if(UNLIKELY(!sublist->Effects)) { - VECTOR_POP_BACK(device->EffectList); + device->EffectList.pop_back(); almtx_unlock(&device->EffectLock); alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect batch"); return NULL; @@ -421,7 +417,7 @@ static ALeffect *AllocEffect(ALCcontext *context) effect = sublist->Effects + slidx; } - memset(effect, 0, sizeof(*effect)); + effect = new (effect) ALeffect{}; InitEffectParams(effect, AL_EFFECT_NULL); /* Add 1 to avoid effect ID 0. */ @@ -439,30 +435,28 @@ static void FreeEffect(ALCdevice *device, ALeffect *effect) ALsizei lidx = id >> 6; ALsizei slidx = id & 0x3f; - memset(effect, 0, sizeof(*effect)); + effect->~ALeffect(); - VECTOR_ELEM(device->EffectList, lidx).FreeMask |= U64(1) << slidx; + device->EffectList[lidx].FreeMask |= U64(1) << slidx; } void ReleaseALEffects(ALCdevice *device) { - EffectSubList *sublist = VECTOR_BEGIN(device->EffectList); - EffectSubList *subend = VECTOR_END(device->EffectList); size_t leftover = 0; - for(;sublist != subend;++sublist) + for(auto &sublist : device->EffectList) { - ALuint64 usemask = ~sublist->FreeMask; + ALuint64 usemask = ~sublist.FreeMask; while(usemask) { ALsizei idx = CTZ64(usemask); - ALeffect *effect = sublist->Effects + idx; + ALeffect *effect = sublist.Effects + idx; - memset(effect, 0, sizeof(*effect)); + effect->~ALeffect(); ++leftover; usemask &= ~(U64(1) << idx); } - sublist->FreeMask = ~usemask; + sublist.FreeMask = ~usemask; } if(leftover > 0) WARN("(%p) Deleted " SZFMT " Effect%s\n", device, leftover, (leftover==1)?"":"s"); -- cgit v1.2.3