summaryrefslogtreecommitdiff
path: root/scene/2d/tile_map.h
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-05-13 15:04:37 +0200
committerRĂ©mi Verschelde <rverschelde@gmail.com>2022-05-16 10:37:48 +0200
commit746dddc0673d7261f19b1e056e90e6e3a49ef33a (patch)
tree434b526eb286850ebccc6d2c998a7d90fdb8b5e2 /scene/2d/tile_map.h
parent396def9b66c476f7834604adb7136ca903ed01be (diff)
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!
Diffstat (limited to 'scene/2d/tile_map.h')
-rw-r--r--scene/2d/tile_map.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index a0655dea2a..02a2b3a1c6 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -57,11 +57,11 @@ struct TileMapQuadrant {
Vector2i coords;
// TileMapCells
- Set<Vector2i> cells;
+ RBSet<Vector2i> cells;
// We need those two maps to sort by world position for rendering
// This is kind of workaround, it would be better to sort the cells directly in the "cells" set instead.
- Map<Vector2i, Vector2i> map_to_world;
- Map<Vector2i, Vector2i, CoordsWorldComparator> world_to_map;
+ RBMap<Vector2i, Vector2i> map_to_world;
+ RBMap<Vector2i, Vector2i, CoordsWorldComparator> world_to_map;
// Debug.
RID debug_canvas_item;
@@ -74,13 +74,13 @@ struct TileMapQuadrant {
List<RID> bodies;
// Navigation.
- Map<Vector2i, Vector<RID>> navigation_regions;
+ HashMap<Vector2i, Vector<RID>> navigation_regions;
// Scenes.
- Map<Vector2i, String> scenes;
+ HashMap<Vector2i, String> scenes;
// Runtime TileData cache.
- Map<Vector2i, TileData *> runtime_tile_data_cache;
+ HashMap<Vector2i, TileData *> runtime_tile_data_cache;
void operator=(const TileMapQuadrant &q) {
layer = q.layer;
@@ -135,7 +135,7 @@ public:
return base_cell_coords;
}
- Map<Vector2i, TileSet::CellNeighbor> get_overlapping_coords_and_peering_bits() const;
+ HashMap<Vector2i, TileSet::CellNeighbor> get_overlapping_coords_and_peering_bits() const;
void set_terrain(int p_terrain) {
terrain = p_terrain;
@@ -193,22 +193,22 @@ private:
int y_sort_origin = 0;
int z_index = 0;
RID canvas_item;
- Map<Vector2i, TileMapCell> tile_map;
- Map<Vector2i, TileMapQuadrant> quadrant_map;
+ HashMap<Vector2i, TileMapCell> tile_map;
+ HashMap<Vector2i, TileMapQuadrant> quadrant_map;
SelfList<TileMapQuadrant>::List dirty_quadrant_list;
};
LocalVector<TileMapLayer> layers;
int selected_layer = -1;
// Mapping for RID to coords.
- Map<RID, Vector2i> bodies_coords;
+ HashMap<RID, Vector2i> bodies_coords;
// Quadrants and internals management.
Vector2i _coords_to_quadrant_coords(int p_layer, const Vector2i &p_coords) const;
- Map<Vector2i, TileMapQuadrant>::Element *_create_quadrant(int p_layer, const Vector2i &p_qk);
+ HashMap<Vector2i, TileMapQuadrant>::Iterator _create_quadrant(int p_layer, const Vector2i &p_qk);
- void _make_quadrant_dirty(Map<Vector2i, TileMapQuadrant>::Element *Q);
+ void _make_quadrant_dirty(HashMap<Vector2i, TileMapQuadrant>::Iterator Q);
void _make_all_quadrants_dirty();
void _queue_update_dirty_quadrants();
@@ -217,7 +217,7 @@ private:
void _recreate_layer_internals(int p_layer);
void _recreate_internals();
- void _erase_quadrant(Map<Vector2i, TileMapQuadrant>::Element *Q);
+ void _erase_quadrant(HashMap<Vector2i, TileMapQuadrant>::Iterator Q);
void _clear_layer_internals(int p_layer);
void _clear_internals();
@@ -251,7 +251,7 @@ private:
void _scenes_draw_quadrant_debug(TileMapQuadrant *p_quadrant);
// Terrains.
- Set<TileSet::TerrainsPattern> _get_valid_terrains_patterns_for_constraints(int p_terrain_set, const Vector2i &p_position, Set<TerrainConstraint> p_constraints);
+ RBSet<TileSet::TerrainsPattern> _get_valid_terrains_patterns_for_constraints(int p_terrain_set, const Vector2i &p_position, RBSet<TerrainConstraint> p_constraints);
// Set and get tiles from data arrays.
void _set_tile_data(int p_layer, const Vector<int> &p_data);
@@ -333,14 +333,14 @@ public:
void set_pattern(int p_layer, Vector2i p_position, const Ref<TileMapPattern> p_pattern);
// Terrains.
- Set<TerrainConstraint> get_terrain_constraints_from_removed_cells_list(int p_layer, const Set<Vector2i> &p_to_replace, int p_terrain_set, bool p_ignore_empty_terrains = true) const; // Not exposed.
- Set<TerrainConstraint> get_terrain_constraints_from_added_tile(Vector2i p_position, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const; // Not exposed.
- Map<Vector2i, TileSet::TerrainsPattern> terrain_wave_function_collapse(const Set<Vector2i> &p_to_replace, int p_terrain_set, const Set<TerrainConstraint> p_constraints); // Not exposed.
+ RBSet<TerrainConstraint> get_terrain_constraints_from_removed_cells_list(int p_layer, const RBSet<Vector2i> &p_to_replace, int p_terrain_set, bool p_ignore_empty_terrains = true) const; // Not exposed.
+ RBSet<TerrainConstraint> get_terrain_constraints_from_added_tile(Vector2i p_position, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern) const; // Not exposed.
+ HashMap<Vector2i, TileSet::TerrainsPattern> terrain_wave_function_collapse(const RBSet<Vector2i> &p_to_replace, int p_terrain_set, const RBSet<TerrainConstraint> p_constraints); // Not exposed.
void set_cells_from_surrounding_terrains(int p_layer, TypedArray<Vector2i> p_coords_array, int p_terrain_set, bool p_ignore_empty_terrains = true);
// Not exposed to users
TileMapCell get_cell(int p_layer, const Vector2i &p_coords, bool p_use_proxies = false) const;
- Map<Vector2i, TileMapQuadrant> *get_quadrant_map(int p_layer);
+ HashMap<Vector2i, TileMapQuadrant> *get_quadrant_map(int p_layer);
int get_effective_quadrant_size(int p_layer) const;
//---
@@ -377,7 +377,7 @@ public:
// Helpers?
TypedArray<Vector2i> get_surrounding_tiles(Vector2i coords);
- void draw_cells_outline(Control *p_control, Set<Vector2i> p_cells, Color p_color, Transform2D p_transform = Transform2D());
+ void draw_cells_outline(Control *p_control, RBSet<Vector2i> p_cells, Color p_color, Transform2D p_transform = Transform2D());
// Virtual function to modify the TileData at runtime
GDVIRTUAL2R(bool, _use_tile_data_runtime_update, int, Vector2i);