diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-26 05:37:23 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-26 05:37:23 +1000 |
commit | 4b3cf6a40c4a2291dd6cf344320840ba7a1980b3 (patch) | |
tree | 86f50764c4b437cf0f70a13167c7208dfc49f462 /source/core | |
parent | f3079a79e7d336fabc6b8bbd0a670176e0b5bc6a (diff) |
net: fix index index compatibility issues in NetElementGroup
Diffstat (limited to 'source/core')
-rw-r--r-- | source/core/StarNetElementGroup.cpp | 35 | ||||
-rw-r--r-- | source/core/StarNetElementGroup.hpp | 4 |
2 files changed, 28 insertions, 11 deletions
diff --git a/source/core/StarNetElementGroup.cpp b/source/core/StarNetElementGroup.cpp index 6626e2b..901eeb1 100644 --- a/source/core/StarNetElementGroup.cpp +++ b/source/core/StarNetElementGroup.cpp @@ -13,6 +13,8 @@ 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) { @@ -89,26 +91,24 @@ bool NetElementGroup::writeNetDelta(DataStream& ds, uint64_t fromVersion, NetCom void NetElementGroup::readNetDelta(DataStream& ds, float interpolationTime, NetCompatibilityRules 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); + 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); } else { uint64_t readIndex = ds.readVlqU(); - uint64_t i = 0; - for (auto& element : m_elements) { - if (!element.first->checkWithRules(rules)) - continue; + for (uint64_t i = 0; i != elements.size(); ++i) { if (readIndex == 0 || readIndex - 1 > i) { if (m_interpolationEnabled) - m_elements[i].first->blankNetDelta(interpolationTime); + elements[i]->blankNetDelta(interpolationTime); } else if (readIndex - 1 == i) { - m_elements[i].first->readNetDelta(ds, interpolationTime, rules); + elements[i]->readNetDelta(ds, interpolationTime); readIndex = ds.readVlqU(); } else { throw IOException("group indexes out of order in NetElementGroup::readNetDelta"); } - ++i; } } } @@ -120,4 +120,17 @@ 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; +} + } diff --git a/source/core/StarNetElementGroup.hpp b/source/core/StarNetElementGroup.hpp index 1904a33..6f009d8 100644 --- a/source/core/StarNetElementGroup.hpp +++ b/source/core/StarNetElementGroup.hpp @@ -40,7 +40,11 @@ public: float netExtrapolationHint() const; private: + List<NetElement*>& filterElementsForRules(NetCompatibilityRules rules); + List<pair<NetElement*, bool>> m_elements; + Maybe<NetCompatibilityRules> m_filteredForRules; + List<NetElement*> m_filteredElementsCache; NetElementVersion const* m_version = nullptr; bool m_interpolationEnabled = false; float m_extrapolationHint = 0.0f; |