mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03: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:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user