From 0f4679981b575cc76158126dec7d9bdda3ba1c29 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 15 Jul 2022 06:14:25 -0700 Subject: Allocate EffectSlots in clusters --- core/context.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'core/context.cpp') diff --git a/core/context.cpp b/core/context.cpp index 39fd8522..111802d9 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -136,3 +136,24 @@ void ContextBase::allocVoices(size_t addcount) delete oldvoices; } } + + +EffectSlot *ContextBase::getEffectSlot() +{ + for(auto& cluster : mEffectSlotClusters) + { + for(size_t i{0};i < EffectSlotClusterSize;++i) + { + if(!cluster[i].InUse) + return &cluster[i]; + } + } + + if(1 >= std::numeric_limits::max()/EffectSlotClusterSize - mEffectSlotClusters.size()) + throw std::runtime_error{"Allocating too many effect slots"}; + const size_t totalcount{(mEffectSlotClusters.size()+1) * EffectSlotClusterSize}; + TRACE("Increasing allocated effect slots to %zu\n", totalcount); + + mEffectSlotClusters.emplace_back(std::make_unique(EffectSlotClusterSize)); + return getEffectSlot(); +} -- cgit v1.2.3