Make the source's send array static instead of dynamic

This commit is contained in:
Chris Robinson 2020-02-25 06:39:03 -08:00
parent 9ddfcd6a1b
commit 795c4fcecc
3 changed files with 22 additions and 35 deletions

View File

@ -556,7 +556,7 @@ bool EnsureSources(ALCcontext *context, size_t needed)
return true;
}
ALsource *AllocSource(ALCcontext *context, ALuint num_sends)
ALsource *AllocSource(ALCcontext *context)
{
auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(),
[](const SourceSubList &entry) noexcept -> bool
@ -565,7 +565,7 @@ ALsource *AllocSource(ALCcontext *context, ALuint num_sends)
auto lidx = static_cast<ALuint>(std::distance(context->mSourceList.begin(), sublist));
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
ALsource *source{::new (sublist->Sources + slidx) ALsource{num_sends}};
ALsource *source{::new(sublist->Sources + slidx) ALsource{}};
/* Add 1 to avoid source ID 0. */
source->id = ((lidx<<6) | slidx) + 1;
@ -2100,16 +2100,15 @@ START_API_FUNC
if(n == 1)
{
ALsource *source{AllocSource(context.get(), device->NumAuxSends)};
ALsource *source{AllocSource(context.get())};
sources[0] = source->id;
}
else
{
const ALuint num_sends{device->NumAuxSends};
al::vector<ALuint> ids;
ids.reserve(static_cast<ALuint>(n));
do {
ALsource *source{AllocSource(context.get(), num_sends)};
ALsource *source{AllocSource(context.get())};
ids.emplace_back(source->id);
} while(--n);
std::copy(ids.cbegin(), ids.cend(), sources);
@ -3283,7 +3282,7 @@ START_API_FUNC
END_API_FUNC
ALsource::ALsource(ALuint num_sends)
ALsource::ALsource()
{
InnerAngle = 360.0f;
OuterAngle = 360.0f;
@ -3335,7 +3334,6 @@ ALsource::ALsource(ALuint num_sends)
Direct.HFReference = LOWPASSFREQREF;
Direct.GainLF = 1.0f;
Direct.LFReference = HIGHPASSFREQREF;
Send.resize(num_sends);
for(auto &send : Send)
{
send.Slot = nullptr;
@ -3360,14 +3358,9 @@ ALsource::~ALsource()
}
queue = nullptr;
std::for_each(Send.begin(), Send.end(),
[](ALsource::SendData &send) -> void
{
if(send.Slot)
DecrementRef(send.Slot->ref);
send.Slot = nullptr;
}
);
auto clear_send = [](ALsource::SendData &send) -> void
{ if(send.Slot) DecrementRef(send.Slot->ref); };
std::for_each(Send.begin(), Send.end(), clear_send);
}
void UpdateAllSourceProps(ALCcontext *context)

View File

@ -88,7 +88,7 @@ struct ALsource {
ALfloat GainLF;
ALfloat LFReference;
};
al::vector<SendData> Send;
std::array<SendData,MAX_SENDS> Send;
/**
* Last user-specified offset, and the offset type (bytes, samples, or
@ -117,7 +117,7 @@ struct ALsource {
ALuint id{0};
ALsource(ALuint num_sends);
ALsource();
~ALsource();
ALsource(const ALsource&) = delete;

View File

@ -2269,25 +2269,19 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
usemask &= ~(1_u64 << idx);
if(old_sends != device->NumAuxSends)
auto clear_send = [](ALsource::SendData &send) -> void
{
if(source->Send.size() > device->NumAuxSends)
{
auto clear_send = [](ALsource::SendData &send) -> void
{
if(send.Slot)
DecrementRef(send.Slot->ref);
send.Slot = nullptr;
};
auto send_begin = source->Send.begin() +
static_cast<ptrdiff_t>(device->NumAuxSends);
std::for_each(send_begin, source->Send.end(), clear_send);
}
source->Send.resize(device->NumAuxSends,
{nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF});
source->Send.shrink_to_fit();
}
if(send.Slot)
DecrementRef(send.Slot->ref);
send.Slot = nullptr;
send.Gain = 1.0f;
send.GainHF = 1.0f;
send.HFReference = LOWPASSFREQREF;
send.GainLF = 1.0f;
send.LFReference = HIGHPASSFREQREF;
};
auto send_begin = source->Send.begin()+static_cast<ptrdiff_t>(device->NumAuxSends);
std::for_each(send_begin, source->Send.end(), clear_send);
source->PropsClean.clear(std::memory_order_release);
}