summaryrefslogtreecommitdiffstats
path: root/modules/navigation
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2024-11-05 22:10:53 +0100
committersmix8 <52464204+smix8@users.noreply.github.com>2024-11-05 22:10:53 +0100
commitb840c9837aa5a8138ed4051ee167620f2be81e67 (patch)
tree8a2bbe09935691e35264bc9a2fe5365328b2dfb8 /modules/navigation
parentb00e1cbf743dcb6a2b7f6bd14e348a1a7cf3d403 (diff)
downloadredot-engine-b840c9837aa5a8138ed4051ee167620f2be81e67.tar.gz
Reduce allocations for NavMap synchronisation
Improves navigation map sync performance be avoiding unnecessary memory allocations.
Diffstat (limited to 'modules/navigation')
-rw-r--r--modules/navigation/3d/nav_mesh_queries_3d.cpp2
-rw-r--r--modules/navigation/nav_map.cpp9
-rw-r--r--modules/navigation/nav_map.h8
-rw-r--r--modules/navigation/nav_utils.h2
4 files changed, 12 insertions, 9 deletions
diff --git a/modules/navigation/3d/nav_mesh_queries_3d.cpp b/modules/navigation/3d/nav_mesh_queries_3d.cpp
index 70207f86ce..5acc598d43 100644
--- a/modules/navigation/3d/nav_mesh_queries_3d.cpp
+++ b/modules/navigation/3d/nav_mesh_queries_3d.cpp
@@ -234,7 +234,7 @@ Vector<Vector3> NavMeshQueries3D::polygons_get_path(const LocalVector<gd::Polygo
// Takes the current least_cost_poly neighbors (iterating over its edges) and compute the traveled_distance.
for (const gd::Edge &edge : navigation_polys[least_cost_id].poly->edges) {
// Iterate over connections in this edge, then compute the new optimized travel distance assigned to this polygon.
- for (int connection_index = 0; connection_index < edge.connections.size(); connection_index++) {
+ for (uint32_t connection_index = 0; connection_index < edge.connections.size(); connection_index++) {
const gd::Edge::Connection &connection = edge.connections[connection_index];
// Only consider the connection to another polygon if this polygon is in a region with compatible layers.
diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp
index 04c8a5a943..8055dd4bc8 100644
--- a/modules/navigation/nav_map.cpp
+++ b/modules/navigation/nav_map.cpp
@@ -426,13 +426,8 @@ void NavMap::sync() {
_new_pm_polygon_count = polygon_count;
- struct ConnectionPair {
- gd::Edge::Connection connections[2];
- int size = 0;
- };
-
// Group all edges per key.
- HashMap<gd::EdgeKey, ConnectionPair, gd::EdgeKey> connection_pairs_map;
+ connection_pairs_map.clear();
connection_pairs_map.reserve(polygons.size());
int free_edges_count = 0; // How many ConnectionPairs have only one Connection.
@@ -469,7 +464,7 @@ void NavMap::sync() {
}
}
- LocalVector<gd::Edge::Connection> free_edges;
+ free_edges.clear();
free_edges.reserve(free_edges_count);
for (const KeyValue<gd::EdgeKey, ConnectionPair> &pair_it : connection_pairs_map) {
diff --git a/modules/navigation/nav_map.h b/modules/navigation/nav_map.h
index b9120c04d9..3442b78497 100644
--- a/modules/navigation/nav_map.h
+++ b/modules/navigation/nav_map.h
@@ -128,6 +128,14 @@ class NavMap : public NavRid {
HashMap<NavRegion *, LocalVector<gd::Edge::Connection>> region_external_connections;
+ struct ConnectionPair {
+ gd::Edge::Connection connections[2];
+ int size = 0;
+ };
+
+ HashMap<gd::EdgeKey, ConnectionPair, gd::EdgeKey> connection_pairs_map;
+ LocalVector<gd::Edge::Connection> free_edges;
+
public:
NavMap();
~NavMap();
diff --git a/modules/navigation/nav_utils.h b/modules/navigation/nav_utils.h
index ba4c44b748..c466c82fc7 100644
--- a/modules/navigation/nav_utils.h
+++ b/modules/navigation/nav_utils.h
@@ -94,7 +94,7 @@ struct Edge {
};
/// Connections from this edge to other polygons.
- Vector<Connection> connections;
+ LocalVector<Connection> connections;
};
struct Polygon {