diff --git a/Alc/alc.cpp b/Alc/alc.cpp index dcf35c63..66c19b86 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2272,9 +2272,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) almtx_lock(&context->PropLock); almtx_lock(&context->EffectSlotLock); - for(pos = 0;pos < (ALsizei)VECTOR_SIZE(context->EffectSlotList);pos++) + for(auto &slot : context->EffectSlotList) { - ALeffectslot *slot = VECTOR_ELEM(context->EffectSlotList, pos); ALeffectState *state = slot->Effect.State; state->OutBuffer = device->Dry.Buffer; @@ -2611,7 +2610,6 @@ static ALvoid InitContext(ALCcontext *Context) ATOMIC_INIT(&Context->LastError, AL_NO_ERROR); Context->NumSources = 0; almtx_init(&Context->SourceLock, almtx_plain); - VECTOR_INIT(Context->EffectSlotList); almtx_init(&Context->EffectSlotLock, almtx_plain); if(Context->DefaultSlot) @@ -2737,10 +2735,7 @@ static void FreeContext(ALCcontext *context) TRACE("Freed " SZFMT " AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); ReleaseALAuxiliaryEffectSlots(context); -#define FREE_EFFECTSLOTPTR(x) al_free(*(x)) - VECTOR_FOR_EACH(ALeffectslotPtr, context->EffectSlotList, FREE_EFFECTSLOTPTR); -#undef FREE_EFFECTSLOTPTR - VECTOR_DEINIT(context->EffectSlotList); + context->EffectSlotList.clear(); almtx_destroy(&context->EffectSlotLock); count = 0; diff --git a/Alc/alcontext.h b/Alc/alcontext.h index a4e397be..d0a2dc51 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -54,7 +54,7 @@ struct ALCcontext_struct { ALuint NumSources; almtx_t SourceLock; - vector_ALeffectslotPtr EffectSlotList; + al::vector EffectSlotList; almtx_t EffectSlotLock; ATOMIC(ALenum) LastError; diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index bcf5c967..119bb038 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include "AL/al.h" #include "AL/alc.h" @@ -77,10 +79,10 @@ static void ALeffectState_IncRef(ALeffectState *state); static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) { - id--; - if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList))) + --id; + if(UNLIKELY(id >= context->EffectSlotList.size())) return nullptr; - return VECTOR_ELEM(context->EffectSlotList, id); + return context->EffectSlotList[id]; } static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) @@ -123,31 +125,29 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo device = context->Device; for(cur = 0;cur < n;cur++) { - ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList); - ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList); - ALeffectslot *slot = nullptr; - ALenum err = AL_OUT_OF_MEMORY; - - for(;iter != end;iter++) + auto iter = std::find_if(context->EffectSlotList.begin(), context->EffectSlotList.end(), + [](const ALeffectslotPtr &entry) noexcept -> bool + { return !entry; } + ); + if(iter == context->EffectSlotList.end()) { - if(!*iter) - break; - } - if(iter == end) - { - if(device->AuxiliaryEffectSlotMax == VECTOR_SIZE(context->EffectSlotList)) + if(device->AuxiliaryEffectSlotMax == context->EffectSlotList.size()) { UnlockEffectSlotList(context); alDeleteAuxiliaryEffectSlots(cur, effectslots); SETERR_GOTO(context, AL_OUT_OF_MEMORY, done, "Exceeding %u auxiliary effect slot limit", device->AuxiliaryEffectSlotMax); } - VECTOR_PUSH_BACK(context->EffectSlotList, nullptr); - iter = &VECTOR_BACK(context->EffectSlotList); + context->EffectSlotList.emplace_back(nullptr); + iter = context->EffectSlotList.end() - 1; } - slot = static_cast(al_calloc(16, sizeof(ALeffectslot))); + + ALenum err{AL_OUT_OF_MEMORY}; + auto slot = static_cast(al_calloc(16, sizeof(ALeffectslot))); + if(slot) slot = new (slot) ALeffectslot{}; if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { + slot->~ALeffectslot(); al_free(slot); UnlockEffectSlotList(context); @@ -156,7 +156,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo } aluInitEffectPanning(slot); - slot->id = (iter - VECTOR_BEGIN(context->EffectSlotList)) + 1; + slot->id = std::distance(context->EffectSlotList.begin(), iter) + 1; *iter = slot; effectslots[cur] = slot->id; @@ -198,11 +198,11 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint * { if((slot=LookupEffectSlot(context, effectslots[i])) == nullptr) continue; - VECTOR_ELEM(context->EffectSlotList, effectslots[i]-1) = nullptr; + context->EffectSlotList[effectslots[i]-1] = nullptr; DeinitEffectSlot(slot); - memset(slot, 0, sizeof(*slot)); + slot->~ALeffectslot(); al_free(slot); } @@ -785,19 +785,16 @@ void UpdateAllEffectSlotProps(ALCcontext *context) ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *context) { - ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList); - ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList); size_t leftover = 0; - - for(;iter != end;iter++) + for(auto &entry : context->EffectSlotList) { - ALeffectslot *slot = *iter; + ALeffectslot *slot = entry; if(!slot) continue; - *iter = nullptr; + entry = nullptr; DeinitEffectSlot(slot); - memset(slot, 0, sizeof(*slot)); + slot->~ALeffectslot(); al_free(slot); ++leftover; } diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index e1c65cd8..e3fd4557 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -104,10 +104,10 @@ static inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) { - id--; - if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList))) - return NULL; - return VECTOR_ELEM(context->EffectSlotList, id); + --id; + if(UNLIKELY(id >= context->EffectSlotList.size())) + return nullptr; + return context->EffectSlotList[id]; }