You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated!
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "quick_hull.h"
|
||||
|
||||
#include "core/templates/map.h"
|
||||
#include "core/templates/rb_map.h"
|
||||
|
||||
uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF;
|
||||
|
||||
@@ -52,7 +52,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
|
||||
Vector<bool> valid_points;
|
||||
valid_points.resize(p_points.size());
|
||||
Set<Vector3> valid_cache;
|
||||
RBSet<Vector3> valid_cache;
|
||||
|
||||
for (int i = 0; i < p_points.size(); i++) {
|
||||
Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001));
|
||||
@@ -237,7 +237,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
//find lit faces and lit edges
|
||||
List<List<Face>::Element *> lit_faces; //lit face is a death sentence
|
||||
|
||||
Map<Edge, FaceConnect> lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot
|
||||
HashMap<Edge, FaceConnect, Edge> lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot
|
||||
|
||||
for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
|
||||
if (E->get().plane.distance_to(v) > 0) {
|
||||
@@ -248,15 +248,15 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
uint32_t b = E->get().vertices[(i + 1) % 3];
|
||||
Edge e(a, b);
|
||||
|
||||
Map<Edge, FaceConnect>::Element *F = lit_edges.find(e);
|
||||
HashMap<Edge, FaceConnect, Edge>::Iterator F = lit_edges.find(e);
|
||||
if (!F) {
|
||||
F = lit_edges.insert(e, FaceConnect());
|
||||
}
|
||||
if (e.vertices[0] == a) {
|
||||
//left
|
||||
F->get().left = E;
|
||||
F->value.left = E;
|
||||
} else {
|
||||
F->get().right = E;
|
||||
F->value.right = E;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
/* CREATE MESHDATA */
|
||||
|
||||
//make a map of edges again
|
||||
Map<Edge, RetFaceConnect> ret_edges;
|
||||
HashMap<Edge, RetFaceConnect, Edge> ret_edges;
|
||||
List<Geometry3D::MeshData::Face> ret_faces;
|
||||
|
||||
for (const Face &E : faces) {
|
||||
@@ -351,15 +351,15 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
uint32_t b = E.vertices[(i + 1) % 3];
|
||||
Edge e(a, b);
|
||||
|
||||
Map<Edge, RetFaceConnect>::Element *G = ret_edges.find(e);
|
||||
HashMap<Edge, RetFaceConnect, Edge>::Iterator G = ret_edges.find(e);
|
||||
if (!G) {
|
||||
G = ret_edges.insert(e, RetFaceConnect());
|
||||
}
|
||||
if (e.vertices[0] == a) {
|
||||
//left
|
||||
G->get().left = F;
|
||||
G->value.left = F;
|
||||
} else {
|
||||
G->get().right = F;
|
||||
G->value.right = F;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,10 +374,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
int b = E->get().indices[(i + 1) % f.indices.size()];
|
||||
Edge e(a, b);
|
||||
|
||||
Map<Edge, RetFaceConnect>::Element *F = ret_edges.find(e);
|
||||
HashMap<Edge, RetFaceConnect, Edge>::Iterator F = ret_edges.find(e);
|
||||
|
||||
ERR_CONTINUE(!F);
|
||||
List<Geometry3D::MeshData::Face>::Element *O = F->get().left == E ? F->get().right : F->get().left;
|
||||
List<Geometry3D::MeshData::Face>::Element *O = F->value.left == E ? F->value.right : F->value.left;
|
||||
ERR_CONTINUE(O == E);
|
||||
ERR_CONTINUE(O == nullptr);
|
||||
|
||||
@@ -401,13 +401,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
}
|
||||
Edge e2(idx, idxn);
|
||||
|
||||
Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2);
|
||||
HashMap<Edge, RetFaceConnect, Edge>::Iterator F2 = ret_edges.find(e2);
|
||||
ERR_CONTINUE(!F2);
|
||||
//change faceconnect, point to this face instead
|
||||
if (F2->get().left == O) {
|
||||
F2->get().left = E;
|
||||
} else if (F2->get().right == O) {
|
||||
F2->get().right = E;
|
||||
if (F2->value.left == O) {
|
||||
F2->value.left = E;
|
||||
} else if (F2->value.right == O) {
|
||||
F2->value.right = E;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
|
||||
}
|
||||
}
|
||||
|
||||
ret_edges.erase(F); //remove the edge
|
||||
ret_edges.remove(F); //remove the edge
|
||||
ret_faces.erase(O); //remove the face
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user