From 954ca26471dd0f78b0cb73cd6316cd1ec3fa16f5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 11 Feb 2025 00:50:21 +0100 Subject: [PATCH] Make sure the remaining chunks are notified of the changed world lights when adding / removing chunks. --- modules/terraman/world/terrain_world.cpp | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/terraman/world/terrain_world.cpp b/modules/terraman/world/terrain_world.cpp index 92a63c319..4e9e61105 100644 --- a/modules/terraman/world/terrain_world.cpp +++ b/modules/terraman/world/terrain_world.cpp @@ -291,6 +291,14 @@ void TerrainWorld::chunk_add(Ref chunk, const int x, const int z) chunk->enter_tree(); } + for (int i = 0; i < chunk->light_get_count(); ++i) { + Ref light = chunk->light_get_index(i); + + if (light.is_valid()) { + world_light_added(light); + } + } + if (has_method("_chunk_added")) { call("_chunk_added", chunk); } @@ -335,6 +343,14 @@ Ref TerrainWorld::chunk_remove(const int x, const int z) { chunk->cancel_build(); } + for (int i = 0; i < chunk->light_get_count(); ++i) { + Ref light = chunk->light_get_index(i); + + if (light.is_valid()) { + world_light_removed(light); + } + } + //never remove from this here //_generating.erase(chunk); @@ -358,6 +374,14 @@ Ref TerrainWorld::chunk_remove_index(const int index) { chunk->cancel_build(); } + for (int i = 0; i < chunk->light_get_count(); ++i) { + Ref light = chunk->light_get_index(i); + + if (light.is_valid()) { + world_light_removed(light); + } + } + //never remove from this here //_generating.erase(chunk); @@ -396,6 +420,8 @@ void TerrainWorld::chunks_clear() { } } + // Ignoring lights here should be fine + //never remove from this here //_generating.clear(); } @@ -487,6 +513,14 @@ void TerrainWorld::chunks_set(const Vector &chunks) { chunk->cancel_build(); } + for (int j = 0; j < chunk->light_get_count(); ++j) { + Ref light = chunk->light_get_index(j); + + if (light.is_valid()) { + world_light_removed(light); + } + } + //never remove from this here //_generating.erase(chunk);