mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 13:12:42 +00:00
Reduce allocations for NavMap synchronisation
Improves navigation map sync performance be avoiding unnecessary memory allocations.
This commit is contained in:
parent
b00e1cbf74
commit
b840c9837a
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -94,7 +94,7 @@ struct Edge {
|
||||
};
|
||||
|
||||
/// Connections from this edge to other polygons.
|
||||
Vector<Connection> connections;
|
||||
LocalVector<Connection> connections;
|
||||
};
|
||||
|
||||
struct Polygon {
|
||||
|
Loading…
Reference in New Issue
Block a user