Browse Source

Nullkiller: thread interuption point

Andrii Danylchenko 4 years ago
parent
commit
f2c26d7553

+ 2 - 0
AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp

@@ -46,6 +46,8 @@ void DangerHitMapAnalyzer::updateHitMap()
 	{
 		ai->pathfinder->updatePaths(pair.second, PathfinderSettings());
 
+		boost::this_thread::interruption_point();
+
 		foreach_tile_pos([&](const int3 & pos)
 		{
 			for(AIPath & path : ai->pathfinder->getPathInfo(pos))

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

@@ -44,7 +44,7 @@ void Nullkiller::init(std::shared_ptr<CCallback> cb, PlayerColor playerID)
 
 	priorityEvaluator.reset(new PriorityEvaluator(this));
 	dangerHitMap.reset(new DangerHitMapAnalyzer(this));
-	buildAnalyzer.reset(new BuildAnalyzer());
+	buildAnalyzer.reset(new BuildAnalyzer(this));
 	objectClusterizer.reset(new ObjectClusterizer(this));
 	dangerEvaluator.reset(new FuzzyHelper(this));
 	pathfinder.reset(new AIPathfinder(cb.get(), this));
@@ -70,6 +70,8 @@ Goals::TTask Nullkiller::choseBestTask(Goals::TSubgoal behavior, int decompositi
 	
 	Goals::TGoalVec elementarGoals = decomposer->decompose(behavior, decompositionMaxDepth);
 	Goals::TTaskVec tasks;
+
+	boost::this_thread::interruption_point();
 	
 	for(auto goal : elementarGoals)
 	{
@@ -109,6 +111,8 @@ void Nullkiller::resetAiState()
 
 void Nullkiller::updateAiState(int pass)
 {
+	boost::this_thread::interruption_point();
+
 	auto start = boost::chrono::high_resolution_clock::now();
 
 	activeHero = nullptr;
@@ -116,6 +120,8 @@ void Nullkiller::updateAiState(int pass)
 	memory->removeInvisibleObjects(cb.get());
 	dangerHitMap->updateHitMap();
 
+	boost::this_thread::interruption_point();
+
 	heroManager->update();
 	logAi->trace("Updating paths");
 
@@ -216,6 +222,7 @@ void Nullkiller::makeTurn()
 			return;
 		}
 
+		boost::this_thread::interruption_point();
 		logAi->debug("Trying to realize %s (value %2.3f)", bestTask->toString(), bestTask->priority);
 
 		try

+ 4 - 0
AI/Nullkiller/Pathfinding/AIPathfinder.cpp

@@ -78,6 +78,8 @@ void AIPathfinder::updatePaths(std::map<const CGHeroInstance *, HeroRole> heroes
 		{
 			while(storage->calculateHeroChain())
 			{
+				boost::this_thread::interruption_point();
+
 				logAi->trace("Recalculate paths pass %d", pass++);
 				cb->calculatePaths(config);
 			}
@@ -87,6 +89,8 @@ void AIPathfinder::updatePaths(std::map<const CGHeroInstance *, HeroRole> heroes
 
 		if(storage->calculateHeroChainFinal())
 		{
+			boost::this_thread::interruption_point();
+
 			logAi->trace("Recalculate paths pass final");
 			cb->calculatePaths(config);
 		}