diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 225a44bc6..6c7ffa1b2 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -870,7 +870,7 @@ void NavMap::sync() { _new_pm_polygon_count = polygons.size(); // Group all edges per key. - RBMap> connections; + HashMap, gd::EdgeKey> connections; for (uint32_t poly_id = 0; poly_id < polygons.size(); poly_id++) { gd::Polygon &poly(polygons[poly_id]); @@ -879,7 +879,7 @@ void NavMap::sync() { int next_point = (p + 1) % poly.points.size(); gd::EdgeKey ek(poly.points[p].key, poly.points[next_point].key); - RBMap>::Element *connection = connections.find(ek); + HashMap, gd::EdgeKey>::Element *connection = connections.find(ek); if (!connection) { connections[ek] = Vector(); @@ -894,7 +894,7 @@ void NavMap::sync() { new_connection.pathway_start = poly.points[p].pos; new_connection.pathway_end = poly.points[next_point].pos; connections[ek].push_back(new_connection); - + } else { // The edge is already connected with another edge, skip. ERR_PRINT_ONCE("Navigation map synchronization error. Attempted to merge a navigation mesh polygon edge with another already-merged edge. This is usually caused by crossing edges, overlapping polygons, or a mismatch of the NavigationMesh / NavigationPolygon baked 'cell_size' and navigation map 'cell_size'."); } @@ -902,7 +902,7 @@ void NavMap::sync() { } Vector free_edges; - for (RBMap>::Element *E = connections.front(); E; E = E->next()) { + for (HashMap, gd::EdgeKey>::Element *E = connections.front(); E; E = E->next) { if (E->get().size() == 2) { // Connect edge that are shared in different polygons. gd::Edge::Connection &c1 = E->get().write[0]; diff --git a/modules/navigation/nav_utils.h b/modules/navigation/nav_utils.h index ff52026a9..2ebda2161 100644 --- a/modules/navigation/nav_utils.h +++ b/modules/navigation/nav_utils.h @@ -30,8 +30,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/math/vector3.h" +#include "core/containers/hashfuncs.h" #include "core/containers/rid.h" +#include "core/math/vector3.h" class NavBase; @@ -52,10 +53,18 @@ struct EdgeKey { PointKey a; PointKey b; + static uint32_t hash(const EdgeKey &p_val) { + return hash_one_uint64(p_val.a.key) ^ hash_one_uint64(p_val.b.key); + } + bool operator<(const EdgeKey &p_key) const { return (a.key == p_key.a.key) ? (b.key < p_key.b.key) : (a.key < p_key.a.key); } + bool operator==(const EdgeKey &p_key) const { + return (a.key == p_key.a.key) && (b.key == p_key.b.key); + } + EdgeKey(const PointKey &p_a = PointKey(), const PointKey &p_b = PointKey()) : a(p_a), b(p_b) { @@ -142,8 +151,6 @@ struct NavigationPoly { poly = p_poly; back_navigation_poly_id = -1; - back_navigation_edge = UINT32_MAX; - back_navigation_edge = -1; traveled_distance = 0.0; }