mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
AI pathfinding: use own FuzzyHelper for each storage to allow parallel processing without cuncarrent access
This commit is contained in:
@@ -21,6 +21,7 @@ AINodeStorage::AINodeStorage(const int3 & Sizes)
|
||||
: sizes(Sizes)
|
||||
{
|
||||
nodes.resize(boost::extents[sizes.x][sizes.y][sizes.z][EPathfindingLayer::NUM_LAYERS][NUM_CHAINS]);
|
||||
dangerEvaluator.reset(new FuzzyHelper());
|
||||
}
|
||||
|
||||
AINodeStorage::~AINodeStorage() = default;
|
||||
@@ -358,6 +359,8 @@ std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand)
|
||||
current = getAINode(current->theNodeBefore);
|
||||
}
|
||||
|
||||
path.targetObjectDanger = evaluateDanger(pos);
|
||||
|
||||
paths.push_back(path);
|
||||
}
|
||||
|
||||
@@ -403,8 +406,7 @@ float AIPath::movementCost() const
|
||||
uint64_t AIPath::getTotalDanger(HeroPtr hero) const
|
||||
{
|
||||
uint64_t pathDanger = getPathDanger();
|
||||
uint64_t objDanger = evaluateDanger(nodes.front().coord, hero.get()); // bank danger is not checked by pathfinder
|
||||
uint64_t danger = pathDanger > objDanger ? pathDanger : objDanger;
|
||||
uint64_t danger = pathDanger > targetObjectDanger ? pathDanger : targetObjectDanger;
|
||||
|
||||
return danger;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "../../../lib/CPathfinder.h"
|
||||
#include "../../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "../AIUtility.h"
|
||||
#include "../FuzzyHelper.h"
|
||||
#include "../Goals/AbstractGoal.h"
|
||||
#include "Actions/ISpecialAction.h"
|
||||
|
||||
@@ -38,6 +39,7 @@ struct AIPath
|
||||
{
|
||||
std::vector<AIPathNodeInfo> nodes;
|
||||
std::shared_ptr<const ISpecialAction> specialAction;
|
||||
uint64_t targetObjectDanger;
|
||||
|
||||
AIPath();
|
||||
|
||||
@@ -61,6 +63,7 @@ private:
|
||||
boost::multi_array<AIPathNode, 5> nodes;
|
||||
const CPlayerSpecificInfoCallback * cb;
|
||||
const CGHeroInstance * hero;
|
||||
std::unique_ptr<FuzzyHelper> dangerEvaluator;
|
||||
|
||||
STRONG_INLINE
|
||||
void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility);
|
||||
@@ -110,6 +113,11 @@ public:
|
||||
return hero;
|
||||
}
|
||||
|
||||
uint64_t evaluateDanger(const int3 & tile) const
|
||||
{
|
||||
return dangerEvaluator->evaluateDanger(tile, hero, cb);
|
||||
}
|
||||
|
||||
private:
|
||||
void calculateTownPortalTeleportations(const PathNodeInfo & source, std::vector<CGPathNode *> & neighbours);
|
||||
};
|
||||
|
||||
@@ -89,7 +89,7 @@ void AIPathfinder::updatePaths(std::vector<HeroPtr> heroes)
|
||||
boost::thread::hardware_concurrency(),
|
||||
(uint32_t)calculationTasks.size());
|
||||
|
||||
if(threadsCount == 1)
|
||||
if(threadsCount <= 1)
|
||||
{
|
||||
for(auto task : calculationTasks)
|
||||
{
|
||||
|
||||
@@ -121,8 +121,7 @@ namespace AIPathfinding
|
||||
return;
|
||||
}
|
||||
|
||||
auto hero = nodeStorage->getHero();
|
||||
auto danger = evaluateDanger(destination.coord, hero, cb);
|
||||
auto danger = nodeStorage->evaluateDanger(destination.coord);
|
||||
|
||||
destination.node = battleNode;
|
||||
nodeStorage->commit(destination, source);
|
||||
|
||||
Reference in New Issue
Block a user