From a254f3f1859302e00e43b58a7c78090c5b016359 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Tue, 25 Mar 2025 01:07:16 +0100 Subject: findNearestLivingBeing: do cheap bb check before set lookups or pathfinder bb= bounding box --- src/actormanager.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/actormanager.cpp b/src/actormanager.cpp index 2b542fede..2e1079487 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -1311,6 +1311,22 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, continue; } + // Cheap bounding box check, first, before engaging the pathfinder + // (in validateBeing call). Target is _at minimum_ distSq away + const int dx = being->getTileX() - x; + const int dy = being->getTileY() - y; + int distSq = dx*dx + dy*dy; + if (distSq > maxDistSq) + continue; + + // Check if target is too close + if (specialDistance + && (distSq <= 2*2) + && (being->getType() == type)) + { + continue; + } + int priority = defaultPriorityIndex; if (filtered) { @@ -1340,21 +1356,11 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, if (!validateBeing(aroundBeing, being, type, excluded, 50)) continue; - int distSq = being->getDistance(); - distSq = distSq * distSq; - - if (being->getType() != ActorType::Monster - || !mTargetOnlyReachable) - { // if distance not calculated, use old distance - const int dx = being->getTileX() - x; - const int dy = being->getTileY() - y; - distSq = dx*dx + dy*dy; - } - - if (specialDistance && being->getDistance() <= 2 - && being->getType() == type) + // see validateBeing for when real distance is valid + if (mTargetOnlyReachable && being->getType() == ActorType::Monster) { - continue; + const int d = being->getDistance(); + distSq = d*d; } //logger->log("being prio:%3d, dist^2:%3d, name: '%s'", -- cgit v1.2.3-70-g09d2