From cfadcc8ec765a8fe8b50bc108339f3cc326568ec Mon Sep 17 00:00:00 2001 From: Keleborn <22352763+Celandriel@users.noreply.github.com> Date: Mon, 27 Apr 2026 13:33:36 -0700 Subject: [PATCH] Clean up node generation --- src/Ai/Base/Actions/DebugAction.cpp | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Ai/Base/Actions/DebugAction.cpp b/src/Ai/Base/Actions/DebugAction.cpp index a4d0d2494..d343396b8 100644 --- a/src/Ai/Base/Actions/DebugAction.cpp +++ b/src/Ai/Base/Actions/DebugAction.cpp @@ -196,18 +196,18 @@ bool DebugAction::Execute(Event event) { WorldPosition pos(bot); - std::string const name = "USER:" + text.substr(9); + std::string suffix = text.size() > 9 ? text.substr(9) : pos.getAreaName(); + std::string const name = "USER:" + suffix; - /* TravelNode* startNode = */ TravelNodeMap::instance().addNode(pos, name, false, false); // startNode not used, but addNode as side effect, fragment marked for removal. - - for (auto& endNode : TravelNodeMap::instance().getNodes(pos, 2000)) { - endNode->setLinked(false); + std::lock_guard lock(TravelNodeMap::instance().m_nMapMtx); + TravelNodeMap::instance().addNode(pos, name, false, true); + + for (auto& endNode : TravelNodeMap::instance().getNodes(pos, 2000)) + endNode->setLinked(false); } - botAI->TellMasterNoFacing("Node " + name + " created."); - - TravelNodeMap::instance().setHasToGen(); + botAI->TellMasterNoFacing("Node " + name + " created. Run 'gen path' when done adding nodes."); return true; } @@ -223,14 +223,15 @@ bool DebugAction::Execute(Event event) if (startNode->isImportant()) { botAI->TellMasterNoFacing("Node can not be removed."); + return true; } - TravelNodeMap::instance().m_nMapMtx.lock(); - TravelNodeMap::instance().removeNode(startNode); - botAI->TellMasterNoFacing("Node removed."); - TravelNodeMap::instance().m_nMapMtx.unlock(); + { + std::lock_guard lock(TravelNodeMap::instance().m_nMapMtx); + TravelNodeMap::instance().removeNode(startNode); + } - TravelNodeMap::instance().setHasToGen(); + botAI->TellMasterNoFacing("Node removed. Run 'gen path' when done editing nodes."); return true; } @@ -249,13 +250,14 @@ bool DebugAction::Execute(Event event) } else if (text.find("gen node") != std::string::npos) { - // Pathfinder - TravelNodeMap::instance().generateNodes(); + botAI->TellMasterNoFacing("Regenerating travel nodes..."); + std::thread([]() { TravelNodeMap::instance().generateAll(); }).detach(); return true; } else if (text.find("gen path") != std::string::npos) { - TravelNodeMap::instance().generatePaths(); + botAI->TellMasterNoFacing("Regenerating travel paths..."); + std::thread([]() { TravelNodeMap::instance().generateAll(); }).detach(); return true; } else if (text.find("crop path") != std::string::npos)