Skip to content

Commit

Permalink
Don't force-cleanup already cleaned up TileMap cells
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Aug 23, 2024
1 parent a1acd38 commit a207a88
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions scene/2d/tile_map_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
(is_y_sort_enabled() && (dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] || dirty.flags[DIRTY_FLAGS_LAYER_X_DRAW_ORDER_REVERSED] || dirty.flags[DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM])) ||
(!is_y_sort_enabled() && dirty.flags[DIRTY_FLAGS_LAYER_RENDERING_QUADRANT_SIZE]);

bool quadrants_were_cleaned_up = false;
// Free all quadrants.
if (forced_cleanup || quadrant_shape_changed) {
for (const KeyValue<Vector2i, Ref<RenderingQuadrant>> &kv : rendering_quadrant_map) {
Expand All @@ -224,12 +225,12 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
kv.value->cells.clear();
}
rendering_quadrant_map.clear();
_rendering_was_cleaned_up = true;
quadrants_were_cleaned_up = true;
}

if (!forced_cleanup) {
// List all quadrants to update, recreating them if needed.
if (dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || _rendering_was_cleaned_up) {
if (dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || _rendering_was_cleaned_up || quadrants_were_cleaned_up) {
// Update all cells.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
CellData &cell_data = kv.value;
Expand Down Expand Up @@ -412,9 +413,11 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {

// ----------- Occluders processing -----------
if (forced_cleanup) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_rendering_occluders_clear_cell(kv.value);
if (!_rendering_was_cleaned_up) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_rendering_occluders_clear_cell(kv.value);
}
}
} else {
if (_rendering_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET]) {
Expand Down Expand Up @@ -688,9 +691,11 @@ void TileMapLayer::_physics_update(bool p_force_cleanup) {
// Check if we should cleanup everything.
bool forced_cleanup = p_force_cleanup || !enabled || !collision_enabled || !is_inside_tree() || tile_set.is_null();
if (forced_cleanup) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_physics_clear_cell(kv.value);
if (!_physics_was_cleaned_up) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_physics_clear_cell(kv.value);
}
}
} else {
if (_physics_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
Expand Down Expand Up @@ -967,9 +972,11 @@ void TileMapLayer::_navigation_update(bool p_force_cleanup) {

// ----------- Navigation regions processing -----------
if (forced_cleanup) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_navigation_clear_cell(kv.value);
if (!_navigation_was_cleaned_up) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_navigation_clear_cell(kv.value);
}
}
} else {
if (_navigation_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || dirty.flags[DIRTY_FLAGS_LAYER_NAVIGATION_MAP]) {
Expand Down Expand Up @@ -1212,9 +1219,11 @@ void TileMapLayer::_scenes_update(bool p_force_cleanup) {
bool forced_cleanup = p_force_cleanup || !enabled || !is_inside_tree() || tile_set.is_null();

if (forced_cleanup) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_scenes_clear_cell(kv.value);
if (!_scenes_was_cleaned_up) {
// Clean everything.
for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
_scenes_clear_cell(kv.value);
}
}
} else {
if (_scenes_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
Expand Down

0 comments on commit a207a88

Please sign in to comment.