diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-26 11:37:24 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-26 11:37:24 +1000 |
commit | 3a7a5187e6e63e0b47430160d3facb6d99db6005 (patch) | |
tree | f8a0d8fb03a77a40ab366f2ebae99f9592ef4245 /source/core/StarNetElementGroup.cpp | |
parent | 4b3cf6a40c4a2291dd6cf344320840ba7a1980b3 (diff) |
cleaner fix for NetElementGroup
ty @WasabiRaptor
Diffstat (limited to 'source/core/StarNetElementGroup.cpp')
-rw-r--r-- | source/core/StarNetElementGroup.cpp | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/source/core/StarNetElementGroup.cpp b/source/core/StarNetElementGroup.cpp index 901eeb1..2f0df52 100644 --- a/source/core/StarNetElementGroup.cpp +++ b/source/core/StarNetElementGroup.cpp @@ -13,8 +13,6 @@ void NetElementGroup::addNetElement(NetElement* element, bool propagateInterpola void NetElementGroup::clearNetElements() { m_elements.clear(); - m_filteredForRules.reset(); - m_filteredElementsCache.clear(); } void NetElementGroup::initNetVersion(NetElementVersion const* version) { @@ -90,25 +88,31 @@ bool NetElementGroup::writeNetDelta(DataStream& ds, uint64_t fromVersion, NetCom } void NetElementGroup::readNetDelta(DataStream& ds, float interpolationTime, NetCompatibilityRules rules) { - if (!checkWithRules(rules)) return; - auto& elements = filterElementsForRules(rules); - if (elements.size() == 0) { - if (m_elements.size() == 0) - throw IOException("readNetDelta called on empty NetElementGroup"); - } else if (elements.size() == 1) { - elements[0]->readNetDelta(ds, interpolationTime, rules); + if (!checkWithRules(rules)) + return; + if (m_elements.size() == 0) { + throw IOException("readNetDelta called on empty NetElementGroup"); + } else if (m_elements.size() == 1) { + m_elements[0].first->readNetDelta(ds, interpolationTime, rules); } else { uint64_t readIndex = ds.readVlqU(); - for (uint64_t i = 0; i != elements.size(); ++i) { + uint64_t i = 0; + uint64_t offset = 0; + for (auto& element : m_elements) { + if (!element.first->checkWithRules(rules)) { + offset++; + continue; + } if (readIndex == 0 || readIndex - 1 > i) { if (m_interpolationEnabled) - elements[i]->blankNetDelta(interpolationTime); + m_elements[i + offset].first->blankNetDelta(interpolationTime); } else if (readIndex - 1 == i) { - elements[i]->readNetDelta(ds, interpolationTime); + m_elements[i + offset].first->readNetDelta(ds, interpolationTime, rules); readIndex = ds.readVlqU(); } else { throw IOException("group indexes out of order in NetElementGroup::readNetDelta"); } + ++i; } } } @@ -120,17 +124,4 @@ void NetElementGroup::blankNetDelta(float interpolationTime) { } } -List<NetElement*>& NetElementGroup::filterElementsForRules(NetCompatibilityRules rules) { - if (!m_filteredForRules || m_filteredForRules != rules) { - m_filteredForRules = rules; - m_filteredElementsCache.clear(); - m_filteredElementsCache.reserve(m_elements.size()); - for (auto& element : m_elements) { - if (element.first->checkWithRules(rules)) - m_filteredElementsCache.push_back(element.first); - } - } - return m_filteredElementsCache; -} - } |