diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index add18f490c9..160733c2d93 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -113,8 +113,7 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) { } } - // Update those quadrants. - bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated(); + // Create new quadrants if needed. for (const Vector2i &quadrant_coords : quadrants_to_updates) { if (!debug_quadrant_map.has(quadrant_coords)) { // Create a new quadrant and add it to the quadrant map. @@ -123,7 +122,30 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) { new_quadrant->quadrant_coords = quadrant_coords; debug_quadrant_map[quadrant_coords] = new_quadrant; } + } + // Second pass on modified cells to update the list of cells per quandrant. + if (_debug_was_cleaned_up || anything_changed) { + for (KeyValue &kv : tile_map_layer_data) { + CellData &cell_data = kv.value; + Ref debug_quadrant = debug_quadrant_map[_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)]; + if (!cell_data.debug_quadrant_list_element.in_list()) { + debug_quadrant->cells.add(&cell_data.debug_quadrant_list_element); + } + } + } else { + for (SelfList *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) { + CellData &cell_data = *cell_data_list_element->self(); + Ref debug_quadrant = debug_quadrant_map[_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)]; + if (!cell_data.debug_quadrant_list_element.in_list()) { + debug_quadrant->cells.add(&cell_data.debug_quadrant_list_element); + } + } + } + + // Update those quadrants. + bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated(); + for (const Vector2i &quadrant_coords : quadrants_to_updates) { Ref debug_quadrant = debug_quadrant_map[quadrant_coords]; // Update the quadrant's canvas item. diff --git a/scene/2d/tile_map_layer.h b/scene/2d/tile_map_layer.h index 7bca54d5cbe..10194b79b27 100644 --- a/scene/2d/tile_map_layer.h +++ b/scene/2d/tile_map_layer.h @@ -105,6 +105,9 @@ struct CellData { Vector2i coords; TileMapCell cell; + // Debug + SelfList debug_quadrant_list_element; + // Rendering. Ref rendering_quadrant; SelfList rendering_quadrant_list_element; @@ -143,6 +146,7 @@ struct CellData { } CellData(const CellData &p_other) : + debug_quadrant_list_element(this), rendering_quadrant_list_element(this), #ifndef PHYSICS_2D_DISABLED physics_quadrant_list_element(this), @@ -157,6 +161,7 @@ struct CellData { } CellData() : + debug_quadrant_list_element(this), rendering_quadrant_list_element(this), #ifndef PHYSICS_2D_DISABLED physics_quadrant_list_element(this),