diff options
author | WasabiRaptor <ketchupraptor@gmail.com> | 2025-05-25 19:12:06 -0400 |
---|---|---|
committer | WasabiRaptor <ketchupraptor@gmail.com> | 2025-05-25 19:12:06 -0400 |
commit | 28466a651bd8449f17bd229178698aa8eac7c56d (patch) | |
tree | e8e07473fec4af4ce5a1021390e76f7b34b99dac /source/core | |
parent | 59854f015602b791b51c20a008e78aaed68d20b9 (diff) | |
parent | 4b3cf6a40c4a2291dd6cf344320840ba7a1980b3 (diff) |
Merge remote-tracking branch 'upstream/main' into networked-animator-improvements
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; |