diff options
author | Chris Robinson <[email protected]> | 2017-09-27 08:55:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-09-27 08:55:42 -0700 |
commit | 101d284a1801532e12b7867aed3499896d7a9a6f (patch) | |
tree | c9ae9c08e48b5c0a0dd579b43de40887a8e22a8d /Alc/ALu.c | |
parent | 2f6613905399aa06a253a421352e6fff57a1dce1 (diff) |
Update the context state properties separately
The context state properties are less likely to change compared to the listener
state, and future changes may prefer more infrequent updates to the context
state.
Note that this puts the MetersPerUnit in as a context state, even though it's
handled through the listener functions. Considering the infrequency that it's
updated at (generally set just once for the context's lifetime), it makes more
sense to put it there than with the more frequently updated listener
properties. The aforementioned future changes would also prefer MetersPerUnit
to not be updated unnecessarily.
Diffstat (limited to 'Alc/ALu.c')
-rw-r--r-- | Alc/ALu.c | 52 |
1 files changed, 32 insertions, 20 deletions
@@ -271,7 +271,30 @@ ALboolean BsincPrepare(const ALuint increment, BsincState *state, const BSincTab } -static ALboolean CalcListenerParams(ALCcontext *Context) +static bool CalcContextParams(ALCcontext *Context) +{ + ALlistener *Listener = Context->Listener; + struct ALcontextProps *props; + + props = ATOMIC_EXCHANGE_PTR(&Context->Update, NULL, almemory_order_acq_rel); + if(!props) return false; + + Listener->Params.MetersPerUnit = props->MetersPerUnit; + + Listener->Params.DopplerFactor = props->DopplerFactor; + Listener->Params.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity; + if(!OverrideReverbSpeedOfSound) + Listener->Params.ReverbSpeedOfSound = Listener->Params.SpeedOfSound * + Listener->Params.MetersPerUnit; + + Listener->Params.SourceDistanceModel = props->SourceDistanceModel; + Listener->Params.DistanceModel = props->DistanceModel; + + ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &Context->FreeList, props); + return true; +} + +static bool CalcListenerParams(ALCcontext *Context) { ALlistener *Listener = Context->Listener; ALfloat N[3], V[3], U[3], P[3]; @@ -279,7 +302,7 @@ static ALboolean CalcListenerParams(ALCcontext *Context) aluVector vel; props = ATOMIC_EXCHANGE_PTR(&Listener->Update, NULL, almemory_order_acq_rel); - if(!props) return AL_FALSE; + if(!props) return false; /* AT then UP */ N[0] = props->Forward[0]; @@ -311,30 +334,18 @@ static ALboolean CalcListenerParams(ALCcontext *Context) Listener->Params.Velocity = aluMatrixfVector(&Listener->Params.Matrix, &vel); Listener->Params.Gain = props->Gain * Context->GainBoost; - Listener->Params.MetersPerUnit = props->MetersPerUnit; - - Listener->Params.DopplerFactor = props->DopplerFactor; - Listener->Params.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity; - if(OverrideReverbSpeedOfSound) - Listener->Params.ReverbSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; - else - Listener->Params.ReverbSpeedOfSound = Listener->Params.SpeedOfSound * - Listener->Params.MetersPerUnit; - - Listener->Params.SourceDistanceModel = props->SourceDistanceModel; - Listener->Params.DistanceModel = props->DistanceModel; ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &Listener->FreeList, props); - return AL_TRUE; + return true; } -static ALboolean CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context) +static bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context) { struct ALeffectslotProps *props; ALeffectState *state; props = ATOMIC_EXCHANGE_PTR(&slot->Update, NULL, almemory_order_acq_rel); - if(!props) return AL_FALSE; + if(!props) return false; slot->Params.Gain = props->Gain; slot->Params.AuxSendAuto = props->AuxSendAuto; @@ -366,7 +377,7 @@ static ALboolean CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context) V(state,update)(context, slot, &props->Props); ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &slot->FreeList, props); - return AL_TRUE; + return true; } @@ -1430,7 +1441,7 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, Device); } -static void CalcSourceParams(ALvoice *voice, ALCcontext *context, ALboolean force) +static void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) { ALbufferlistitem *BufferListItem; struct ALvoiceProps *props; @@ -1475,7 +1486,8 @@ static void UpdateContextSources(ALCcontext *ctx, const struct ALeffectslotArray IncrementRef(&ctx->UpdateCount); if(!ATOMIC_LOAD(&ctx->HoldUpdates, almemory_order_acquire)) { - ALboolean force = CalcListenerParams(ctx); + ALboolean cforce = CalcContextParams(ctx); + ALboolean force = CalcListenerParams(ctx) | cforce; for(i = 0;i < slots->count;i++) force |= CalcEffectSlotParams(slots->slot[i], ctx); |