From 520c1515ed52cce3fc09c8e808f0bf8c76d90c80 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 18 Nov 2019 02:23:22 +0100 Subject: [PATCH] Check if towner is in range first This dramatically reduces the CPU spend finding towners --- SourceX/controls/plrctrls.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SourceX/controls/plrctrls.cpp b/SourceX/controls/plrctrls.cpp index e9010ab69..b547d2083 100644 --- a/SourceX/controls/plrctrls.cpp +++ b/SourceX/controls/plrctrls.cpp @@ -120,8 +120,10 @@ void FindItemOrObject() void CheckTownersNearby() { for (int i = 0; i < 16; i++) { + if (GetDistanceRanged(towner[i]._tx, towner[i]._ty) > 6) + continue; int distance = GetDistance(towner[i]._tx, towner[i]._ty); - if (distance == 0 || distance > 6) + if (distance == 0 || distance > 2) continue; pcursmonst = i; } @@ -132,10 +134,10 @@ bool HasRangedSpell() int v = plr[myplr]._pRSpell; return v != SPL_INVALID - && v != SPL_TOWN - && v != SPL_TELEPORT - && spelldata[v].sTargeted - && !spelldata[v].sTownSpell; + && v != SPL_TOWN + && v != SPL_TELEPORT + && spelldata[v].sTargeted + && !spelldata[v].sTownSpell; } void CheckMonstersNearby()