Improve TileMap Y-sorting performance

This commit is contained in:
Gilles Roudière
2023-09-18 16:30:06 +02:00
parent 787259441a
commit 30b94bb8ab
4 changed files with 166 additions and 63 deletions

View File

@ -121,6 +121,10 @@ struct CellData {
// List elements.
SelfList<CellData> dirty_list_element;
bool operator<(const CellData &p_other) const {
return coords < p_other.coords;
}
// For those, copy everything but SelfList elements.
void operator=(const CellData &p_other) {
coords = p_other.coords;
@ -152,6 +156,13 @@ struct CellData {
}
};
// For compatibility reasons, we use another comparator for Y-sorted layers.
struct CellDataYSortedComparator {
_FORCE_INLINE_ bool operator()(const CellData &p_a, const CellData &p_b) const {
return p_a.coords.x == p_b.coords.x ? (p_a.coords.y < p_b.coords.y) : (p_a.coords.x > p_b.coords.x);
}
};
#ifdef DEBUG_ENABLED
class DebugQuadrant : public RefCounted {
GDCLASS(DebugQuadrant, RefCounted);
@ -199,6 +210,7 @@ public:
Vector2i quadrant_coords;
SelfList<CellData>::List cells;
List<RID> canvas_items;
Vector2 canvas_items_position;
SelfList<RenderingQuadrant> dirty_quadrant_list_element;
@ -304,7 +316,6 @@ private:
#endif // DEBUG_ENABLED
HashMap<Vector2i, Ref<RenderingQuadrant>> rendering_quadrant_map;
Vector2i _coords_to_rendering_quadrant_coords(const Vector2i &p_coords) const;
bool _rendering_was_cleaned_up = false;
void _rendering_update();
void _rendering_quadrants_update_cell(CellData &r_cell_data, SelfList<RenderingQuadrant>::List &r_dirty_rendering_quadrant_list);
@ -361,7 +372,6 @@ public:
// Not exposed to users.
TileMapCell get_cell(const Vector2i &p_coords, bool p_use_proxies = false) const;
int get_effective_quadrant_size() const;
// For TileMap node's use.
void set_tile_data(DataFormat p_format, const Vector<int> &p_data);
@ -455,6 +465,8 @@ private:
void _tile_set_changed();
void _update_notify_local_transform();
// Polygons.
HashMap<Pair<Ref<Resource>, int>, Ref<Resource>, PairHash<Ref<Resource>, int>> polygon_cache;
PackedVector2Array _get_transformed_vertices(const PackedVector2Array &p_vertices, int p_alternative_id);