From 4edd7fe6476dc83fae162ab694984b17924968c3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 18 May 2010 17:41:06 -0700 Subject: [PATCH] Use a map for the effects list --- Alc/ALc.c | 7 +++- OpenAL32/Include/alEffect.h | 2 - OpenAL32/Include/alMain.h | 5 +-- OpenAL32/alAuxEffectSlot.c | 5 +-- OpenAL32/alEffect.c | 89 +++++++++++++++++++-------------------------- 5 files changed, 46 insertions(+), 62 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index cd791c38..3f9c6006 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1932,6 +1932,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->NumContexts = 0; InitUIntMap(&device->BufferMap); + InitUIntMap(&device->EffectMap); //Set output format device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE); @@ -2052,13 +2053,15 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) } ResetUIntMap(&pDevice->BufferMap); - if(pDevice->EffectCount > 0) + if(pDevice->EffectMap.size > 0) { #ifdef _DEBUG - AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectCount); + AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size); #endif ReleaseALEffects(pDevice); } + ResetUIntMap(&pDevice->EffectMap); + if(pDevice->FilterCount > 0) { #ifdef _DEBUG diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h index 6cbf0e5d..500b60a1 100644 --- a/OpenAL32/Include/alEffect.h +++ b/OpenAL32/Include/alEffect.h @@ -71,8 +71,6 @@ typedef struct ALeffect // Index to itself ALuint effect; - - struct ALeffect *next; } ALeffect; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index a0251042..9b1bcca9 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -358,9 +358,8 @@ struct ALCdevice_struct // Map of Buffers for this device UIntMap BufferMap; - // Linked List of Effects for this device - struct ALeffect *EffectList; - ALuint EffectCount; + // Map of Effects for this device + UIntMap EffectMap; // Linked List of Filters for this device struct ALfilter *FilterList; diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index b659c5f5..e8a76d35 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -34,9 +34,8 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); -DECL_VERIFIER(Effect, ALeffect, effect) - #define LookupEffectSlot(m, k) ((ALeffectslot*)LookupUIntMapKey(&(m), (k))) +#define LookupEffect(m, k) ((ALeffect*)LookupUIntMapKey(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { @@ -187,7 +186,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param ALeffect *effect = NULL; if(iValue == 0 || - (effect=VerifyEffect(Context->Device->EffectList, iValue)) != NULL) + (effect=LookupEffect(Context->Device->EffectMap, iValue)) != NULL) { InitializeEffect(Context, EffectSlot, effect); updateSources = AL_TRUE; diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index 3dbc8b3d..f3109ca2 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -36,7 +36,7 @@ ALboolean DisabledEffects[MAX_EFFECTS]; static void InitEffectParams(ALeffect *effect, ALenum type); -DECL_VERIFIER(Effect, ALeffect, effect) +#define LookupEffect(m, k) ((ALeffect*)LookupUIntMapKey(&(m), (k))) AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) { @@ -53,38 +53,34 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) // Check that enough memory has been allocted in the 'effects' array for n Effects if (!IsBadWritePtr((void*)effects, n * sizeof(ALuint))) { - ALeffect *end; - ALeffect **list = &device->EffectList; - while(*list) - list = &(*list)->next; + ALenum err; - end = *list; while(i < n) { - *list = calloc(1, sizeof(ALeffect)); - if(!(*list)) + ALeffect *effect = calloc(1, sizeof(ALeffect)); + if(!effect) { - while(end->next) - { - ALeffect *temp = end->next; - end->next = temp->next; - - ALTHUNK_REMOVEENTRY(temp->effect); - device->EffectCount--; - free(temp); - } alSetError(Context, AL_OUT_OF_MEMORY); + alDeleteEffects(i, effects); break; } - effects[i] = (ALuint)ALTHUNK_ADDENTRY(*list); - (*list)->effect = effects[i]; + effect->effect = ALTHUNK_ADDENTRY(effect); + err = InsertUIntMapEntry(&device->EffectMap, effect->effect, + effect); + if(err != AL_NO_ERROR) + { + ALTHUNK_REMOVEENTRY(effect->effect); + memset(effect, 0, sizeof(ALeffect)); + free(effect); - InitEffectParams(*list, AL_EFFECT_NULL); - device->EffectCount++; - i++; + alSetError(Context, err); + alDeleteEffects(i, effects); + break; + } - list = &(*list)->next; + effects[i++] = effect->effect; + InitEffectParams(effect, AL_EFFECT_NULL); } } } @@ -111,7 +107,7 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) if(!effects[i]) continue; - if(!VerifyEffect(device->EffectList, effects[i])) + if(!LookupEffect(device->EffectMap, effects[i])) { alSetError(Context, AL_INVALID_NAME); break; @@ -124,23 +120,13 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) for (i = 0; i < n; i++) { // Recheck that the effect is valid, because there could be duplicated names - if((ALEffect=VerifyEffect(device->EffectList, effects[i])) != NULL) + if((ALEffect=LookupEffect(device->EffectMap, effects[i])) != NULL) { - ALeffect **list; - - // Remove Effect from list of effects - list = &device->EffectList; - while(*list && *list != ALEffect) - list = &(*list)->next; - - if(*list) - *list = (*list)->next; + RemoveUIntMapKey(&device->EffectMap, ALEffect->effect); ALTHUNK_REMOVEENTRY(ALEffect->effect); memset(ALEffect, 0, sizeof(ALeffect)); free(ALEffect); - - device->EffectCount--; } } } @@ -154,14 +140,13 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects) AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect) { ALCcontext *Context; - ALboolean result = AL_TRUE; + ALboolean result; Context = GetContextSuspended(); if(!Context) return AL_FALSE; - if(effect) - result = (VerifyEffect(Context->Device->EffectList, effect) ? - AL_TRUE : AL_FALSE); + result = ((!effect || LookupEffect(Context->Device->EffectMap, effect)) ? + AL_TRUE : AL_FALSE); ProcessContext(Context); @@ -178,7 +163,7 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue) if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(param == AL_EFFECT_TYPE) { @@ -277,7 +262,7 @@ AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValue if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(param == AL_EFFECT_TYPE) { @@ -352,7 +337,7 @@ AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(ALEffect->type == AL_EFFECT_EAXREVERB) { @@ -715,7 +700,7 @@ AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflVa if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(ALEffect->type == AL_EFFECT_EAXREVERB) { @@ -844,7 +829,7 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piVal if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(param == AL_EFFECT_TYPE) { @@ -923,7 +908,7 @@ AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piVa if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(param == AL_EFFECT_TYPE) { @@ -998,7 +983,7 @@ AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pfl if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(ALEffect->type == AL_EFFECT_EAXREVERB) { @@ -1210,7 +1195,7 @@ AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pf if(!Context) return; Device = Context->Device; - if((ALEffect=VerifyEffect(Device->EffectList, effect)) != NULL) + if((ALEffect=LookupEffect(Device->EffectMap, effect)) != NULL) { if(ALEffect->type == AL_EFFECT_EAXREVERB) { @@ -1322,17 +1307,17 @@ AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pf ALvoid ReleaseALEffects(ALCdevice *device) { - while(device->EffectList) + ALsizei i; + for(i = 0;i < device->EffectMap.size;i++) { - ALeffect *temp = device->EffectList; - device->EffectList = temp->next; + ALeffect *temp = device->EffectMap.array[i].value; + device->EffectMap.array[i].value = NULL; // Release effect structure ALTHUNK_REMOVEENTRY(temp->effect); memset(temp, 0, sizeof(ALeffect)); free(temp); } - device->EffectCount = 0; } -- 2.11.4.GIT