Use a map for the effects list
This commit is contained in:
parent
ad5dfab428
commit
4edd7fe647
@ -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
|
||||
|
@ -71,8 +71,6 @@ typedef struct ALeffect
|
||||
|
||||
// Index to itself
|
||||
ALuint effect;
|
||||
|
||||
struct ALeffect *next;
|
||||
} ALeffect;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user