Skip to content

Commit

Permalink
refactor: back some things into an order
Browse files Browse the repository at this point in the history
  • Loading branch information
jeefo committed Jun 6, 2024
1 parent ece8373 commit 91073dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion inc/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class BotGraph final : public Singleton <BotGraph> {
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:
Expand Down
10 changes: 5 additions & 5 deletions src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 <int> (result.length ()) > maxCount) {
break;
Expand Down
7 changes: 3 additions & 4 deletions src/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 91073dd

Please sign in to comment.