summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2025-03-22 01:01:26 +0100
committerFedja Beader <fedja@protonmail.ch>2025-03-22 01:05:17 +0100
commit57efa1ec52af28386242767f9a68abb6836a1811 (patch)
treebfc6a36fd5758ddbedeb6bd39b82a18c1e1ff4f5
parent6722d5773bb9cb71bec870b214b4f34bbe6d0b08 (diff)
downloadmanaplus-57efa1ec52af28386242767f9a68abb6836a1811.tar.gz
manaplus-57efa1ec52af28386242767f9a68abb6836a1811.tar.bz2
manaplus-57efa1ec52af28386242767f9a68abb6836a1811.tar.xz
manaplus-57efa1ec52af28386242767f9a68abb6836a1811.zip
Cleanup findNearestLivingBeing: search priorityMobsMap at most once per being (down from 3x)
Note: the filter used priorityMobs (instead of priorityMobsMap). The former seems to be the std::set variant of the latter, but I can't find where either are filled. It does work in practice, however...
-rw-r--r--src/actormanager.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index d30ddbc3a..674239da0 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -1305,6 +1305,7 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
}
Being *const being = static_cast<Being*>(*i);
+ int priority = defaultPriorityIndex;
if (filtered)
{
// Skip ignored
@@ -1313,11 +1314,18 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
{
continue;
}
+
+ const StringIntMapCIter prioIter
+ = priorityMobsMap.find(being->getName());
+
+ if (prioIter != priorityMobsMap.end())
+ priority = prioIter->second;
+
// if (default) is in ignore list, then only attack
// those in priority or general attack list.
if (ignoreDefault
&& attackMobs.find(being->getName()) == attackMobs.end()
- && priorityMobs.find(being->getName()) == priorityMobs.end())
+ && prioIter == priorityMobsMap.end())
{
continue;
}
@@ -1349,9 +1357,8 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
continue;
}
-// logger->log("being name:" + being->getName());
-// logger->log("index:" + toString(index));
-// logger->log("d:" + toString(d));
+ //logger->log("being prio:%3d, dist^2:%3d, name: '%s'",
+ // priority, distSq, being->getName().c_str());
if (!filtered)
{
@@ -1363,20 +1370,14 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
}
else
{
- int w2 = defaultPriorityIndex;
if (closestBeing != nullptr)
{
- const StringIntMapCIter it2 = priorityMobsMap.find(
- being->getName());
- if (it2 != priorityMobsMap.end())
- w2 = (*it2).second;
-
- if ((w2 < closestPriority && distSq <= maxDistSq) ||
- (w2 == closestPriority && distSq < closestDistSq))
+ if ((priority < closestPriority && distSq <= maxDistSq) ||
+ (priority == closestPriority && distSq < closestDistSq))
{
closestBeing = being;
closestDistSq = distSq;
- closestPriority = w2;
+ closestPriority = priority;
continue;
}
}
@@ -1385,12 +1386,7 @@ Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing,
{
closestBeing = being;
closestDistSq = distSq;
- const StringIntMapCIter it1 = priorityMobsMap.find(
- being->getName());
- if (it1 != priorityMobsMap.end())
- closestPriority = it1->second;
- else
- closestPriority = defaultPriorityIndex;
+ closestPriority = priority;
}
}
}