From b248a28ccfaddbf2006fbf375556becb21ac60a8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 14 Feb 2025 18:02:32 +0100 Subject: [PATCH] More tweaks to TerrainChunk's new scene api. --- modules/terraman/world/terrain_chunk.cpp | 18 ++++++++++++++---- modules/terraman/world/terrain_chunk.h | 5 +++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/terraman/world/terrain_chunk.cpp b/modules/terraman/world/terrain_chunk.cpp index b6ac7076e..05a37163c 100644 --- a/modules/terraman/world/terrain_chunk.cpp +++ b/modules/terraman/world/terrain_chunk.cpp @@ -944,12 +944,22 @@ void TerrainChunk::scene_set_node(const int index, const Node *p_node) { int TerrainChunk::scene_get_count() const { return _scenes.size(); } -void TerrainChunk::scene_remove(const int index) { +void TerrainChunk::scene_remove(const int index, const bool p_queue_free) { ERR_FAIL_INDEX(index, _scenes.size()); + if (p_queue_free) { + scene_queue_free(index); + } + _scenes.remove(index); } -void TerrainChunk::scenes_clear() { +void TerrainChunk::scenes_clear(const bool p_queue_free) { + if (p_queue_free) { + for (int i = 0; i < _scenes.size(); ++i) { + scene_queue_free(i); + } + } + _scenes.clear(); } @@ -2077,8 +2087,8 @@ void TerrainChunk::_bind_methods() { ClassDB::bind_method(D_METHOD("scene_set_node", "index", "node"), &TerrainChunk::scene_set_node); ClassDB::bind_method(D_METHOD("scene_get_count"), &TerrainChunk::scene_get_count); - ClassDB::bind_method(D_METHOD("scene_remove", "index"), &TerrainChunk::scene_remove); - ClassDB::bind_method(D_METHOD("scenes_clear"), &TerrainChunk::scenes_clear); + ClassDB::bind_method(D_METHOD("scene_remove", "index", "queue_free"), &TerrainChunk::scene_remove, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("scenes_clear", "queue_free"), &TerrainChunk::scenes_clear, DEFVAL(true)); ClassDB::bind_method(D_METHOD("scene_instance", "index"), &TerrainChunk::scene_instance); ClassDB::bind_method(D_METHOD("scene_queue_free", "index"), &TerrainChunk::scene_queue_free); diff --git a/modules/terraman/world/terrain_chunk.h b/modules/terraman/world/terrain_chunk.h index 4f063eb02..748cc19fe 100644 --- a/modules/terraman/world/terrain_chunk.h +++ b/modules/terraman/world/terrain_chunk.h @@ -263,8 +263,9 @@ public: void scene_set_node(const int index, const Node *p_node); int scene_get_count() const; - void scene_remove(const int index); - void scenes_clear(); + + void scene_remove(const int index, const bool p_queue_free = true); + void scenes_clear(const bool p_queue_free = true); void scene_instance(const int index); void scene_queue_free(const int index);