Remove al_try from alState.c

This commit is contained in:
Chris Robinson 2013-10-07 08:50:17 -07:00
parent 997f6228de
commit c080dcae8d

View File

@ -43,260 +43,239 @@ static const ALchar alErrOutOfMemory[] = "Out of Memory";
AL_API ALvoid AL_APIENTRY alEnable(ALenum capability) AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try
{
switch(capability) switch(capability)
{ {
case AL_SOURCE_DISTANCE_MODEL: case AL_SOURCE_DISTANCE_MODEL:
Context->SourceDistanceModel = AL_TRUE; context->SourceDistanceModel = AL_TRUE;
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alDisable(ALenum capability) AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try
{
switch(capability) switch(capability)
{ {
case AL_SOURCE_DISTANCE_MODEL: case AL_SOURCE_DISTANCE_MODEL:
Context->SourceDistanceModel = AL_FALSE; context->SourceDistanceModel = AL_FALSE;
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability) AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
{ {
ALCcontext *Context; ALCcontext *context;
ALboolean value=AL_FALSE; ALboolean value=AL_FALSE;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return AL_FALSE; if(!context) return AL_FALSE;
al_try
{
switch(capability) switch(capability)
{ {
case AL_SOURCE_DISTANCE_MODEL: case AL_SOURCE_DISTANCE_MODEL:
value = Context->SourceDistanceModel; value = context->SourceDistanceModel;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
{ {
ALCcontext *Context; ALCcontext *context;
ALboolean value=AL_FALSE; ALboolean value=AL_FALSE;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return AL_FALSE; if(!context) return AL_FALSE;
al_try
{
switch(pname) switch(pname)
{ {
case AL_DOPPLER_FACTOR: case AL_DOPPLER_FACTOR:
if(Context->DopplerFactor != 0.0f) if(context->DopplerFactor != 0.0f)
value = AL_TRUE; value = AL_TRUE;
break; break;
case AL_DOPPLER_VELOCITY: case AL_DOPPLER_VELOCITY:
if(Context->DopplerVelocity != 0.0f) if(context->DopplerVelocity != 0.0f)
value = AL_TRUE; value = AL_TRUE;
break; break;
case AL_DISTANCE_MODEL: case AL_DISTANCE_MODEL:
if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) if(context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
value = AL_TRUE; value = AL_TRUE;
break; break;
case AL_SPEED_OF_SOUND: case AL_SPEED_OF_SOUND:
if(Context->SpeedOfSound != 0.0f) if(context->SpeedOfSound != 0.0f)
value = AL_TRUE; value = AL_TRUE;
break; break;
case AL_DEFERRED_UPDATES_SOFT: case AL_DEFERRED_UPDATES_SOFT:
value = Context->DeferUpdates; value = context->DeferUpdates;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
{ {
ALCcontext *Context; ALCcontext *context;
ALdouble value = 0.0; ALdouble value = 0.0;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return 0.0; if(!context) return 0.0;
al_try
{
switch(pname) switch(pname)
{ {
case AL_DOPPLER_FACTOR: case AL_DOPPLER_FACTOR:
value = (ALdouble)Context->DopplerFactor; value = (ALdouble)context->DopplerFactor;
break; break;
case AL_DOPPLER_VELOCITY: case AL_DOPPLER_VELOCITY:
value = (ALdouble)Context->DopplerVelocity; value = (ALdouble)context->DopplerVelocity;
break; break;
case AL_DISTANCE_MODEL: case AL_DISTANCE_MODEL:
value = (ALdouble)Context->DistanceModel; value = (ALdouble)context->DistanceModel;
break; break;
case AL_SPEED_OF_SOUND: case AL_SPEED_OF_SOUND:
value = (ALdouble)Context->SpeedOfSound; value = (ALdouble)context->SpeedOfSound;
break; break;
case AL_DEFERRED_UPDATES_SOFT: case AL_DEFERRED_UPDATES_SOFT:
value = (ALdouble)Context->DeferUpdates; value = (ALdouble)context->DeferUpdates;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
{ {
ALCcontext *Context; ALCcontext *context;
ALfloat value = 0.0f; ALfloat value = 0.0f;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return 0.0f; if(!context) return 0.0f;
al_try
{
switch(pname) switch(pname)
{ {
case AL_DOPPLER_FACTOR: case AL_DOPPLER_FACTOR:
value = Context->DopplerFactor; value = context->DopplerFactor;
break; break;
case AL_DOPPLER_VELOCITY: case AL_DOPPLER_VELOCITY:
value = Context->DopplerVelocity; value = context->DopplerVelocity;
break; break;
case AL_DISTANCE_MODEL: case AL_DISTANCE_MODEL:
value = (ALfloat)Context->DistanceModel; value = (ALfloat)context->DistanceModel;
break; break;
case AL_SPEED_OF_SOUND: case AL_SPEED_OF_SOUND:
value = Context->SpeedOfSound; value = context->SpeedOfSound;
break; break;
case AL_DEFERRED_UPDATES_SOFT: case AL_DEFERRED_UPDATES_SOFT:
value = (ALfloat)Context->DeferUpdates; value = (ALfloat)context->DeferUpdates;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
{ {
ALCcontext *Context; ALCcontext *context;
ALint value = 0; ALint value = 0;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return 0; if(!context) return 0;
al_try
{
switch(pname) switch(pname)
{ {
case AL_DOPPLER_FACTOR: case AL_DOPPLER_FACTOR:
value = (ALint)Context->DopplerFactor; value = (ALint)context->DopplerFactor;
break; break;
case AL_DOPPLER_VELOCITY: case AL_DOPPLER_VELOCITY:
value = (ALint)Context->DopplerVelocity; value = (ALint)context->DopplerVelocity;
break; break;
case AL_DISTANCE_MODEL: case AL_DISTANCE_MODEL:
value = (ALint)Context->DistanceModel; value = (ALint)context->DistanceModel;
break; break;
case AL_SPEED_OF_SOUND: case AL_SPEED_OF_SOUND:
value = (ALint)Context->SpeedOfSound; value = (ALint)context->SpeedOfSound;
break; break;
case AL_DEFERRED_UPDATES_SOFT: case AL_DEFERRED_UPDATES_SOFT:
value = (ALint)Context->DeferUpdates; value = (ALint)context->DeferUpdates;
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values) AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
{ {
ALCcontext *Context; ALCcontext *context;
if(values) if(values)
{ {
@ -312,26 +291,24 @@ AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
} }
} }
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(values))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, values);
switch(pname) switch(pname)
{ {
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values) AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
{ {
ALCcontext *Context; ALCcontext *context;
if(values) if(values)
{ {
@ -347,26 +324,24 @@ AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
} }
} }
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(values))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, values);
switch(pname) switch(pname)
{ {
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values) AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
{ {
ALCcontext *Context; ALCcontext *context;
if(values) if(values)
{ {
@ -382,26 +357,24 @@ AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
} }
} }
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(values))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, values);
switch(pname) switch(pname)
{ {
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values) AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
{ {
ALCcontext *Context; ALCcontext *context;
if(values) if(values)
{ {
@ -417,33 +390,29 @@ AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
} }
} }
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(values))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, values);
switch(pname) switch(pname)
{ {
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname) AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
{ {
const ALchar *value = NULL; const ALchar *value = NULL;
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return NULL; if(!context) return NULL;
al_try
{
switch(pname) switch(pname)
{ {
case AL_VENDOR: case AL_VENDOR:
@ -459,7 +428,7 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
break; break;
case AL_EXTENSIONS: case AL_EXTENSIONS:
value = Context->ExtensionList; value = context->ExtensionList;
break; break;
case AL_NO_ERROR: case AL_NO_ERROR:
@ -487,108 +456,96 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
break; break;
default: default:
al_throwerr(Context, AL_INVALID_ENUM); SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
} }
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
return value; return value;
} }
AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value) AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(value >= 0.0f && isfinite(value)))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
Context->DopplerFactor = value; context->DopplerFactor = value;
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value) AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(value >= 0.0f && isfinite(value)))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
Context->DopplerVelocity = value; context->DopplerVelocity = value;
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value) AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(value > 0.0f && isfinite(value)))
{ SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
CHECK_VALUE(Context, value > 0.0f && isfinite(value));
Context->SpeedOfSound = value; context->SpeedOfSound = value;
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value) AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
al_try if(!(value == AL_INVERSE_DISTANCE || value == AL_INVERSE_DISTANCE_CLAMPED ||
{ value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED ||
CHECK_VALUE(Context, value == AL_NONE || value == AL_EXPONENT_DISTANCE || value == AL_EXPONENT_DISTANCE_CLAMPED ||
value == AL_INVERSE_DISTANCE || value == AL_NONE))
value == AL_INVERSE_DISTANCE_CLAMPED || SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
value == AL_LINEAR_DISTANCE ||
value == AL_LINEAR_DISTANCE_CLAMPED ||
value == AL_EXPONENT_DISTANCE ||
value == AL_EXPONENT_DISTANCE_CLAMPED);
Context->DistanceModel = value; context->DistanceModel = value;
if(!Context->SourceDistanceModel) if(!context->SourceDistanceModel)
Context->UpdateSources = AL_TRUE; context->UpdateSources = AL_TRUE;
}
al_endtry;
ALCcontext_DecRef(Context); done:
ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
if(!Context->DeferUpdates) if(!context->DeferUpdates)
{ {
ALboolean UpdateSources; ALboolean UpdateSources;
ALsource **src, **src_end; ALsource **src, **src_end;
@ -597,61 +554,61 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)
SetMixerFPUMode(&oldMode); SetMixerFPUMode(&oldMode);
LockContext(Context); LockContext(context);
Context->DeferUpdates = AL_TRUE; context->DeferUpdates = AL_TRUE;
/* Make sure all pending updates are performed */ /* Make sure all pending updates are performed */
UpdateSources = ExchangeInt(&Context->UpdateSources, AL_FALSE); UpdateSources = ExchangeInt(&context->UpdateSources, AL_FALSE);
src = Context->ActiveSources; src = context->ActiveSources;
src_end = src + Context->ActiveSourceCount; src_end = src + context->ActiveSourceCount;
while(src != src_end) while(src != src_end)
{ {
if((*src)->state != AL_PLAYING) if((*src)->state != AL_PLAYING)
{ {
Context->ActiveSourceCount--; context->ActiveSourceCount--;
*src = *(--src_end); *src = *(--src_end);
continue; continue;
} }
if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources) if(ExchangeInt(&(*src)->NeedsUpdate, AL_FALSE) || UpdateSources)
ALsource_Update(*src, Context); ALsource_Update(*src, context);
src++; src++;
} }
slot = Context->ActiveEffectSlots; slot = context->ActiveEffectSlots;
slot_end = slot + Context->ActiveEffectSlotCount; slot_end = slot + context->ActiveEffectSlotCount;
while(slot != slot_end) while(slot != slot_end)
{ {
if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE)) if(ExchangeInt(&(*slot)->NeedsUpdate, AL_FALSE))
VCALL((*slot)->EffectState,update,(Context->Device, *slot)); VCALL((*slot)->EffectState,update,(context->Device, *slot));
slot++; slot++;
} }
UnlockContext(Context); UnlockContext(context);
RestoreFPUMode(&oldMode); RestoreFPUMode(&oldMode);
} }
ALCcontext_DecRef(Context); ALCcontext_DecRef(context);
} }
AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
{ {
ALCcontext *Context; ALCcontext *context;
Context = GetContextRef(); context = GetContextRef();
if(!Context) return; if(!context) return;
if(ExchangeInt(&Context->DeferUpdates, AL_FALSE)) if(ExchangeInt(&context->DeferUpdates, AL_FALSE))
{ {
ALsizei pos; ALsizei pos;
LockContext(Context); LockContext(context);
LockUIntMapRead(&Context->SourceMap); LockUIntMapRead(&context->SourceMap);
for(pos = 0;pos < Context->SourceMap.size;pos++) for(pos = 0;pos < context->SourceMap.size;pos++)
{ {
ALsource *Source = Context->SourceMap.array[pos].value; ALsource *Source = context->SourceMap.array[pos].value;
ALenum new_state; ALenum new_state;
if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) && if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
@ -660,11 +617,11 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
new_state = ExchangeInt(&Source->new_state, AL_NONE); new_state = ExchangeInt(&Source->new_state, AL_NONE);
if(new_state) if(new_state)
SetSourceState(Source, Context, new_state); SetSourceState(Source, context, new_state);
} }
UnlockUIntMapRead(&Context->SourceMap); UnlockUIntMapRead(&context->SourceMap);
UnlockContext(Context); UnlockContext(context);
} }
ALCcontext_DecRef(Context); ALCcontext_DecRef(context);
} }