Merge pull request #67330 from KoBeWi/immortal_scenes
Don't free instanced scenes when recreating tiles
This commit is contained in:
@ -1859,18 +1859,29 @@ void TileMap::_scenes_update_dirty_quadrants(SelfList<TileMapQuadrant>::List &r_
|
|||||||
while (q_list_element) {
|
while (q_list_element) {
|
||||||
TileMapQuadrant &q = *q_list_element->self();
|
TileMapQuadrant &q = *q_list_element->self();
|
||||||
|
|
||||||
// Clear the scenes.
|
// Clear the scenes if instance cache was cleared.
|
||||||
|
if (instantiated_scenes.is_empty()) {
|
||||||
for (const KeyValue<Vector2i, String> &E : q.scenes) {
|
for (const KeyValue<Vector2i, String> &E : q.scenes) {
|
||||||
Node *node = get_node_or_null(E.value);
|
Node *node = get_node_or_null(E.value);
|
||||||
if (node) {
|
if (node) {
|
||||||
node->queue_free();
|
node->queue_free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
q.scenes.clear();
|
q.scenes.clear();
|
||||||
|
|
||||||
// Recreate the scenes.
|
// Recreate the scenes.
|
||||||
for (const Vector2i &E_cell : q.cells) {
|
for (const Vector2i &E_cell : q.cells) {
|
||||||
|
Vector3i cell_coords = Vector3i(q.layer, E_cell.x, E_cell.y);
|
||||||
|
if (instantiated_scenes.has(cell_coords)) {
|
||||||
|
// Skip scene if the instance was cached (to avoid recreating scenes unnecessarily).
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
||||||
|
instantiated_scenes.insert(cell_coords);
|
||||||
|
}
|
||||||
|
|
||||||
const TileMapCell &c = get_cell(q.layer, E_cell, true);
|
const TileMapCell &c = get_cell(q.layer, E_cell, true);
|
||||||
|
|
||||||
TileSetSource *source;
|
TileSetSource *source;
|
||||||
@ -1907,16 +1918,17 @@ void TileMap::_scenes_update_dirty_quadrants(SelfList<TileMapQuadrant>::List &r_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TileMap::_scenes_cleanup_quadrant(TileMapQuadrant *p_quadrant) {
|
void TileMap::_scenes_cleanup_quadrant(TileMapQuadrant *p_quadrant) {
|
||||||
// Clear the scenes.
|
// Clear the scenes if instance cache was cleared.
|
||||||
|
if (instantiated_scenes.is_empty()) {
|
||||||
for (const KeyValue<Vector2i, String> &E : p_quadrant->scenes) {
|
for (const KeyValue<Vector2i, String> &E : p_quadrant->scenes) {
|
||||||
Node *node = get_node_or_null(E.value);
|
Node *node = get_node_or_null(E.value);
|
||||||
if (node) {
|
if (node) {
|
||||||
node->queue_free();
|
node->queue_free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p_quadrant->scenes.clear();
|
p_quadrant->scenes.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TileMap::_scenes_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
|
void TileMap::_scenes_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
|
||||||
ERR_FAIL_COND(!tile_set.is_valid());
|
ERR_FAIL_COND(!tile_set.is_valid());
|
||||||
@ -4037,6 +4049,7 @@ void TileMap::_bind_methods() {
|
|||||||
void TileMap::_tile_set_changed() {
|
void TileMap::_tile_set_changed() {
|
||||||
emit_signal(SNAME("changed"));
|
emit_signal(SNAME("changed"));
|
||||||
_tile_set_changed_deferred_update_needed = true;
|
_tile_set_changed_deferred_update_needed = true;
|
||||||
|
instantiated_scenes.clear();
|
||||||
call_deferred(SNAME("_tile_set_changed_deferred_update"));
|
call_deferred(SNAME("_tile_set_changed_deferred_update"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -236,6 +236,8 @@ private:
|
|||||||
void _clear_layer_internals(int p_layer);
|
void _clear_layer_internals(int p_layer);
|
||||||
void _clear_internals();
|
void _clear_internals();
|
||||||
|
|
||||||
|
HashSet<Vector3i> instantiated_scenes;
|
||||||
|
|
||||||
// Rect caching.
|
// Rect caching.
|
||||||
void _recompute_rect_cache();
|
void _recompute_rect_cache();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user