From f2c26d75530af660a02a4464d8bc401c3528b821 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sun, 16 May 2021 14:57:33 +0300 Subject: [PATCH] Nullkiller: thread interuption point --- AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp | 2 ++ AI/Nullkiller/Engine/Nullkiller.cpp | 9 ++++++++- AI/Nullkiller/Pathfinding/AIPathfinder.cpp | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index 37f749cff..e4f5c6fbb 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/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)) diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index 0abfe64dd..4fdbc3083 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -44,7 +44,7 @@ void Nullkiller::init(std::shared_ptr 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 diff --git a/AI/Nullkiller/Pathfinding/AIPathfinder.cpp b/AI/Nullkiller/Pathfinding/AIPathfinder.cpp index f0dbab692..e9784e89e 100644 --- a/AI/Nullkiller/Pathfinding/AIPathfinder.cpp +++ b/AI/Nullkiller/Pathfinding/AIPathfinder.cpp @@ -78,6 +78,8 @@ void AIPathfinder::updatePaths(std::map 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 heroes if(storage->calculateHeroChainFinal()) { + boost::this_thread::interruption_point(); + logAi->trace("Recalculate paths pass final"); cb->calculatePaths(config); }