summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2024-11-24 13:19:33 +0100
committersmix8 <52464204+smix8@users.noreply.github.com>2024-11-24 13:27:45 +0100
commit37c3907d0e093632e142a494c0e405263f9c9c34 (patch)
tree43fcafb171bd39d45a82767bbe3e35d72de182ba /modules
parent0c45ace151f25de2ca54fe7a46b6f077be32ba6f (diff)
downloadredot-engine-37c3907d0e093632e142a494c0e405263f9c9c34.tar.gz
Change navigation map performance monitor to use a struct
Changes navigation map performance monitor to use a struct as it is easier to pass to sub functions.
Diffstat (limited to 'modules')
-rw-r--r--modules/navigation/nav_map.cpp45
-rw-r--r--modules/navigation/nav_map.h28
-rw-r--r--modules/navigation/nav_utils.h13
3 files changed, 37 insertions, 49 deletions
diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp
index 8055dd4bc8..d7b5ab87c5 100644
--- a/modules/navigation/nav_map.cpp
+++ b/modules/navigation/nav_map.cpp
@@ -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) {
@@ -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();
@@ -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();
@@ -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;
@@ -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()) {
@@ -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;
@@ -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;
}
}
@@ -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() {
diff --git a/modules/navigation/nav_map.h b/modules/navigation/nav_map.h
index 3442b78497..7eaf2133b9 100644
--- a/modules/navigation/nav_map.h
+++ b/modules/navigation/nav_map.h
@@ -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;
@@ -220,15 +212,15 @@ public:
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;
diff --git a/modules/navigation/nav_utils.h b/modules/navigation/nav_utils.h
index c466c82fc7..993a97638d 100644
--- a/modules/navigation/nav_utils.h
+++ b/modules/navigation/nav_utils.h
@@ -298,6 +298,19 @@ private:
}
}
};
+
+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