diff options
-rw-r--r-- | Alc/alc.cpp | 111 | ||||
-rw-r--r-- | Alc/alcontext.h | 70 | ||||
-rw-r--r-- | OpenAL32/Include/alListener.h | 14 |
3 files changed, 90 insertions, 105 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index bf665cfe..2ab2df8e 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2670,64 +2670,55 @@ static ALvoid InitContext(ALCcontext *Context) } -/* FreeContext +/* ALCcontext_struct::~ALCcontext_struct() * * Cleans up the context, and destroys any remaining objects the app failed to * delete. Called once there's no more references on the context. */ -static void FreeContext(ALCcontext *context) +ALCcontext_struct::~ALCcontext_struct() { - ALlistener &listener = context->Listener; - struct ALeffectslotProps *eprops; - struct ALlistenerProps *lprops; - struct ALcontextProps *cprops; - struct ALvoiceProps *vprops; - size_t count; - ALsizei i; - - TRACE("%p\n", context); + TRACE("%p\n", this); - if((cprops=ATOMIC_LOAD(&context->Update, almemory_order_acquire)) != nullptr) + struct ALcontextProps *cprops{Update.load(std::memory_order_relaxed)}; + if(cprops) { TRACE("Freed unapplied context update %p\n", cprops); al_free(cprops); } - - count = 0; - cprops = ATOMIC_LOAD(&context->FreeContextProps, almemory_order_acquire); + size_t count{0}; + cprops = FreeContextProps.load(std::memory_order_acquire); while(cprops) { - struct ALcontextProps *next = ATOMIC_LOAD(&cprops->next, almemory_order_acquire); + struct ALcontextProps *next{cprops->next.load(std::memory_order_relaxed)}; al_free(cprops); cprops = next; ++count; } TRACE("Freed " SZFMT " context property object%s\n", count, (count==1)?"":"s"); - if(context->DefaultSlot) + if(DefaultSlot) { - DeinitEffectSlot(context->DefaultSlot); - delete context->DefaultSlot; - context->DefaultSlot = nullptr; + DeinitEffectSlot(DefaultSlot); + delete DefaultSlot; + DefaultSlot = nullptr; } - al_free(ATOMIC_EXCHANGE(&context->ActiveAuxSlots, - static_cast<ALeffectslotArray*>(nullptr), almemory_order_relaxed)); + al_free(ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)); - ReleaseALSources(context); - std::for_each(context->SourceList.begin(), context->SourceList.end(), + ReleaseALSources(this); + std::for_each(SourceList.begin(), SourceList.end(), [](const SourceSubList &entry) noexcept -> void { al_free(entry.Sources); } ); - context->SourceList.clear(); - context->NumSources = 0; - almtx_destroy(&context->SourceLock); + SourceList.clear(); + NumSources = 0; + almtx_destroy(&SourceLock); count = 0; - eprops = ATOMIC_LOAD(&context->FreeEffectslotProps, almemory_order_relaxed); + struct ALeffectslotProps *eprops{FreeEffectslotProps.load(std::memory_order_acquire)}; while(eprops) { - struct ALeffectslotProps *next = ATOMIC_LOAD(&eprops->next, almemory_order_relaxed); + struct ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)}; if(eprops->State) ALeffectState_DecRef(eprops->State); al_free(eprops); eprops = next; @@ -2735,56 +2726,54 @@ static void FreeContext(ALCcontext *context) } TRACE("Freed " SZFMT " AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); - ReleaseALAuxiliaryEffectSlots(context); - context->EffectSlotList.clear(); - almtx_destroy(&context->EffectSlotLock); + ReleaseALAuxiliaryEffectSlots(this); + EffectSlotList.clear(); + almtx_destroy(&EffectSlotLock); count = 0; - vprops = ATOMIC_LOAD(&context->FreeVoiceProps, almemory_order_relaxed); + struct ALvoiceProps *vprops{FreeVoiceProps.load(std::memory_order_acquire)}; while(vprops) { - struct ALvoiceProps *next = ATOMIC_LOAD(&vprops->next, almemory_order_relaxed); + struct ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)}; al_free(vprops); vprops = next; ++count; } TRACE("Freed " SZFMT " voice property object%s\n", count, (count==1)?"":"s"); - for(i = 0;i < context->VoiceCount;i++) - DeinitVoice(context->Voices[i]); - al_free(context->Voices); - context->Voices = nullptr; - context->VoiceCount = 0; - context->MaxVoices = 0; + for(ALsizei i{0};i < VoiceCount;i++) + DeinitVoice(Voices[i]); + al_free(Voices); + Voices = nullptr; + VoiceCount = 0; + MaxVoices = 0; - if((lprops=ATOMIC_LOAD(&listener.Update, almemory_order_acquire)) != nullptr) + struct ALlistenerProps *lprops{Listener.Update.load(std::memory_order_relaxed)}; + if(lprops) { TRACE("Freed unapplied listener update %p\n", lprops); al_free(lprops); } count = 0; - lprops = ATOMIC_LOAD(&context->FreeListenerProps, almemory_order_acquire); + lprops = FreeListenerProps.load(std::memory_order_acquire); while(lprops) { - struct ALlistenerProps *next = ATOMIC_LOAD(&lprops->next, almemory_order_acquire); + struct ALlistenerProps *next{lprops->next.load(std::memory_order_relaxed)}; al_free(lprops); lprops = next; ++count; } TRACE("Freed " SZFMT " listener property object%s\n", count, (count==1)?"":"s"); - almtx_destroy(&context->EventCbLock); - alsem_destroy(&context->EventSem); + almtx_destroy(&EventCbLock); + alsem_destroy(&EventSem); - ll_ringbuffer_free(context->AsyncEvents); - context->AsyncEvents = nullptr; + ll_ringbuffer_free(AsyncEvents); + AsyncEvents = nullptr; - almtx_destroy(&context->PropLock); + almtx_destroy(&PropLock); - ALCdevice_DecRef(context->Device); - context->Device = nullptr; - - delete context; + ALCdevice_DecRef(Device); } /* ReleaseContext @@ -2852,7 +2841,7 @@ void ALCcontext_DecRef(ALCcontext *context) { uint ref = DecrementRef(&context->ref); TRACEREF("%p decreasing refcount to %u\n", context, ref); - if(ref == 0) FreeContext(context); + if(ref == 0) delete context; } static void ReleaseThreadCtx(ALCcontext *context) @@ -3782,23 +3771,14 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ATOMIC_STORE_SEQ(&device->LastError, ALC_NO_ERROR); - ALContext = new ALCcontext{}; - - InitRef(&ALContext->ref, 1); - ALContext->DefaultSlot = nullptr; - - ALContext->Voices = nullptr; - ALContext->VoiceCount = 0; - ALContext->MaxVoices = 0; - ATOMIC_INIT(&ALContext->ActiveAuxSlots, static_cast<ALeffectslotArray*>(nullptr)); - ALContext->Device = device; - ATOMIC_INIT(&ALContext->next, static_cast<ALCcontext*>(nullptr)); + ALContext = new ALCcontext{device}; + ALCdevice_IncRef(ALContext->Device); if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR) { almtx_unlock(&device->BackendLock); - al_free(ALContext); + delete ALContext; ALContext = nullptr; alcSetError(device, err); @@ -3826,7 +3806,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin } } - ALCdevice_IncRef(ALContext->Device); InitContext(ALContext); if(ConfigValueFloat(device->DeviceName, nullptr, "volume-adjust", &valf)) diff --git a/Alc/alcontext.h b/Alc/alcontext.h index 2cdb0cf7..6a7ac376 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -47,71 +47,77 @@ struct SourceSubList { using ALeffectslotPtr = struct ALeffectslot*; struct ALCcontext_struct { - RefCount ref; + RefCount ref{1u}; al::vector<SourceSubList> SourceList; - ALuint NumSources; + ALuint NumSources{0}; almtx_t SourceLock; al::vector<ALeffectslotPtr> EffectSlotList; almtx_t EffectSlotLock; - ATOMIC(ALenum) LastError; + ATOMIC(ALenum) LastError{AL_NO_ERROR}; - DistanceModel mDistanceModel; - ALboolean SourceDistanceModel; + DistanceModel mDistanceModel{DistanceModel::Default}; + ALboolean SourceDistanceModel{AL_FALSE}; - ALfloat DopplerFactor; - ALfloat DopplerVelocity; - ALfloat SpeedOfSound; - ALfloat MetersPerUnit; + ALfloat DopplerFactor{1.0f}; + ALfloat DopplerVelocity{1.0f}; + ALfloat SpeedOfSound{}; + ALfloat MetersPerUnit{1.0f}; - ATOMIC(ALenum) PropsClean; - ATOMIC(ALenum) DeferUpdates; + ATOMIC(ALenum) PropsClean{AL_TRUE}; + ATOMIC(ALenum) DeferUpdates{AL_FALSE}; almtx_t PropLock; /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit * indicates if updates are currently happening). */ - RefCount UpdateCount; - ATOMIC(ALenum) HoldUpdates; + RefCount UpdateCount{0u}; + ATOMIC(ALenum) HoldUpdates{AL_FALSE}; - ALfloat GainBoost; + ALfloat GainBoost{1.0f}; - ATOMIC(ALcontextProps*) Update; + ATOMIC(ALcontextProps*) Update{nullptr}; /* Linked lists of unused property containers, free to use for future * updates. */ - ATOMIC(ALcontextProps*) FreeContextProps; - ATOMIC(ALlistenerProps*) FreeListenerProps; - ATOMIC(ALvoiceProps*) FreeVoiceProps; - ATOMIC(ALeffectslotProps*) FreeEffectslotProps; + ATOMIC(ALcontextProps*) FreeContextProps{nullptr}; + ATOMIC(ALlistenerProps*) FreeListenerProps{nullptr}; + ATOMIC(ALvoiceProps*) FreeVoiceProps{nullptr}; + ATOMIC(ALeffectslotProps*) FreeEffectslotProps{nullptr}; - ALvoice **Voices; - ALsizei VoiceCount; - ALsizei MaxVoices; + ALvoice **Voices{nullptr}; + ALsizei VoiceCount{0}; + ALsizei MaxVoices{0}; - ATOMIC(ALeffectslotArray*) ActiveAuxSlots; + ATOMIC(ALeffectslotArray*) ActiveAuxSlots{nullptr}; althrd_t EventThread; alsem_t EventSem; - ll_ringbuffer *AsyncEvents; - ATOMIC(ALbitfieldSOFT) EnabledEvts; + ll_ringbuffer *AsyncEvents{nullptr}; + ATOMIC(ALbitfieldSOFT) EnabledEvts{0u}; almtx_t EventCbLock; - ALEVENTPROCSOFT EventCb; - void *EventParam; + ALEVENTPROCSOFT EventCb{}; + void *EventParam{nullptr}; /* Default effect slot */ - ALeffectslot *DefaultSlot; + ALeffectslot *DefaultSlot{nullptr}; + + ALCdevice *const Device; + const ALCchar *ExtensionList{nullptr}; + + ATOMIC(ALCcontext*) next{nullptr}; - ALCdevice *Device; - const ALCchar *ExtensionList; + ALlistener Listener{}; - ATOMIC(ALCcontext*) next; - ALlistener Listener; + ALCcontext_struct(ALCdevice *device) : Device{device} { } + ALCcontext_struct(const ALCcontext_struct&) = delete; + ALCcontext_struct& operator=(const ALCcontext_struct&) = delete; + ~ALCcontext_struct(); DEF_NEWDEL(ALCcontext) }; diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h index e14527d9..1e0a8265 100644 --- a/OpenAL32/Include/alListener.h +++ b/OpenAL32/Include/alListener.h @@ -22,17 +22,17 @@ struct ALlistenerProps { }; struct ALlistener { - alignas(16) ALfloat Position[3]; - ALfloat Velocity[3]; - ALfloat Forward[3]; - ALfloat Up[3]; - ALfloat Gain; + ALfloat Position[3]{0.0f, 0.0f, 0.0f}; + ALfloat Velocity[3]{0.0f, 0.0f, 0.0f}; + ALfloat Forward[3]{0.0f, 0.0f, -1.0f}; + ALfloat Up[3]{0.0f, 1.0f, 0.0f}; + ALfloat Gain{1.0f}; - ATOMIC(ALenum) PropsClean; + ATOMIC(ALenum) PropsClean{AL_TRUE}; /* Pointer to the most recent property values that are awaiting an update. */ - ATOMIC(ALlistenerProps*) Update; + ATOMIC(ALlistenerProps*) Update{nullptr}; struct { aluMatrixf Matrix; |