Skip to content

Commit 11dcbd4

Browse files
committed
Merge pull request #108963 from groud/fix_debug_rendering_in_tilemaplayer
Fix debug rendering in TileMapLayer
2 parents 967e2d4 + 8637922 commit 11dcbd4

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

scene/2d/tile_map_layer.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
113113
}
114114
}
115115

116-
// Update those quadrants.
117-
bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated();
116+
// Create new quadrants if needed.
118117
for (const Vector2i &quadrant_coords : quadrants_to_updates) {
119118
if (!debug_quadrant_map.has(quadrant_coords)) {
120119
// Create a new quadrant and add it to the quadrant map.
@@ -123,7 +122,30 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
123122
new_quadrant->quadrant_coords = quadrant_coords;
124123
debug_quadrant_map[quadrant_coords] = new_quadrant;
125124
}
125+
}
126+
127+
// Second pass on modified cells to update the list of cells per quandrant.
128+
if (_debug_was_cleaned_up || anything_changed) {
129+
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
130+
CellData &cell_data = kv.value;
131+
Ref<DebugQuadrant> debug_quadrant = debug_quadrant_map[_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)];
132+
if (!cell_data.debug_quadrant_list_element.in_list()) {
133+
debug_quadrant->cells.add(&cell_data.debug_quadrant_list_element);
134+
}
135+
}
136+
} else {
137+
for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
138+
CellData &cell_data = *cell_data_list_element->self();
139+
Ref<DebugQuadrant> debug_quadrant = debug_quadrant_map[_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)];
140+
if (!cell_data.debug_quadrant_list_element.in_list()) {
141+
debug_quadrant->cells.add(&cell_data.debug_quadrant_list_element);
142+
}
143+
}
144+
}
126145

146+
// Update those quadrants.
147+
bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated();
148+
for (const Vector2i &quadrant_coords : quadrants_to_updates) {
127149
Ref<DebugQuadrant> debug_quadrant = debug_quadrant_map[quadrant_coords];
128150

129151
// Update the quadrant's canvas item.

scene/2d/tile_map_layer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct CellData {
105105
Vector2i coords;
106106
TileMapCell cell;
107107

108+
// Debug
109+
SelfList<CellData> debug_quadrant_list_element;
110+
108111
// Rendering.
109112
Ref<RenderingQuadrant> rendering_quadrant;
110113
SelfList<CellData> rendering_quadrant_list_element;
@@ -143,6 +146,7 @@ struct CellData {
143146
}
144147

145148
CellData(const CellData &p_other) :
149+
debug_quadrant_list_element(this),
146150
rendering_quadrant_list_element(this),
147151
#ifndef PHYSICS_2D_DISABLED
148152
physics_quadrant_list_element(this),
@@ -157,6 +161,7 @@ struct CellData {
157161
}
158162

159163
CellData() :
164+
debug_quadrant_list_element(this),
160165
rendering_quadrant_list_element(this),
161166
#ifndef PHYSICS_2D_DISABLED
162167
physics_quadrant_list_element(this),

0 commit comments

Comments
 (0)