@@ -51,11 +51,11 @@ Vector2i TileMapLayer::_coords_to_debug_quadrant_coords(const Vector2i &p_coords
5151 p_coords.y > 0 ? p_coords.y / TILE_MAP_DEBUG_QUADRANT_SIZE : (p_coords.y - (TILE_MAP_DEBUG_QUADRANT_SIZE - 1 )) / TILE_MAP_DEBUG_QUADRANT_SIZE);
5252}
5353
54- void TileMapLayer::_debug_update () {
54+ void TileMapLayer::_debug_update (bool p_force_cleanup ) {
5555 RenderingServer *rs = RenderingServer::get_singleton ();
5656
5757 // Check if we should cleanup everything.
58- bool forced_cleanup = in_destructor || !enabled || tile_set.is_null () || !is_visible_in_tree ();
58+ bool forced_cleanup = p_force_cleanup || !enabled || tile_set.is_null () || !is_visible_in_tree ();
5959
6060 if (forced_cleanup) {
6161 for (KeyValue<Vector2i, Ref<DebugQuadrant>> &kv : debug_quadrant_map) {
@@ -178,11 +178,11 @@ void TileMapLayer::_debug_quadrants_update_cell(CellData &r_cell_data, SelfList<
178178#endif // DEBUG_ENABLED
179179
180180// ///////////////////////////// Rendering //////////////////////////////////////
181- void TileMapLayer::_rendering_update () {
181+ void TileMapLayer::_rendering_update (bool p_force_cleanup ) {
182182 RenderingServer *rs = RenderingServer::get_singleton ();
183183
184184 // Check if we should cleanup everything.
185- bool forced_cleanup = in_destructor || !enabled || tile_set.is_null () || !is_visible_in_tree ();
185+ bool forced_cleanup = p_force_cleanup || !enabled || tile_set.is_null () || !is_visible_in_tree ();
186186
187187 // ----------- Layer level processing -----------
188188 if (!forced_cleanup) {
@@ -673,9 +673,9 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
673673
674674// ///////////////////////////// Physics //////////////////////////////////////
675675
676- void TileMapLayer::_physics_update () {
676+ void TileMapLayer::_physics_update (bool p_force_cleanup ) {
677677 // Check if we should cleanup everything.
678- bool forced_cleanup = in_destructor || !enabled || !collision_enabled || !is_inside_tree () || tile_set.is_null ();
678+ bool forced_cleanup = p_force_cleanup || !enabled || !collision_enabled || !is_inside_tree () || tile_set.is_null ();
679679 if (forced_cleanup) {
680680 // Clean everything.
681681 for (KeyValue<Vector2i, CellData> &kv : tile_map_layer_data) {
@@ -923,12 +923,12 @@ void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vect
923923
924924// ///////////////////////////// Navigation //////////////////////////////////////
925925
926- void TileMapLayer::_navigation_update () {
926+ void TileMapLayer::_navigation_update (bool p_force_cleanup ) {
927927 ERR_FAIL_NULL (NavigationServer2D::get_singleton ());
928928 NavigationServer2D *ns = NavigationServer2D::get_singleton ();
929929
930930 // Check if we should cleanup everything.
931- bool forced_cleanup = in_destructor || !enabled || !navigation_enabled || !is_inside_tree () || tile_set.is_null ();
931+ bool forced_cleanup = p_force_cleanup || !enabled || !navigation_enabled || !is_inside_tree () || tile_set.is_null ();
932932
933933 // ----------- Layer level processing -----------
934934 // All this processing is kept for compatibility with the TileMap node.
@@ -1196,9 +1196,9 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V
11961196
11971197// ///////////////////////////// Scenes //////////////////////////////////////
11981198
1199- void TileMapLayer::_scenes_update () {
1199+ void TileMapLayer::_scenes_update (bool p_force_cleanup ) {
12001200 // Check if we should cleanup everything.
1201- bool forced_cleanup = in_destructor || !enabled || !is_inside_tree () || tile_set.is_null ();
1201+ bool forced_cleanup = p_force_cleanup || !enabled || !is_inside_tree () || tile_set.is_null ();
12021202
12031203 if (forced_cleanup) {
12041204 // Clean everything.
@@ -1329,9 +1329,9 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto
13291329
13301330// ///////////////////////////////////////////////////////////////////
13311331
1332- void TileMapLayer::_build_runtime_update_tile_data () {
1332+ void TileMapLayer::_build_runtime_update_tile_data (bool p_force_cleanup ) {
13331333 // Check if we should cleanup everything.
1334- bool forced_cleanup = in_destructor || !enabled || tile_set.is_null () || !is_visible_in_tree ();
1334+ bool forced_cleanup = p_force_cleanup || !enabled || tile_set.is_null () || !is_visible_in_tree ();
13351335 if (!forced_cleanup) {
13361336 bool valid_runtime_update = GDVIRTUAL_IS_OVERRIDDEN (_use_tile_data_runtime_update) && GDVIRTUAL_IS_OVERRIDDEN (_tile_data_runtime_update);
13371337 bool valid_runtime_update_for_tilemap = tile_map_node && tile_map_node->GDVIRTUAL_IS_OVERRIDDEN (_use_tile_data_runtime_update) && tile_map_node->GDVIRTUAL_IS_OVERRIDDEN (_tile_data_runtime_update); // For keeping compatibility.
@@ -1635,23 +1635,21 @@ void TileMapLayer::_deferred_internal_update() {
16351635 }
16361636
16371637 // Update dirty quadrants on layers.
1638- _internal_update ();
1639-
1640- pending_update = false ;
1638+ _internal_update (false );
16411639}
16421640
1643- void TileMapLayer::_internal_update () {
1641+ void TileMapLayer::_internal_update (bool p_force_cleanup ) {
16441642 // Find TileData that need a runtime modification.
16451643 // This may add cells to the dirty list if a runtime modification has been notified.
1646- _build_runtime_update_tile_data ();
1644+ _build_runtime_update_tile_data (p_force_cleanup );
16471645
16481646 // Update all subsystems.
1649- _rendering_update ();
1650- _physics_update ();
1651- _navigation_update ();
1652- _scenes_update ();
1647+ _rendering_update (p_force_cleanup );
1648+ _physics_update (p_force_cleanup );
1649+ _navigation_update (p_force_cleanup );
1650+ _scenes_update (p_force_cleanup );
16531651#ifdef DEBUG_ENABLED
1654- _debug_update ();
1652+ _debug_update (p_force_cleanup );
16551653#endif // DEBUG_ENABLED
16561654
16571655 _clear_runtime_update_tile_data ();
@@ -1678,6 +1676,8 @@ void TileMapLayer::_internal_update() {
16781676
16791677 // Clear the dirty cells list.
16801678 dirty.cell_list .clear ();
1679+
1680+ pending_update = false ;
16811681}
16821682
16831683void TileMapLayer::_notification (int p_what) {
@@ -1694,8 +1694,8 @@ void TileMapLayer::_notification(int p_what) {
16941694
16951695 case NOTIFICATION_EXIT_TREE: {
16961696 dirty.flags [DIRTY_FLAGS_LAYER_IN_TREE] = true ;
1697- // Update immediately on exiting.
1698- update_internals ( );
1697+ // Update immediately on exiting, and force cleanup .
1698+ _internal_update ( true );
16991699 } break ;
17001700
17011701 case TileMap::NOTIFICATION_ENTER_CANVAS: {
@@ -1705,8 +1705,8 @@ void TileMapLayer::_notification(int p_what) {
17051705
17061706 case TileMap::NOTIFICATION_EXIT_CANVAS: {
17071707 dirty.flags [DIRTY_FLAGS_LAYER_IN_CANVAS] = true ;
1708- // Update immediately on exiting.
1709- update_internals ( );
1708+ // Update immediately on exiting, and force cleanup .
1709+ _internal_update ( true );
17101710 } break ;
17111711
17121712 case TileMap::NOTIFICATION_VISIBILITY_CHANGED: {
@@ -2498,8 +2498,7 @@ Vector2i TileMapLayer::get_coords_for_body_rid(RID p_physics_body) const {
24982498}
24992499
25002500void TileMapLayer::update_internals () {
2501- pending_update = true ;
2502- _deferred_internal_update ();
2501+ _internal_update (false );
25032502}
25042503
25052504void TileMapLayer::notify_runtime_tile_data_update () {
@@ -2825,9 +2824,8 @@ TileMapLayer::TileMapLayer() {
28252824}
28262825
28272826TileMapLayer::~TileMapLayer () {
2828- in_destructor = true ;
28292827 clear ();
2830- _internal_update ();
2828+ _internal_update (true );
28312829}
28322830
28332831HashMap<Vector2i, TileSet::CellNeighbor> TerrainConstraint::get_overlapping_coords_and_peering_bits () const {
0 commit comments