From 91073ddf5d4eaf0d7ec748c9b80bbd7519bdd458 Mon Sep 17 00:00:00 2001 From: jeefo Date: Thu, 6 Jun 2024 20:38:05 +0300 Subject: [PATCH] refactor: back some things into an order --- inc/graph.h | 2 +- src/graph.cpp | 10 +++++----- src/navigate.cpp | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/inc/graph.h b/inc/graph.h index 28d5d49..f2d16d6 100644 --- a/inc/graph.h +++ b/inc/graph.h @@ -264,7 +264,7 @@ public: void syncCollectOnline (); void collectOnline (); - IntArray getNearestInRadius (float radiusSq, const Vector &origin, int maxCount = -1); + IntArray getNearestInRadius (float radius, const Vector &origin, int maxCount = -1); const IntArray &getNodesInBucket (const Vector &pos); public: diff --git a/src/graph.cpp b/src/graph.cpp index bb40aad..cee9ba1 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -493,12 +493,12 @@ int BotGraph::getForAnalyzer (const Vector &origin, const float maxRange) { return index; } -int BotGraph::getNearestNoBuckets (const Vector &origin, float nearestDistanceSq, int flags) { +int BotGraph::getNearestNoBuckets (const Vector &origin, const float range, int flags) { // find the nearest node to that origin and return the index // fallback and go thru wall the nodes... int index = kInvalidNodeIndex; - nearestDistanceSq = cr::sqrf (nearestDistanceSq); + float nearestDistanceSq = cr::sqrf (range); for (const auto &path : m_paths) { if (flags != -1 && !(path.flags & flags)) { @@ -555,15 +555,15 @@ int BotGraph::getNearest (const Vector &origin, const float range, int flags) { return index; } -IntArray BotGraph::getNearestInRadius (float radiusSq, const Vector &origin, int maxCount) { +IntArray BotGraph::getNearestInRadius (float radius, const Vector &origin, int maxCount) { // returns all nodes within radius from position - radiusSq = cr::sqrf (radiusSq); + const float radiusSq = cr::sqrf (radius); IntArray result {}; const auto &bucket = getNodesInBucket (origin); - if (bucket.length () < kMaxNodeLinks || radiusSq > cr::sqrf (256.0f)) { + if (bucket.length () < kMaxNodeLinks || radius > cr::sqrf (256.0f)) { for (const auto &path : m_paths) { if (maxCount != -1 && static_cast (result.length ()) > maxCount) { break; diff --git a/src/navigate.cpp b/src/navigate.cpp index d29657f..e629a10 100644 --- a/src/navigate.cpp +++ b/src/navigate.cpp @@ -1247,10 +1247,9 @@ bool Bot::updateNavigation () { // needs precise placement - check if we get past the point if (desiredDistanceSq < cr::sqrf (22.0f) && nodeDistanceSq < cr::sqrf (30.0f)) { - if (m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) >= nodeDistanceSq) { - desiredDistanceSq = nodeDistanceSq + 1.0f; - } - if (m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) <= desiredDistanceSq) { + const auto predictRangeSq = m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval); + + if (predictRangeSq >= nodeDistanceSq || predictRangeSq <= desiredDistanceSq) { desiredDistanceSq = nodeDistanceSq + 1.0f; } }