diff options
-rw-r--r-- | al/listener.cpp | 62 | ||||
-rw-r--r-- | al/listener.h | 6 | ||||
-rw-r--r-- | al/state.cpp | 8 | ||||
-rw-r--r-- | alc/alc.cpp | 3 | ||||
-rw-r--r-- | alc/alu.cpp | 25 | ||||
-rw-r--r-- | alc/context.cpp | 6 | ||||
-rw-r--r-- | core/context.cpp | 16 | ||||
-rw-r--r-- | core/context.h | 22 |
8 files changed, 36 insertions, 112 deletions
diff --git a/al/listener.cpp b/al/listener.cpp index 11b7162a..a260c93c 100644 --- a/al/listener.cpp +++ b/al/listener.cpp @@ -38,16 +38,16 @@ namespace { -inline void UpdateProps(ALlistener &listener, ALCcontext *context) +inline void UpdateProps(ALCcontext *context) { if(!context->mDeferUpdates.load(std::memory_order_acquire)) - UpdateListenerProps(context); + UpdateContextProps(context); else - listener.mPropsDirty.set(std::memory_order_release); + context->mPropsDirty.set(std::memory_order_release); } #ifdef ALSOFT_EAX -inline void CommitAndUpdateProps(ALlistener &listener, ALCcontext *context) +inline void CommitAndUpdateProps(ALCcontext *context) { if(!context->mDeferUpdates.load(std::memory_order_acquire)) { @@ -60,17 +60,17 @@ inline void CommitAndUpdateProps(ALlistener &listener, ALCcontext *context) context->eax_commit_and_update_sources(); } - UpdateListenerProps(context); + UpdateContextProps(context); context->mHoldUpdates.store(false, std::memory_order_release); } else - listener.mPropsDirty.set(std::memory_order_release); + context->mPropsDirty.set(std::memory_order_release); } #else -inline void CommitAndUpdateProps(ALlistener &listener, ALCcontext *context) -{ UpdateProps(listener, context); } +inline void CommitAndUpdateProps(ALCcontext *context) +{ UpdateProps(context); } #endif } // namespace @@ -89,14 +89,14 @@ START_API_FUNC if(!(value >= 0.0f && std::isfinite(value))) SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener gain out of range"); listener.Gain = value; - UpdateProps(listener, context.get()); + UpdateProps(context.get()); break; case AL_METERS_PER_UNIT: if(!(value >= AL_MIN_METERS_PER_UNIT && value <= AL_MAX_METERS_PER_UNIT)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener meters per unit out of range"); listener.mMetersPerUnit = value; - UpdateProps(listener, context.get()); + UpdateProps(context.get()); break; default: @@ -121,7 +121,7 @@ START_API_FUNC listener.Position[0] = value1; listener.Position[1] = value2; listener.Position[2] = value3; - CommitAndUpdateProps(listener, context.get()); + CommitAndUpdateProps(context.get()); break; case AL_VELOCITY: @@ -130,7 +130,7 @@ START_API_FUNC listener.Velocity[0] = value1; listener.Velocity[1] = value2; listener.Velocity[2] = value3; - CommitAndUpdateProps(listener, context.get()); + CommitAndUpdateProps(context.get()); break; default: @@ -177,7 +177,7 @@ START_API_FUNC listener.OrientUp[0] = values[3]; listener.OrientUp[1] = values[4]; listener.OrientUp[2] = values[5]; - CommitAndUpdateProps(listener, context.get()); + CommitAndUpdateProps(context.get()); break; default: @@ -445,39 +445,3 @@ START_API_FUNC } } END_API_FUNC - - -void UpdateListenerProps(ALCcontext *context) -{ - /* Get an unused proprty container, or allocate a new one as needed. */ - ListenerProps *props{context->mFreeListenerProps.load(std::memory_order_acquire)}; - if(!props) - props = new ListenerProps{}; - else - { - ListenerProps *next; - do { - next = props->next.load(std::memory_order_relaxed); - } while(context->mFreeListenerProps.compare_exchange_weak(props, next, - std::memory_order_seq_cst, std::memory_order_acquire) == 0); - } - - /* Copy in current property values. */ - ALlistener &listener = context->mListener; - props->Position = listener.Position; - props->Velocity = listener.Velocity; - props->OrientAt = listener.OrientAt; - props->OrientUp = listener.OrientUp; - props->Gain = listener.Gain; - props->MetersPerUnit = listener.mMetersPerUnit; - - /* Set the new container for updating internal parameters. */ - props = context->mParams.ListenerUpdate.exchange(props, std::memory_order_acq_rel); - if(props) - { - /* If there was an unused update container, put it back in the - * freelist. - */ - AtomicReplaceHead(context->mFreeListenerProps, props); - } -} diff --git a/al/listener.h b/al/listener.h index f3332763..f9df4116 100644 --- a/al/listener.h +++ b/al/listener.h @@ -20,13 +20,7 @@ struct ALlistener { float Gain{1.0f}; float mMetersPerUnit{AL_DEFAULT_METERS_PER_UNIT}; - al::atomic_invflag mPropsDirty; - - ALlistener() { mPropsDirty.test_and_clear(std::memory_order_relaxed); } - DISABLE_ALLOC() }; -void UpdateListenerProps(ALCcontext *context); - #endif diff --git a/al/state.cpp b/al/state.cpp index 6da55d6f..7d69e962 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -935,6 +935,14 @@ void UpdateContextProps(ALCcontext *context) } /* Copy in current property values. */ + ALlistener &listener = context->mListener; + props->Position = listener.Position; + props->Velocity = listener.Velocity; + props->OrientAt = listener.OrientAt; + props->OrientUp = listener.OrientUp; + props->Gain = listener.Gain; + props->MetersPerUnit = listener.mMetersPerUnit; + props->DopplerFactor = context->mDopplerFactor; props->DopplerVelocity = context->mDopplerVelocity; props->SpeedOfSound = context->mSpeedOfSound; diff --git a/alc/alc.cpp b/alc/alc.cpp index 1659593f..d6bd005f 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2149,8 +2149,6 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) context->mPropsDirty.test_and_clear(std::memory_order_release); UpdateContextProps(context); - context->mListener.mPropsDirty.test_and_clear(std::memory_order_release); - UpdateListenerProps(context); UpdateAllSourceProps(context); } mixer_mode.leave(); @@ -3025,7 +3023,6 @@ START_API_FUNC TRACE("volume-adjust gain: %f\n", context->mGainBoost); } } - UpdateListenerProps(context.get()); { using ContextArray = al::FlexArray<ContextBase*>; diff --git a/alc/alu.cpp b/alc/alu.cpp index 62fc23dd..b8fd85ea 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -375,22 +375,6 @@ bool CalcContextParams(ContextBase *ctx) ContextProps *props{ctx->mParams.ContextUpdate.exchange(nullptr, std::memory_order_acq_rel)}; if(!props) return false; - ctx->mParams.DopplerFactor = props->DopplerFactor; - ctx->mParams.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity; - - ctx->mParams.SourceDistanceModel = props->SourceDistanceModel; - ctx->mParams.mDistanceModel = props->mDistanceModel; - - AtomicReplaceHead(ctx->mFreeContextProps, props); - return true; -} - -bool CalcListenerParams(ContextBase *ctx) -{ - ListenerProps *props{ctx->mParams.ListenerUpdate.exchange(nullptr, - std::memory_order_acq_rel)}; - if(!props) return false; - const alu::Vector pos{props->Position[0], props->Position[1], props->Position[2], 1.0f}; ctx->mParams.Position = pos; @@ -416,7 +400,13 @@ bool CalcListenerParams(ContextBase *ctx) ctx->mParams.Gain = props->Gain * ctx->mGainBoost; ctx->mParams.MetersPerUnit = props->MetersPerUnit; - AtomicReplaceHead(ctx->mFreeListenerProps, props); + ctx->mParams.DopplerFactor = props->DopplerFactor; + ctx->mParams.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity; + + ctx->mParams.SourceDistanceModel = props->SourceDistanceModel; + ctx->mParams.mDistanceModel = props->mDistanceModel; + + AtomicReplaceHead(ctx->mFreeContextProps, props); return true; } @@ -1691,7 +1681,6 @@ void ProcessParamUpdates(ContextBase *ctx, const EffectSlotArray &slots, if LIKELY(!ctx->mHoldUpdates.load(std::memory_order_acquire)) { bool force{CalcContextParams(ctx)}; - force |= CalcListenerParams(ctx); auto sorted_slots = const_cast<EffectSlot**>(slots.data() + slots.size()); for(EffectSlot *slot : slots) force |= CalcEffectSlotParams(slot, sorted_slots, ctx); diff --git a/alc/context.cpp b/alc/context.cpp index 525d4a5f..f24282f8 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -259,8 +259,6 @@ void ALCcontext::applyAllUpdates() if(mPropsDirty.test_and_clear(std::memory_order_acq_rel)) UpdateContextProps(this); - if(mListener.mPropsDirty.test_and_clear(std::memory_order_acq_rel)) - UpdateListenerProps(this); UpdateAllEffectSlotProps(this); UpdateAllSourceProps(this); @@ -948,7 +946,7 @@ void ALCcontext::eax_set_primary_fx_slot_id() void ALCcontext::eax_set_distance_factor() { mListener.mMetersPerUnit = eax_.context.flDistanceFactor; - mListener.mPropsDirty.set(std::memory_order_release); + mPropsDirty.set(std::memory_order_release); } void ALCcontext::eax_set_air_absorbtion_hf() @@ -1333,8 +1331,6 @@ void ALCcontext::eax_set( if(mPropsDirty.test_and_clear(std::memory_order_acq_rel)) UpdateContextProps(this); - if(mListener.mPropsDirty.test_and_clear(std::memory_order_acq_rel)) - UpdateListenerProps(this); UpdateAllSourceProps(this); mHoldUpdates.store(false, std::memory_order_release); diff --git a/core/context.cpp b/core/context.cpp index 6457a6ec..39fd8522 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -52,22 +52,6 @@ ContextBase::~ContextBase() delete mVoices.exchange(nullptr, std::memory_order_relaxed); - count = 0; - ListenerProps *lprops{mParams.ListenerUpdate.exchange(nullptr, std::memory_order_relaxed)}; - if(lprops) - { - ++count; - delete lprops; - } - lprops = mFreeListenerProps.exchange(nullptr, std::memory_order_acquire); - while(lprops) - { - std::unique_ptr<ListenerProps> old{lprops}; - lprops = old->next.load(std::memory_order_relaxed); - ++count; - } - TRACE("Freed %zu listener property object%s\n", count, (count==1)?"":"s"); - if(mAsyncEvents) { count = 0; diff --git a/core/context.h b/core/context.h index f3e05689..5f1f2ae1 100644 --- a/core/context.h +++ b/core/context.h @@ -50,6 +50,13 @@ using WetBufferPtr = std::unique_ptr<WetBuffer>; struct ContextProps { + std::array<float,3> Position; + std::array<float,3> Velocity; + std::array<float,3> OrientAt; + std::array<float,3> OrientUp; + float Gain; + float MetersPerUnit; + float DopplerFactor; float DopplerVelocity; float SpeedOfSound; @@ -61,23 +68,9 @@ struct ContextProps { DEF_NEWDEL(ContextProps) }; -struct ListenerProps { - std::array<float,3> Position; - std::array<float,3> Velocity; - std::array<float,3> OrientAt; - std::array<float,3> OrientUp; - float Gain; - float MetersPerUnit; - - std::atomic<ListenerProps*> next; - - DEF_NEWDEL(ListenerProps) -}; - struct ContextParams { /* Pointer to the most recent property values that are awaiting an update. */ std::atomic<ContextProps*> ContextUpdate{nullptr}; - std::atomic<ListenerProps*> ListenerUpdate{nullptr}; alu::Vector Position{}; alu::Matrix Matrix{alu::Matrix::Identity()}; @@ -109,7 +102,6 @@ struct ContextBase { * updates. */ std::atomic<ContextProps*> mFreeContextProps{nullptr}; - std::atomic<ListenerProps*> mFreeListenerProps{nullptr}; std::atomic<VoicePropsItem*> mFreeVoiceProps{nullptr}; std::atomic<EffectSlotProps*> mFreeEffectslotProps{nullptr}; |