diff options
author | Sven Gothel <[email protected]> | 2014-06-10 05:30:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-10 05:30:02 +0200 |
commit | f95bf4457fbc31112fa82dacbc1b7e094b9fd1cf (patch) | |
tree | 965ba5b8e6fc8e6bfe7a981c1dfb1179bb9adcde /OpenAL32/alAuxEffectSlot.c | |
parent | 7297c3214a4c648aaee81a9877da15b88f798197 (diff) | |
parent | c07fb7b45c1e345dbaa439882250de5b2213026f (diff) |
Merge branch 'UPSTREAM' into UPSTREAM_MERGE
Diffstat (limited to 'OpenAL32/alAuxEffectSlot.c')
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 75 |
1 files changed, 32 insertions, 43 deletions
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index aa071de2..9f554cb0 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -35,8 +35,8 @@ extern inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id); extern inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id); -static ALenum AddEffectSlotArray(ALCcontext *Context, ALsizei count, const ALuint *slots); -static ALvoid RemoveEffectSlotArray(ALCcontext *Context, ALeffectslot *slot); +static ALenum AddEffectSlotArray(ALCcontext *Context, const_vector_ALeffectslotPtr slots); +static void RemoveEffectSlotArray(ALCcontext *Context, const ALeffectslot *slot); static UIntMap EffectStateFactoryMap; @@ -52,14 +52,20 @@ static inline ALeffectStateFactory *getFactoryByType(ALenum type) AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *context; + vector_ALeffectslotPtr slotvec; ALsizei cur; ALenum err; context = GetContextRef(); if(!context) return; + VECTOR_INIT(slotvec); + if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + if(!VECTOR_RESERVE(slotvec, n)) + SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); + for(cur = 0;cur < n;cur++) { ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); @@ -84,9 +90,11 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo SET_ERROR_AND_GOTO(context, err, done); } + VECTOR_PUSH_BACK(slotvec, slot); + effectslots[cur] = slot->id; } - err = AddEffectSlotArray(context, n, effectslots); + err = AddEffectSlotArray(context, slotvec); if(err != AL_NO_ERROR) { alDeleteAuxiliaryEffectSlots(cur, effectslots); @@ -94,6 +102,8 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo } done: + VECTOR_DEINIT(slotvec); + ALCcontext_DecRef(context); } @@ -112,7 +122,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint * { if((slot=LookupEffectSlot(context, effectslots[i])) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); - if(slot->ref != 0) + if(ReadRef(&slot->ref) != 0) SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } @@ -375,56 +385,37 @@ done: } -static ALvoid RemoveEffectSlotArray(ALCcontext *context, ALeffectslot *slot) +static ALenum AddEffectSlotArray(ALCcontext *context, const_vector_ALeffectslotPtr slots) { - ALeffectslot **slotlist, **slotlistend; + ALenum err = AL_NO_ERROR; LockContext(context); - slotlist = context->ActiveEffectSlots; - slotlistend = slotlist + context->ActiveEffectSlotCount; - while(slotlist != slotlistend) - { - if(*slotlist == slot) - { - *slotlist = *(--slotlistend); - context->ActiveEffectSlotCount--; - break; - } - slotlist++; - } + if(!VECTOR_INSERT(context->ActiveAuxSlots, VECTOR_ITER_END(context->ActiveAuxSlots), + VECTOR_ITER_BEGIN(slots), VECTOR_ITER_END(slots))) + err = AL_OUT_OF_MEMORY; UnlockContext(context); + + return err; } -static ALenum AddEffectSlotArray(ALCcontext *context, ALsizei count, const ALuint *slots) +static void RemoveEffectSlotArray(ALCcontext *context, const ALeffectslot *slot) { - ALsizei i; + ALeffectslot **slotlist, **slotlistend; LockContext(context); - if(count > context->MaxActiveEffectSlots-context->ActiveEffectSlotCount) + slotlist = VECTOR_ITER_BEGIN(context->ActiveAuxSlots); + slotlistend = VECTOR_ITER_END(context->ActiveAuxSlots); + while(slotlist != slotlistend) { - ALsizei newcount; - void *temp = NULL; - - newcount = context->MaxActiveEffectSlots ? (context->MaxActiveEffectSlots<<1) : 1; - if(newcount > context->MaxActiveEffectSlots) - temp = realloc(context->ActiveEffectSlots, - newcount * sizeof(*context->ActiveEffectSlots)); - if(!temp) + if(*slotlist == slot) { - UnlockContext(context); - return AL_OUT_OF_MEMORY; + *slotlist = VECTOR_BACK(context->ActiveAuxSlots); + VECTOR_POP_BACK(context->ActiveAuxSlots); + break; } - context->ActiveEffectSlots = temp; - context->MaxActiveEffectSlots = newcount; - } - for(i = 0;i < count;i++) - { - ALeffectslot *slot = LookupEffectSlot(context, slots[i]); - assert(slot != NULL); - context->ActiveEffectSlots[context->ActiveEffectSlotCount++] = slot; + slotlist++; } UnlockContext(context); - return AL_NO_ERROR; } @@ -541,10 +532,8 @@ ALenum InitEffectSlot(ALeffectslot *slot) { for(i = 0;i < BUFFERSIZE;i++) slot->WetBuffer[c][i] = 0.0f; - slot->ClickRemoval[c] = 0.0f; - slot->PendingClicks[c] = 0.0f; } - slot->ref = 0; + InitRef(&slot->ref, 0); return AL_NO_ERROR; } |