From 71cd25a798b1414f9f01fd09acf5842f2c3511e8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 18 Mar 2025 20:26:11 +0100 Subject: [PATCH] Preserve LBM ordering when running them (broken in 811adf5d42844bbd40e98e07773db3d16e104b90) --- src/serverenvironment.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 9a810434f..b299d1f7e 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -237,6 +237,21 @@ std::string LBMManager::createIntroductionTimesString() return oss.str(); } +namespace { + struct LBMToRun { + std::unordered_set p; // node positions + std::vector l; // ordered list of LBMs + + template + void insertLBMs(const C &container) { + for (auto &it : container) { + if (!CONTAINS(l, it)) + l.push_back(it); + } + } + }; +} + void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, const u32 stamp, const float dtime_s) { @@ -245,10 +260,6 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, "attempted to query on non fully set up LBMManager"); // Collect a list of all LBMs and associated positions - struct LBMToRun { - std::unordered_set p; // node positions - std::unordered_set l; - }; std::unordered_map to_run; // Note: the iteration count of this outer loop is typically very low, so it's ok. @@ -279,7 +290,7 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, continue; batch->p.insert(pos); if (c_changed) { - batch->l.insert(lbm_list->begin(), lbm_list->end()); + batch->insertLBMs(*lbm_list); } else { // we were here before so the list must be filled assert(!batch->l.empty()); @@ -290,6 +301,11 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, // Actually run them bool first = true; for (auto &[c, batch] : to_run) { + if (tracestream) { + tracestream << "Running " << batch.l.size() << " LBMs for node " + << env->getGameDef()->ndef()->get(c).name << " (" + << batch.p.size() << "x) in block " << block->getPos() << std::endl; + } for (auto &lbm_def : batch.l) { if (!first) { // The fun part: since any LBM call can change the nodes inside of he