refactor: back some things into an order

This commit is contained in:
jeefo 2024-06-06 20:38:05 +03:00 committed by jeefo
commit 91073ddf5d
3 changed files with 9 additions and 10 deletions

View file

@ -264,7 +264,7 @@ public:
void syncCollectOnline (); void syncCollectOnline ();
void collectOnline (); 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); const IntArray &getNodesInBucket (const Vector &pos);
public: public:

View file

@ -493,12 +493,12 @@ int BotGraph::getForAnalyzer (const Vector &origin, const float maxRange) {
return index; 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 // find the nearest node to that origin and return the index
// fallback and go thru wall the nodes... // fallback and go thru wall the nodes...
int index = kInvalidNodeIndex; int index = kInvalidNodeIndex;
nearestDistanceSq = cr::sqrf (nearestDistanceSq); float nearestDistanceSq = cr::sqrf (range);
for (const auto &path : m_paths) { for (const auto &path : m_paths) {
if (flags != -1 && !(path.flags & flags)) { if (flags != -1 && !(path.flags & flags)) {
@ -555,15 +555,15 @@ int BotGraph::getNearest (const Vector &origin, const float range, int flags) {
return index; 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 // returns all nodes within radius from position
radiusSq = cr::sqrf (radiusSq); const float radiusSq = cr::sqrf (radius);
IntArray result {}; IntArray result {};
const auto &bucket = getNodesInBucket (origin); 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) { for (const auto &path : m_paths) {
if (maxCount != -1 && static_cast <int> (result.length ()) > maxCount) { if (maxCount != -1 && static_cast <int> (result.length ()) > maxCount) {
break; break;

View file

@ -1247,10 +1247,9 @@ bool Bot::updateNavigation () {
// needs precise placement - check if we get past the point // needs precise placement - check if we get past the point
if (desiredDistanceSq < cr::sqrf (22.0f) && nodeDistanceSq < cr::sqrf (30.0f)) { if (desiredDistanceSq < cr::sqrf (22.0f) && nodeDistanceSq < cr::sqrf (30.0f)) {
if (m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) >= nodeDistanceSq) { const auto predictRangeSq = m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval);
desiredDistanceSq = nodeDistanceSq + 1.0f;
} if (predictRangeSq >= nodeDistanceSq || predictRangeSq <= desiredDistanceSq) {
if (m_pathOrigin.distanceSq (pev->origin + pev->velocity * m_frameInterval) <= desiredDistanceSq) {
desiredDistanceSq = nodeDistanceSq + 1.0f; desiredDistanceSq = nodeDistanceSq + 1.0f;
} }
} }