diff options
author | Chris Robinson <[email protected]> | 2022-07-15 06:14:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-07-15 06:14:25 -0700 |
commit | 0f4679981b575cc76158126dec7d9bdda3ba1c29 (patch) | |
tree | 77e9176befdeb963e7dd791fc50df3db34f789bc /core/context.cpp | |
parent | 0b9fc03545f7418be89bb9a8901b342ce84a5f67 (diff) |
Allocate EffectSlots in clusters
Diffstat (limited to 'core/context.cpp')
-rw-r--r-- | core/context.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
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<int>::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<EffectSlot[]>(EffectSlotClusterSize)); + return getEffectSlot(); +} |