diff options
author | Chris Robinson <[email protected]> | 2010-05-12 02:20:14 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-05-12 02:20:14 -0700 |
commit | af4faaf6660d02ce593e07b97d05020b44ed06e4 (patch) | |
tree | af18189c604ec6c165084fe3c49bb1cdc2c3603f | |
parent | f2548570b85b6deaba57f1bfa2ded87bf2f42886 (diff) |
Use a UIntMap for the effect slot list
-rw-r--r-- | Alc/ALc.c | 9 | ||||
-rw-r--r-- | Alc/ALu.c | 6 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 4 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 104 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 4 |
5 files changed, 56 insertions, 71 deletions
@@ -1513,12 +1513,12 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin for(i = 0;i < device->NumContexts;i++) { ALCcontext *context = device->Contexts[i]; - ALeffectslot *slot; ALsizei pos; SuspendContext(context); - for(slot = context->EffectSlotList;slot != NULL;slot = slot->next) + for(pos = 0;pos < context->EffectSlotMap.size;pos++) { + ALeffectslot *slot = context->EffectSlotMap.array[pos].value; if(!slot->EffectState) continue; @@ -1649,13 +1649,14 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) } ResetUIntMap(&context->SourceMap); - if(context->EffectSlotCount > 0) + if(context->EffectSlotMap.size > 0) { #ifdef _DEBUG - AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotCount); + AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size); #endif ReleaseALAuxiliaryEffectSlots(context); } + ResetUIntMap(&context->EffectSlotMap); list = &g_pContextList; while(*list != context) @@ -1409,6 +1409,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ALfloat samp; int fpuState; ALuint i, j, c; + ALsizei e; #if defined(HAVE_FESETROUND) fpuState = fegetround(); @@ -1438,15 +1439,14 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) MixSomeSources(ALContext, DryBuffer, SamplesToDo); /* effect slot processing */ - ALEffectSlot = ALContext->EffectSlotList; - while(ALEffectSlot) + for(e = 0;e < ALContext->EffectSlotMap.size;e++) { + ALEffectSlot = ALContext->EffectSlotMap.array[e].value; if(ALEffectSlot->EffectState) ALEffect_Process(ALEffectSlot->EffectState, ALEffectSlot, SamplesToDo, ALEffectSlot->WetBuffer, DryBuffer); for(i = 0;i < SamplesToDo;i++) ALEffectSlot->WetBuffer[i] = 0.0f; - ALEffectSlot = ALEffectSlot->next; } ProcessContext(ALContext); } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 5f40bcc7..5baca397 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -346,9 +346,7 @@ struct ALCcontext_struct ALlistener Listener; UIntMap SourceMap; - - struct ALeffectslot *EffectSlotList; - ALuint EffectSlotCount; + UIntMap EffectSlotMap; struct ALdatabuffer *SampleSource; struct ALdatabuffer *SampleSink; diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 0ff10ab2..b659c5f5 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -34,9 +34,10 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); -DECL_VERIFIER(EffectSlot, ALeffectslot, effectslot) DECL_VERIFIER(Effect, ALeffect, effect) +#define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k))) + AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; @@ -45,55 +46,50 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo Context = GetContextSuspended(); if(!Context) return; - if (n > 0) + if(n > 0) { ALCdevice *Device = Context->Device; - if(Context->EffectSlotCount+n <= Device->AuxiliaryEffectSlotMax) + if(Context->EffectSlotMap.size+n <= (ALsizei)Device->AuxiliaryEffectSlotMax) { // Check that enough memory has been allocted in the 'effectslots' array for n Effect Slots - if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) + if(!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) { - ALeffectslot *end; - ALeffectslot **list = &Context->EffectSlotList; - while(*list) - list = &(*list)->next; + ALenum err; - end = *list; while(i < n) { - *list = calloc(1, sizeof(ALeffectslot)); - if(!(*list) || !((*list)->EffectState=NoneCreate())) + ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); + if(!slot || !(slot->EffectState=NoneCreate())) { + free(slot); // We must have run out or memory - free(*list); *list = NULL; - while(end->next) - { - ALeffectslot *temp = end->next; - end->next = temp->next; - - ALEffect_Destroy(temp->EffectState); - ALTHUNK_REMOVEENTRY(temp->effectslot); - Context->EffectSlotCount--; - free(temp); - } alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteAuxiliaryEffectSlots(i, effectslots); break; } - (*list)->Gain = 1.0; - (*list)->AuxSendAuto = AL_TRUE; - for(j = 0;j < BUFFERSIZE;j++) - (*list)->WetBuffer[j] = 0.0f; - (*list)->refcount = 0; + slot->effectslot = (ALuint)ALTHUNK_ADDENTRY(slot); + err = InsertUIntMapEntry(&Context->EffectSlotMap, + slot->effectslot, slot); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(slot->effectslot); + ALEffect_Destroy(slot->EffectState); + free(slot); - effectslots[i] = (ALuint)ALTHUNK_ADDENTRY(*list); - (*list)->effectslot = effectslots[i]; + alSetError(Context, err); + alDeleteAuxiliaryEffectSlots(i, effectslots); + break; + } - Context->EffectSlotCount++; - i++; + effectslots[i++] = slot->effectslot; - list = &(*list)->next; + slot->Gain = 1.0; + slot->AuxSendAuto = AL_TRUE; + for(j = 0;j < BUFFERSIZE;j++) + slot->WetBuffer[j] = 0.0f; + slot->refcount = 0; } } } @@ -118,7 +114,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect // Check that all effectslots are valid for (i = 0; i < n; i++) { - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslots[i])) == NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL) { alSetError(Context, AL_INVALID_NAME); break; @@ -139,25 +135,15 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect for (i = 0; i < n; i++) { // Recheck that the effectslot is valid, because there could be duplicated names - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslots[i])) != NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) != NULL) { - ALeffectslot **list; - - // Remove Source from list of Sources - list = &Context->EffectSlotList; - while(*list && *list != EffectSlot) - list = &(*list)->next; + ALEffect_Destroy(EffectSlot->EffectState); - if(*list) - *list = (*list)->next; + RemoveUIntMapKey(&Context->EffectSlotMap, EffectSlot->effectslot); ALTHUNK_REMOVEENTRY(EffectSlot->effectslot); - ALEffect_Destroy(EffectSlot->EffectState); - memset(EffectSlot, 0, sizeof(ALeffectslot)); free(EffectSlot); - - Context->EffectSlotCount--; } } } @@ -176,7 +162,7 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot) Context = GetContextSuspended(); if(!Context) return AL_FALSE; - result = (VerifyEffectSlot(Context->EffectSlotList, effectslot) ? + result = (LookupEffectSlot(Context->EffectSlotMap, effectslot) ? AL_TRUE : AL_FALSE); ProcessContext(Context); @@ -193,7 +179,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param Context = GetContextSuspended(); if(!Context) return; - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslot)) != NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslot)) != NULL) { switch(param) { @@ -258,7 +244,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum para Context = GetContextSuspended(); if(!Context) return; - if(VerifyEffectSlot(Context->EffectSlotList, effectslot) != NULL) + if(LookupEffectSlot(Context->EffectSlotMap, effectslot) != NULL) { switch(param) { @@ -286,7 +272,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param Context = GetContextSuspended(); if(!Context) return; - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslot)) != NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslot)) != NULL) { switch(param) { @@ -315,7 +301,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum para Context = GetContextSuspended(); if(!Context) return; - if(VerifyEffectSlot(Context->EffectSlotList, effectslot) != NULL) + if(LookupEffectSlot(Context->EffectSlotMap, effectslot) != NULL) { switch(param) { @@ -342,7 +328,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa Context = GetContextSuspended(); if(!Context) return; - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslot)) != NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslot)) != NULL) { switch(param) { @@ -372,7 +358,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum p Context = GetContextSuspended(); if(!Context) return; - if(VerifyEffectSlot(Context->EffectSlotList, effectslot) != NULL) + if(LookupEffectSlot(Context->EffectSlotMap, effectslot) != NULL) { switch(param) { @@ -400,7 +386,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa Context = GetContextSuspended(); if(!Context) return; - if((EffectSlot=VerifyEffectSlot(Context->EffectSlotList, effectslot)) != NULL) + if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslot)) != NULL) { switch(param) { @@ -426,7 +412,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p Context = GetContextSuspended(); if(!Context) return; - if(VerifyEffectSlot(Context->EffectSlotList, effectslot) != NULL) + if(LookupEffectSlot(Context->EffectSlotMap, effectslot) != NULL) { switch(param) { @@ -522,10 +508,11 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, AL ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) { - while(Context->EffectSlotList) + ALsizei pos; + for(pos = 0;pos < Context->EffectSlotMap.size;pos++) { - ALeffectslot *temp = Context->EffectSlotList; - Context->EffectSlotList = temp->next; + ALeffectslot *temp = Context->EffectSlotMap.array[pos].value; + Context->EffectSlotMap.array[pos].value = NULL; // Release effectslot structure ALEffect_Destroy(temp->EffectState); @@ -534,5 +521,4 @@ ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) memset(temp, 0, sizeof(ALeffectslot)); free(temp); } - Context->EffectSlotCount = 0; } diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index afea8dfb..ba79f03f 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -39,10 +39,10 @@ static ALint GetByteOffset(ALsource *Source); static ALint FramesFromBytes(ALint offset, ALenum format, ALint channels); DECL_VERIFIER(Filter, ALfilter, filter) -DECL_VERIFIER(EffectSlot, ALeffectslot, effectslot) #define LookupSource(m, k) ((ALsource*)LookupUIntMapKey(&(m), (k))) #define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k))) +#define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources) { @@ -718,7 +718,7 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum eParam, ALint lValue1, if((ALuint)lValue2 < device->NumAuxSends && (lValue1 == 0 || - (ALEffectSlot=VerifyEffectSlot(pContext->EffectSlotList, lValue1)) != NULL) && + (ALEffectSlot=LookupEffectSlot(pContext->EffectSlotMap, lValue1)) != NULL) && (lValue3 == 0 || (ALFilter=VerifyFilter(device->FilterList, lValue3)) != NULL)) { |