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:
reduz
2022-05-13 15:04:37 +02:00
committed by Rémi Verschelde
parent 396def9b66
commit 746dddc067
587 changed files with 3707 additions and 3538 deletions

View File

@@ -56,9 +56,15 @@ class GridMap : public Node3D {
};
uint64_t key = 0;
static uint32_t hash(const IndexKey &p_key) {
return hash_one_uint64(p_key.key);
}
_FORCE_INLINE_ bool operator<(const IndexKey &p_key) const {
return key < p_key.key;
}
_FORCE_INLINE_ bool operator==(const IndexKey &p_key) const {
return key == p_key.key;
}
_FORCE_INLINE_ operator Vector3i() const {
return Vector3i(x, y, z);
@@ -107,13 +113,13 @@ class GridMap : public Node3D {
};
Vector<MultimeshInstance> multimesh_instances;
Set<IndexKey> cells;
RBSet<IndexKey> cells;
RID collision_debug;
RID collision_debug_instance;
bool dirty = false;
RID static_body;
Map<IndexKey, NavMesh> navmesh_ids;
HashMap<IndexKey, NavMesh> navmesh_ids;
};
union OctantKey {
@@ -126,8 +132,11 @@ class GridMap : public Node3D {
uint64_t key = 0;
_FORCE_INLINE_ bool operator<(const OctantKey &p_key) const {
return key < p_key.key;
static uint32_t hash(const OctantKey &p_key) {
return hash_one_uint64(p_key.key);
}
_FORCE_INLINE_ bool operator==(const OctantKey &p_key) const {
return key == p_key.key;
}
//OctantKey(const IndexKey& p_k, int p_item) { indexkey=p_k.key; item=p_item; }
@@ -154,8 +163,8 @@ class GridMap : public Node3D {
Ref<MeshLibrary> mesh_library;
Map<OctantKey, Octant *> octant_map;
Map<IndexKey, Cell> cell_map;
HashMap<OctantKey, Octant *, OctantKey> octant_map;
HashMap<IndexKey, Cell, IndexKey> cell_map;
void _recreate_octant_data();