Fix logic in NavMap::sync().

This commit is contained in:
Relintai 2023-09-04 22:00:26 +02:00
parent 1e5f9895e7
commit 73c1f1f673
2 changed files with 14 additions and 7 deletions

View File

@ -870,7 +870,7 @@ void NavMap::sync() {
_new_pm_polygon_count = polygons.size();
// Group all edges per key.
RBMap<gd::EdgeKey, Vector<gd::Edge::Connection>> connections;
HashMap<gd::EdgeKey, Vector<gd::Edge::Connection>, 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<gd::EdgeKey, Vector<gd::Edge::Connection>>::Element *connection = connections.find(ek);
HashMap<gd::EdgeKey, Vector<gd::Edge::Connection>, gd::EdgeKey>::Element *connection = connections.find(ek);
if (!connection) {
connections[ek] = Vector<gd::Edge::Connection>();
@ -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<gd::Edge::Connection> free_edges;
for (RBMap<gd::EdgeKey, Vector<gd::Edge::Connection>>::Element *E = connections.front(); E; E = E->next()) {
for (HashMap<gd::EdgeKey, Vector<gd::Edge::Connection>, 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];

View File

@ -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;
}