aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-25 16:13:07 -0800
committerChris Robinson <[email protected]>2018-11-25 16:16:40 -0800
commit127ec026e7dd0722bd5fbc193a85cb28a95925f5 (patch)
treeb59e28ab8dbe140bb9260728de4d8980371c906d
parent8ae07ad1ae2d957f65ba54fdcd19649eceeb0e3d (diff)
Automatically clean up filters and effects with their sublists
-rw-r--r--Alc/alc.cpp20
-rw-r--r--OpenAL32/Include/alEffect.h1
-rw-r--r--OpenAL32/Include/alFilter.h9
-rw-r--r--OpenAL32/Include/alMain.h32
-rw-r--r--OpenAL32/alEffect.cpp26
-rw-r--r--OpenAL32/alFilter.cpp26
6 files changed, 54 insertions, 60 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 34279269..56bfb875 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -2404,19 +2404,19 @@ ALCdevice_struct::~ALCdevice_struct()
BufferList.clear();
almtx_destroy(&BufferLock);
- ReleaseALEffects(this);
- std::for_each(EffectList.begin(), EffectList.end(),
- [](EffectSubList &entry) noexcept -> void
- { al_free(entry.Effects); }
- );
+ count = 0;
+ for(auto &sublist : EffectList)
+ count += POPCNT64(~sublist.FreeMask);
+ if(count > 0)
+ WARN(SZFMT " Effect%s not deleted\n", count, (count==1)?"":"s");
EffectList.clear();
almtx_destroy(&EffectLock);
- ReleaseALFilters(this);
- std::for_each(FilterList.begin(), FilterList.end(),
- [](FilterSubList &entry) noexcept -> void
- { al_free(entry.Filters); }
- );
+ count = 0;
+ for(auto &sublist : FilterList)
+ count += POPCNT64(~sublist.FreeMask);
+ if(count > 0)
+ WARN(SZFMT " Filter%s not deleted\n", count, (count==1)?"":"s");
FilterList.clear();
almtx_destroy(&FilterLock);
diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h
index 38540cfc..441a8e97 100644
--- a/OpenAL32/Include/alEffect.h
+++ b/OpenAL32/Include/alEffect.h
@@ -199,7 +199,6 @@ inline ALboolean IsReverbEffect(ALenum type)
{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
void InitEffect(ALeffect *effect);
-void ReleaseALEffects(ALCdevice *device);
void LoadReverbPreset(const char *name, ALeffect *effect);
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h
index 2634d5e8..feca54e3 100644
--- a/OpenAL32/Include/alFilter.h
+++ b/OpenAL32/Include/alFilter.h
@@ -4,9 +4,6 @@
#include "AL/alc.h"
#include "AL/al.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
#define LOWPASSFREQREF (5000.0f)
#define HIGHPASSFREQREF (250.0f)
@@ -58,10 +55,4 @@ typedef struct ALfilter {
#define ALfilter_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v))
#define ALfilter_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v))
-void ReleaseALFilters(ALCdevice *device);
-
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index eae3ea99..c08f9a09 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -566,15 +566,35 @@ struct BufferSubList {
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Buffers, rhs.Buffers); return *this; }
};
-typedef struct EffectSubList {
- ALuint64 FreeMask{~ALuint64{}};
+struct EffectSubList {
+ uint64_t FreeMask{~uint64_t{}};
struct ALeffect *Effects{nullptr}; /* 64 */
-} EffectSubList;
-typedef struct FilterSubList {
- ALuint64 FreeMask{~ALuint64{}};
+ EffectSubList() noexcept = default;
+ EffectSubList(const EffectSubList&) = delete;
+ EffectSubList(EffectSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Effects{rhs.Effects}
+ { rhs.FreeMask = ~uint64_t{}; rhs.Effects = nullptr; }
+ ~EffectSubList();
+
+ EffectSubList& operator=(const EffectSubList&) = delete;
+ EffectSubList& operator=(EffectSubList&& rhs) noexcept
+ { std::swap(FreeMask, rhs.FreeMask); std::swap(Effects, rhs.Effects); return *this; }
+};
+
+struct FilterSubList {
+ uint64_t FreeMask{~uint64_t{}};
struct ALfilter *Filters{nullptr}; /* 64 */
-} FilterSubList;
+
+ FilterSubList() noexcept = default;
+ FilterSubList(const FilterSubList&) = delete;
+ FilterSubList(FilterSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Filters{rhs.Filters}
+ { rhs.FreeMask = ~uint64_t{}; rhs.Filters = nullptr; }
+ ~FilterSubList();
+
+ FilterSubList& operator=(const FilterSubList&) = delete;
+ FilterSubList& operator=(FilterSubList&& rhs) noexcept
+ { std::swap(FreeMask, rhs.FreeMask); std::swap(Filters, rhs.Filters); return *this; }
+};
typedef struct EnumeratedHrtf {
diff --git a/OpenAL32/alEffect.cpp b/OpenAL32/alEffect.cpp
index 2bc60e24..7f479c83 100644
--- a/OpenAL32/alEffect.cpp
+++ b/OpenAL32/alEffect.cpp
@@ -571,26 +571,18 @@ void InitEffect(ALeffect *effect)
InitEffectParams(effect, AL_EFFECT_NULL);
}
-void ReleaseALEffects(ALCdevice *device)
+EffectSubList::~EffectSubList()
{
- size_t leftover = 0;
- for(auto &sublist : device->EffectList)
+ ALuint64 usemask = ~FreeMask;
+ while(usemask)
{
- ALuint64 usemask = ~sublist.FreeMask;
- while(usemask)
- {
- ALsizei idx = CTZ64(usemask);
- ALeffect *effect = sublist.Effects + idx;
-
- effect->~ALeffect();
- ++leftover;
-
- usemask &= ~(U64(1) << idx);
- }
- sublist.FreeMask = ~usemask;
+ ALsizei idx = CTZ64(usemask);
+ Effects[idx].~ALeffect();
+ usemask &= ~(U64(1) << idx);
}
- if(leftover > 0)
- WARN("(%p) Deleted " SZFMT " Effect%s\n", device, leftover, (leftover==1)?"":"s");
+ FreeMask = ~usemask;
+ al_free(Effects);
+ Effects = nullptr;
}
diff --git a/OpenAL32/alFilter.cpp b/OpenAL32/alFilter.cpp
index 5b15e7e0..390432cb 100644
--- a/OpenAL32/alFilter.cpp
+++ b/OpenAL32/alFilter.cpp
@@ -622,24 +622,16 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *va
}
-void ReleaseALFilters(ALCdevice *device)
+FilterSubList::~FilterSubList()
{
- size_t leftover = 0;
- for(auto &sublist : device->FilterList)
+ ALuint64 usemask = ~FreeMask;
+ while(usemask)
{
- ALuint64 usemask = ~sublist.FreeMask;
- while(usemask)
- {
- ALsizei idx = CTZ64(usemask);
- ALfilter *filter = sublist.Filters + idx;
-
- filter->~ALfilter();
- ++leftover;
-
- usemask &= ~(U64(1) << idx);
- }
- sublist.FreeMask = ~usemask;
+ ALsizei idx = CTZ64(usemask);
+ Filters[idx].~ALfilter();
+ usemask &= ~(U64(1) << idx);
}
- if(leftover > 0)
- WARN("(%p) Deleted " SZFMT " Filter%s\n", device, leftover, (leftover==1)?"":"s");
+ FreeMask = ~usemask;
+ al_free(Filters);
+ Filters = nullptr;
}