summaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-21 00:54:37 -0700
committerChris Robinson <[email protected]>2014-03-21 01:23:01 -0700
commitff63188cc2eb307eb874350e5281733d9c50f258 (patch)
treec422ded3a9125811f5658fb279aef96245c78268 /OpenAL32
parente6e3937fa9d1d192bc26b900438b45c0e6eb5be2 (diff)
Add a generic vector interface and use it for the active effect slots
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h9
-rw-r--r--OpenAL32/alAuxEffectSlot.c34
-rw-r--r--OpenAL32/alState.c4
3 files changed, 20 insertions, 27 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index a00f2d4c..0f4a3c7e 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -22,6 +22,7 @@
#include "atomic.h"
#include "uintmap.h"
+#include "vector.h"
#ifndef ALC_SOFT_HRTF
#define ALC_SOFT_HRTF 1
@@ -722,6 +723,10 @@ struct ALCdevice_struct
#define MIXER_THREAD_NAME "alsoft-mixer"
+typedef struct ALeffectslot *ALeffectslotPtr;
+DECL_VECTOR(ALeffectslotPtr)
+
+
struct ALCcontext_struct
{
volatile RefCount ref;
@@ -747,9 +752,7 @@ struct ALCcontext_struct
ALsizei ActiveSourceCount;
ALsizei MaxActiveSources;
- struct ALeffectslot **ActiveEffectSlots;
- ALsizei ActiveEffectSlotCount;
- ALsizei MaxActiveEffectSlots;
+ vector_ALeffectslotPtr ActiveAuxSlots;
ALCdevice *Device;
const ALCchar *ExtensionList;
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index aa071de2..dcd64fc8 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -380,14 +380,14 @@ static ALvoid RemoveEffectSlotArray(ALCcontext *context, ALeffectslot *slot)
ALeffectslot **slotlist, **slotlistend;
LockContext(context);
- slotlist = context->ActiveEffectSlots;
- slotlistend = slotlist + context->ActiveEffectSlotCount;
+ slotlist = VECTOR_ITER_BEGIN(context->ActiveAuxSlots);
+ slotlistend = VECTOR_ITER_END(context->ActiveAuxSlots);
while(slotlist != slotlistend)
{
if(*slotlist == slot)
{
*slotlist = *(--slotlistend);
- context->ActiveEffectSlotCount--;
+ VECTOR_POP_BACK(context->ActiveAuxSlots);
break;
}
slotlist++;
@@ -397,33 +397,23 @@ static ALvoid RemoveEffectSlotArray(ALCcontext *context, ALeffectslot *slot)
static ALenum AddEffectSlotArray(ALCcontext *context, ALsizei count, const ALuint *slots)
{
- ALsizei i;
+ ALsizei total = count + VECTOR_SIZE(context->ActiveAuxSlots);
LockContext(context);
- if(count > context->MaxActiveEffectSlots-context->ActiveEffectSlotCount)
+ if(total < VECTOR_SIZE(context->ActiveAuxSlots) || VECTOR_RESERVE(context->ActiveAuxSlots, total) == AL_FALSE)
{
- 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)
- {
- UnlockContext(context);
- return AL_OUT_OF_MEMORY;
- }
- context->ActiveEffectSlots = temp;
- context->MaxActiveEffectSlots = newcount;
+ UnlockContext(context);
+ return AL_OUT_OF_MEMORY;
}
- for(i = 0;i < count;i++)
+
+ while(VECTOR_SIZE(context->ActiveAuxSlots) < total)
{
- ALeffectslot *slot = LookupEffectSlot(context, slots[i]);
+ ALeffectslot *slot = LookupEffectSlot(context, *(slots++));
assert(slot != NULL);
- context->ActiveEffectSlots[context->ActiveEffectSlotCount++] = slot;
+ VECTOR_PUSH_BACK(context->ActiveAuxSlots, slot);
}
UnlockContext(context);
+
return AL_NO_ERROR;
}
diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c
index f97168d6..c6deda46 100644
--- a/OpenAL32/alState.c
+++ b/OpenAL32/alState.c
@@ -748,8 +748,8 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
src++;
}
- slot = context->ActiveEffectSlots;
- slot_end = slot + context->ActiveEffectSlotCount;
+ slot = VECTOR_ITER_BEGIN(context->ActiveAuxSlots);
+ slot_end = VECTOR_ITER_END(context->ActiveAuxSlots);
while(slot != slot_end)
{
if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))