1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

NKAI: fix parallel access to object graph

This commit is contained in:
Andrii Danylchenko 2024-04-21 11:13:37 +03:00
parent 0935f931fa
commit 7aff0e63fc
2 changed files with 10 additions and 3 deletions

View File

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

View File

@ -112,7 +112,9 @@ public:
void addMinimalDistanceJunctions() 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)) if(target->hasNodeAt(pos))
return; return;
@ -129,9 +131,14 @@ public:
if(currentCost.avg < neighborCost) if(currentCost.avg < neighborCost)
{ {
addJunctionActor(pos); junctions.insert(pos);
} }
}); });
for(auto pos : junctions)
{
addJunctionActor(pos);
}
} }
private: private: