浏览代码

NKAI: fix parallel access to object graph

Andrii Danylchenko 1 年之前
父节点
当前提交
7aff0e63fc
共有 2 个文件被更改,包括 10 次插入3 次删除
  1. 1 1
      AI/Nullkiller/Engine/Settings.cpp
  2. 9 2
      AI/Nullkiller/Pathfinding/ObjectGraph.cpp

+ 1 - 1
AI/Nullkiller/Engine/Settings.cpp

@@ -27,7 +27,7 @@ namespace NKAI
 		mainHeroTurnDistanceLimit(10),
 		scoutHeroTurnDistanceLimit(5),
 		maxGoldPressure(0.3f), 
-		maxpass(30),
+		maxpass(10),
 		allowObjectGraph(false)
 	{
 		ResourcePath resource("config/ai/nkai/nkai-settings", EResType::JSON);

+ 9 - 2
AI/Nullkiller/Pathfinding/ObjectGraph.cpp

@@ -112,7 +112,9 @@ public:
 
 	void addMinimalDistanceJunctions()
 	{
-		pforeachTilePaths(ai->cb->getMapSize(), ai, [this](const int3 & pos, std::vector<AIPath> & paths)
+		tbb::concurrent_unordered_set<int3, std::hash<int3>> junctions;
+
+		pforeachTilePaths(ai->cb->getMapSize(), ai, [this, &junctions](const int3 & pos, std::vector<AIPath> & paths)
 			{
 				if(target->hasNodeAt(pos))
 					return;
@@ -129,9 +131,14 @@ public:
 
 				if(currentCost.avg < neighborCost)
 				{
-					addJunctionActor(pos);
+					junctions.insert(pos);
 				}
 			});
+
+		for(auto pos : junctions)
+		{
+			addJunctionActor(pos);
+		}
 	}
 
 private: