Reduce some more indentation

This commit is contained in:
Chris Robinson 2010-09-21 16:54:33 -07:00
parent 8a1d5a21c3
commit 97daaade8a
6 changed files with 194 additions and 189 deletions

View File

@ -104,52 +104,53 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect
{
ALCcontext *Context;
ALeffectslot *EffectSlot;
ALboolean SlotsValid = AL_FALSE;
ALsizei i;
Context = GetContextSuspended();
if(!Context) return;
if (n >= 0)
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
SlotsValid = AL_TRUE;
// Check that all effectslots are valid
for (i = 0; i < n; i++)
for(i = 0;i < n;i++)
{
if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL)
{
alSetError(Context, AL_INVALID_NAME);
SlotsValid = AL_FALSE;
break;
}
else
else if(EffectSlot->refcount > 0)
{
if(EffectSlot->refcount > 0)
{
alSetError(Context, AL_INVALID_NAME);
break;
}
}
}
if (i == n)
{
// All effectslots are valid
for (i = 0; i < n; i++)
{
// Recheck that the effectslot is valid, because there could be duplicated names
if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) != NULL)
{
ALEffect_Destroy(EffectSlot->EffectState);
RemoveUIntMapKey(&Context->EffectSlotMap, EffectSlot->effectslot);
ALTHUNK_REMOVEENTRY(EffectSlot->effectslot);
memset(EffectSlot, 0, sizeof(ALeffectslot));
free(EffectSlot);
}
alSetError(Context, AL_INVALID_NAME);
SlotsValid = AL_FALSE;
break;
}
}
}
else
alSetError(Context, AL_INVALID_VALUE);
if(SlotsValid)
{
// All effectslots are valid
for(i = 0;i < n;i++)
{
// Recheck that the effectslot is valid, because there could be duplicated names
if((EffectSlot=LookupEffectSlot(Context->EffectSlotMap, effectslots[i])) == NULL)
continue;
ALEffect_Destroy(EffectSlot->EffectState);
RemoveUIntMapKey(&Context->EffectSlotMap, EffectSlot->effectslot);
ALTHUNK_REMOVEENTRY(EffectSlot->effectslot);
memset(EffectSlot, 0, sizeof(ALeffectslot));
free(EffectSlot);
}
}
ProcessContext(Context);
}

View File

@ -157,67 +157,67 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
*
* Deletes the n AL Buffers pointed to by puiBuffers
*/
AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
{
ALCcontext *Context;
ALCdevice *device;
ALboolean Failed;
ALbuffer *ALBuf;
ALsizei i;
Context = GetContextSuspended();
if(!Context) return;
// Check we are actually Deleting some Buffers
Failed = AL_TRUE;
device = Context->Device;
/* Check we are actually Deleting some Buffers */
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
ALCdevice *device = Context->Device;
ALboolean bFailed = AL_FALSE;
Failed = AL_FALSE;
// Check that all the buffers are valid and can actually be deleted
/* Check that all the buffers are valid and can actually be deleted */
for(i = 0;i < n;i++)
{
if(!puiBuffers[i])
if(!buffers[i])
continue;
// Check for valid Buffer ID (can be NULL buffer)
if((ALBuf=LookupBuffer(device->BufferMap, puiBuffers[i])) != NULL)
{
if(ALBuf->refcount != 0)
{
// Buffer still in use, cannot be deleted
alSetError(Context, AL_INVALID_OPERATION);
bFailed = AL_TRUE;
break;
}
}
else
/* Check for valid Buffer ID (can be NULL buffer) */
if((ALBuf=LookupBuffer(device->BufferMap, buffers[i])) == NULL)
{
// Invalid Buffer
alSetError(Context, AL_INVALID_NAME);
bFailed = AL_TRUE;
Failed = AL_TRUE;
break;
}
else if(ALBuf->refcount != 0)
{
/* Buffer still in use, cannot be deleted */
alSetError(Context, AL_INVALID_OPERATION);
Failed = AL_TRUE;
break;
}
}
}
// If all the Buffers were valid (and have Reference Counts of 0), then we can delete them
if(!bFailed)
/* If all the Buffers were valid (and have Reference Counts of 0), then we can delete them */
if(!Failed)
{
for(i = 0;i < n;i++)
{
for(i = 0;i < n;i++)
{
if((ALBuf=LookupBuffer(device->BufferMap, puiBuffers[i])) != NULL)
{
// Release the memory used to store audio data
free(ALBuf->data);
if((ALBuf=LookupBuffer(device->BufferMap, buffers[i])) == NULL)
continue;
// Release buffer structure
RemoveUIntMapKey(&device->BufferMap, ALBuf->buffer);
ALTHUNK_REMOVEENTRY(ALBuf->buffer);
/* Release the memory used to store audio data */
free(ALBuf->data);
memset(ALBuf, 0, sizeof(ALbuffer));
free(ALBuf);
}
}
/* Release buffer structure */
RemoveUIntMapKey(&device->BufferMap, ALBuf->buffer);
ALTHUNK_REMOVEENTRY(ALBuf->buffer);
memset(ALBuf, 0, sizeof(ALbuffer));
free(ALBuf);
}
}

View File

@ -93,76 +93,74 @@ AL_API ALvoid AL_APIENTRY alGenDatabuffersEXT(ALsizei n,ALuint *puiBuffers)
*
* Deletes the n AL Databuffers pointed to by puiBuffers
*/
AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *puiBuffers)
AL_API ALvoid AL_APIENTRY alDeleteDatabuffersEXT(ALsizei n, const ALuint *buffers)
{
ALCcontext *Context;
ALCdevice *device;
ALdatabuffer *ALBuf;
ALboolean Failed;
ALsizei i;
ALboolean bFailed = AL_FALSE;
Context = GetContextSuspended();
if(!Context) return;
/* Check we are actually Deleting some Databuffers */
if(n >= 0)
Failed = AL_TRUE;
device = Context->Device;
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
ALCdevice *device = Context->Device;
Failed = AL_FALSE;
/* Check that all the databuffers are valid and can actually be
* deleted */
for(i = 0;i < n;i++)
{
if(!puiBuffers[i])
if(!buffers[i])
continue;
/* Check for valid Buffer ID */
if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL)
{
if(ALBuf->state != UNMAPPED)
{
/* Databuffer still in use, cannot be deleted */
alSetError(Context, AL_INVALID_OPERATION);
bFailed = AL_TRUE;
break;
}
}
else
if((ALBuf=LookupDatabuffer(device->DatabufferMap, buffers[i])) == NULL)
{
/* Invalid Databuffer */
alSetError(Context, AL_INVALID_NAME);
bFailed = AL_TRUE;
Failed = AL_TRUE;
break;
}
else if(ALBuf->state != UNMAPPED)
{
/* Databuffer still in use, cannot be deleted */
alSetError(Context, AL_INVALID_OPERATION);
Failed = AL_TRUE;
break;
}
}
}
/* If all the Databuffers were valid (and unmapped), then we can
* delete them */
if(!bFailed)
/* If all the Databuffers were valid (and unmapped), then we can delete them */
if(!Failed)
{
for(i = 0;i < n;i++)
{
for(i = 0;i < n;i++)
{
if((ALBuf=LookupDatabuffer(device->DatabufferMap, puiBuffers[i])) != NULL)
{
if(ALBuf == Context->SampleSource)
Context->SampleSource = NULL;
if(ALBuf == Context->SampleSink)
Context->SampleSink = NULL;
if((ALBuf=LookupDatabuffer(device->DatabufferMap, buffers[i])) == NULL)
continue;
// Release the memory used to store audio data
free(ALBuf->data);
if(ALBuf == Context->SampleSource)
Context->SampleSource = NULL;
if(ALBuf == Context->SampleSink)
Context->SampleSink = NULL;
// Release buffer structure
RemoveUIntMapKey(&device->DatabufferMap, ALBuf->databuffer);
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
// Release the memory used to store audio data
free(ALBuf->data);
memset(ALBuf, 0, sizeof(ALdatabuffer));
free(ALBuf);
}
}
// Release buffer structure
RemoveUIntMapKey(&device->DatabufferMap, ALBuf->databuffer);
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
memset(ALBuf, 0, sizeof(ALdatabuffer));
free(ALBuf);
}
}
else
alSetError(Context, AL_INVALID_VALUE);
ProcessContext(Context);
}

View File

@ -87,48 +87,52 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
{
ALCcontext *Context;
ALCdevice *device;
ALeffect *ALEffect;
ALboolean Failed;
ALsizei i;
Context = GetContextSuspended();
if(!Context) return;
if (n >= 0)
Failed = AL_TRUE;
device = Context->Device;
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
ALCdevice *device = Context->Device;
Failed = AL_FALSE;
// Check that all effects are valid
for (i = 0; i < n; i++)
for(i = 0;i < n;i++)
{
if(!effects[i])
continue;
if(!LookupEffect(device->EffectMap, effects[i]))
if(LookupEffect(device->EffectMap, effects[i]) == NULL)
{
alSetError(Context, AL_INVALID_NAME);
Failed = AL_TRUE;
break;
}
}
}
if (i == n)
if(!Failed)
{
// All effects are valid
for(i = 0;i < n;i++)
{
// All effects are valid
for (i = 0; i < n; i++)
{
// Recheck that the effect is valid, because there could be duplicated names
if((ALEffect=LookupEffect(device->EffectMap, effects[i])) != NULL)
{
RemoveUIntMapKey(&device->EffectMap, ALEffect->effect);
ALTHUNK_REMOVEENTRY(ALEffect->effect);
// Recheck that the effect is valid, because there could be duplicated names
if((ALEffect=LookupEffect(device->EffectMap, effects[i])) == NULL)
continue;
memset(ALEffect, 0, sizeof(ALeffect));
free(ALEffect);
}
}
RemoveUIntMapKey(&device->EffectMap, ALEffect->effect);
ALTHUNK_REMOVEENTRY(ALEffect->effect);
memset(ALEffect, 0, sizeof(ALeffect));
free(ALEffect);
}
}
else
alSetError(Context, AL_INVALID_VALUE);
ProcessContext(Context);
}

View File

@ -83,48 +83,52 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
{
ALCcontext *Context;
ALCdevice *device;
ALfilter *ALFilter;
ALboolean Failed;
ALsizei i;
Context = GetContextSuspended();
if(!Context) return;
if (n >= 0)
Failed = AL_TRUE;
device = Context->Device;
if(n < 0)
alSetError(Context, AL_INVALID_VALUE);
else
{
ALCdevice *device = Context->Device;
Failed = AL_FALSE;
// Check that all filters are valid
for (i = 0; i < n; i++)
for(i = 0;i < n;i++)
{
if(!filters[i])
continue;
if(!LookupFilter(device->FilterMap, filters[i]))
if(LookupFilter(device->FilterMap, filters[i]) == NULL)
{
alSetError(Context, AL_INVALID_NAME);
Failed = AL_TRUE;
break;
}
}
}
if (i == n)
if(!Failed)
{
// All filters are valid
for(i = 0;i < n;i++)
{
// All filters are valid
for (i = 0; i < n; i++)
{
// Recheck that the filter is valid, because there could be duplicated names
if((ALFilter=LookupFilter(device->FilterMap, filters[i])) != NULL)
{
RemoveUIntMapKey(&device->FilterMap, ALFilter->filter);
ALTHUNK_REMOVEENTRY(ALFilter->filter);
// Recheck that the filter is valid, because there could be duplicated names
if((ALFilter=LookupFilter(device->FilterMap, filters[i])) == NULL)
continue;
memset(ALFilter, 0, sizeof(ALfilter));
free(ALFilter);
}
}
RemoveUIntMapKey(&device->FilterMap, ALFilter->filter);
ALTHUNK_REMOVEENTRY(ALFilter->filter);
memset(ALFilter, 0, sizeof(ALfilter));
free(ALFilter);
}
}
else
alSetError(Context, AL_INVALID_VALUE);
ProcessContext(Context);
}

View File

@ -99,11 +99,10 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n,ALuint *sources)
AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
{
ALCcontext *Context;
ALCdevice *Device;
ALsource *Source;
ALsizei i, j;
ALbufferlistitem *BufferList;
ALboolean bSourcesValid = AL_TRUE;
ALboolean SourcesValid = AL_FALSE;
Context = GetContextSuspended();
if(!Context) return;
@ -112,65 +111,64 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
alSetError(Context, AL_INVALID_VALUE);
else
{
Device = Context->Device;
SourcesValid = AL_TRUE;
// Check that all Sources are valid (and can therefore be deleted)
for(i = 0;i < n;i++)
{
if(LookupSource(Context->SourceMap, sources[i]) == NULL)
{
alSetError(Context, AL_INVALID_NAME);
bSourcesValid = AL_FALSE;
SourcesValid = AL_FALSE;
break;
}
}
}
if(bSourcesValid)
if(SourcesValid)
{
// All Sources are valid, and can be deleted
for(i = 0;i < n;i++)
{
// All Sources are valid, and can be deleted
for(i = 0;i < n;i++)
// Recheck that the Source is valid, because there could be duplicated Source names
if((Source=LookupSource(Context->SourceMap, sources[i])) == NULL)
continue;
for(j = 0;j < Context->ActiveSourceCount;j++)
{
// Recheck that the Source is valid, because there could be duplicated Source names
if((Source=LookupSource(Context->SourceMap, sources[i])) != NULL)
if(Context->ActiveSources[j] == Source)
{
for(j = 0;j < Context->ActiveSourceCount;j++)
{
if(Context->ActiveSources[j] == Source)
{
ALsizei end = --(Context->ActiveSourceCount);
Context->ActiveSources[j] = Context->ActiveSources[end];
break;
}
}
// For each buffer in the source's queue, decrement its reference counter and remove it
while(Source->queue != NULL)
{
BufferList = Source->queue;
// Decrement buffer's reference counter
if(BufferList->buffer != NULL)
BufferList->buffer->refcount--;
// Update queue to point to next element in list
Source->queue = BufferList->next;
// Release memory allocated for buffer list item
free(BufferList);
}
for(j = 0;j < MAX_SENDS;++j)
{
if(Source->Send[j].Slot)
Source->Send[j].Slot->refcount--;
Source->Send[j].Slot = NULL;
}
// Remove Source from list of Sources
RemoveUIntMapKey(&Context->SourceMap, Source->source);
ALTHUNK_REMOVEENTRY(Source->source);
memset(Source,0,sizeof(ALsource));
free(Source);
ALsizei end = --(Context->ActiveSourceCount);
Context->ActiveSources[j] = Context->ActiveSources[end];
break;
}
}
// For each buffer in the source's queue...
while(Source->queue != NULL)
{
BufferList = Source->queue;
// Decrement buffer's reference counter
if(BufferList->buffer != NULL)
BufferList->buffer->refcount--;
// Update queue to point to next element in list
Source->queue = BufferList->next;
// Release memory allocated for buffer list item
free(BufferList);
}
for(j = 0;j < MAX_SENDS;++j)
{
if(Source->Send[j].Slot)
Source->Send[j].Slot->refcount--;
Source->Send[j].Slot = NULL;
}
// Remove Source from list of Sources
RemoveUIntMapKey(&Context->SourceMap, Source->source);
ALTHUNK_REMOVEENTRY(Source->source);
memset(Source,0,sizeof(ALsource));
free(Source);
}
}