Skip to content

Commit

Permalink
Change navigation map performance monitor to use a struct
Browse files Browse the repository at this point in the history
Changes navigation map performance monitor to use a struct as it is easier to pass to sub functions.
  • Loading branch information
smix8 committed Nov 24, 2024
1 parent 0c45ace commit 37c3907
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 49 deletions.
45 changes: 14 additions & 31 deletions modules/navigation/nav_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,10 @@ Vector3 NavMap::get_random_point(uint32_t p_navigation_layers, bool p_uniformly)
void NavMap::sync() {
RWLockWrite write_lock(map_rwlock);

// Performance Monitor
int _new_pm_region_count = regions.size();
int _new_pm_agent_count = agents.size();
int _new_pm_link_count = links.size();
int _new_pm_polygon_count = pm_polygon_count;
int _new_pm_edge_count = pm_edge_count;
int _new_pm_edge_merge_count = pm_edge_merge_count;
int _new_pm_edge_connection_count = pm_edge_connection_count;
int _new_pm_edge_free_count = pm_edge_free_count;
int _new_pm_obstacle_count = obstacles.size();
performance_data.pm_region_count = regions.size();
performance_data.pm_agent_count = agents.size();
performance_data.pm_link_count = links.size();
performance_data.pm_obstacle_count = obstacles.size();

// Check if we need to update the links.
if (regenerate_polygons) {
Expand All @@ -388,11 +382,11 @@ void NavMap::sync() {
}

if (regenerate_links) {
_new_pm_polygon_count = 0;
_new_pm_edge_count = 0;
_new_pm_edge_merge_count = 0;
_new_pm_edge_connection_count = 0;
_new_pm_edge_free_count = 0;
performance_data.pm_polygon_count = 0;
performance_data.pm_edge_count = 0;
performance_data.pm_edge_merge_count = 0;
performance_data.pm_edge_connection_count = 0;
performance_data.pm_edge_free_count = 0;

// Remove regions connections.
region_external_connections.clear();
Expand Down Expand Up @@ -424,7 +418,7 @@ void NavMap::sync() {
}
}

_new_pm_polygon_count = polygon_count;
performance_data.pm_polygon_count = polygon_count;

// Group all edges per key.
connection_pairs_map.clear();
Expand All @@ -439,7 +433,7 @@ void NavMap::sync() {
HashMap<gd::EdgeKey, ConnectionPair, gd::EdgeKey>::Iterator pair_it = connection_pairs_map.find(ek);
if (!pair_it) {
pair_it = connection_pairs_map.insert(ek, ConnectionPair());
_new_pm_edge_count += 1;
performance_data.pm_edge_count += 1;
++free_edges_count;
}
ConnectionPair &pair = pair_it->value;
Expand Down Expand Up @@ -476,7 +470,7 @@ void NavMap::sync() {
c1.polygon->edges[c1.edge].connections.push_back(c2);
c2.polygon->edges[c2.edge].connections.push_back(c1);
// Note: The pathway_start/end are full for those connection and do not need to be modified.
_new_pm_edge_merge_count += 1;
performance_data.pm_edge_merge_count += 1;
} else {
CRASH_COND_MSG(pair.size != 1, vformat("Number of connection != 1. Found: %d", pair.size));
if (use_edge_connections && pair.connections[0].polygon->owner->get_use_edge_connections()) {
Expand All @@ -492,7 +486,7 @@ void NavMap::sync() {
// to be connected, create new polygons to remove that small gap is
// not really useful and would result in wasteful computation during
// connection, integration and path finding.
_new_pm_edge_free_count = free_edges.size();
performance_data.pm_edge_free_count = free_edges.size();

const real_t edge_connection_margin_squared = edge_connection_margin * edge_connection_margin;

Expand Down Expand Up @@ -549,7 +543,7 @@ void NavMap::sync() {

// Add the connection to the region_connection map.
region_external_connections[(NavRegion *)free_edge.polygon->owner].push_back(new_connection);
_new_pm_edge_connection_count += 1;
performance_data.pm_edge_connection_count += 1;
}
}

Expand Down Expand Up @@ -687,17 +681,6 @@ void NavMap::sync() {
regenerate_links = false;
obstacles_dirty = false;
agents_dirty = false;

// Performance Monitor.
pm_region_count = _new_pm_region_count;
pm_agent_count = _new_pm_agent_count;
pm_link_count = _new_pm_link_count;
pm_polygon_count = _new_pm_polygon_count;
pm_edge_count = _new_pm_edge_count;
pm_edge_merge_count = _new_pm_edge_merge_count;
pm_edge_connection_count = _new_pm_edge_connection_count;
pm_edge_free_count = _new_pm_edge_free_count;
pm_obstacle_count = _new_pm_obstacle_count;
}

void NavMap::_update_rvo_obstacles_tree_2d() {
Expand Down
28 changes: 10 additions & 18 deletions modules/navigation/nav_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,7 @@ class NavMap : public NavRid {
bool avoidance_use_high_priority_threads = true;

// Performance Monitor
int pm_region_count = 0;
int pm_agent_count = 0;
int pm_link_count = 0;
int pm_polygon_count = 0;
int pm_edge_count = 0;
int pm_edge_merge_count = 0;
int pm_edge_connection_count = 0;
int pm_edge_free_count = 0;
int pm_obstacle_count = 0;
gd::PerformanceData performance_data;

HashMap<NavRegion *, LocalVector<gd::Edge::Connection>> region_external_connections;

Expand Down Expand Up @@ -220,15 +212,15 @@ class NavMap : public NavRid {
void dispatch_callbacks();

// Performance Monitor
int get_pm_region_count() const { return pm_region_count; }
int get_pm_agent_count() const { return pm_agent_count; }
int get_pm_link_count() const { return pm_link_count; }
int get_pm_polygon_count() const { return pm_polygon_count; }
int get_pm_edge_count() const { return pm_edge_count; }
int get_pm_edge_merge_count() const { return pm_edge_merge_count; }
int get_pm_edge_connection_count() const { return pm_edge_connection_count; }
int get_pm_edge_free_count() const { return pm_edge_free_count; }
int get_pm_obstacle_count() const { return pm_obstacle_count; }
int get_pm_region_count() const { return performance_data.pm_region_count; }
int get_pm_agent_count() const { return performance_data.pm_agent_count; }
int get_pm_link_count() const { return performance_data.pm_link_count; }
int get_pm_polygon_count() const { return performance_data.pm_polygon_count; }
int get_pm_edge_count() const { return performance_data.pm_edge_count; }
int get_pm_edge_merge_count() const { return performance_data.pm_edge_merge_count; }
int get_pm_edge_connection_count() const { return performance_data.pm_edge_connection_count; }
int get_pm_edge_free_count() const { return performance_data.pm_edge_free_count; }
int get_pm_obstacle_count() const { return performance_data.pm_obstacle_count; }

int get_region_connections_count(NavRegion *p_region) const;
Vector3 get_region_connection_pathway_start(NavRegion *p_region, int p_connection_id) const;
Expand Down
13 changes: 13 additions & 0 deletions modules/navigation/nav_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ class Heap {
}
}
};

struct PerformanceData {
int pm_region_count = 0;
int pm_agent_count = 0;
int pm_link_count = 0;
int pm_polygon_count = 0;
int pm_edge_count = 0;
int pm_edge_merge_count = 0;
int pm_edge_connection_count = 0;
int pm_edge_free_count = 0;
int pm_obstacle_count = 0;
};

} // namespace gd

#endif // NAV_UTILS_H

0 comments on commit 37c3907

Please sign in to comment.