From de3f60d3f40ff024e986686365239235fb52da94 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 3 Aug 2019 23:17:19 +0200 Subject: [PATCH] Added a new method to VoxelChunk. --- world/voxel_chunk.cpp | 23 +++++++++++++++++++++++ world/voxel_chunk.h | 1 + 2 files changed, 24 insertions(+) diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 15f4d1a..b58e6b9 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -271,6 +271,28 @@ void VoxelChunk::add_lights_into(Array target) { } } +void VoxelChunk::add_unique_lights_into(Array target) { + for (int i = 0; i < _voxel_lights.size(); ++i) { + Ref l = _voxel_lights.get(i); + + bool append = true; + for (int j = 0; j < target.size(); ++j) { + Ref l2 = target.get(j); + + if (!l2.is_valid()) + continue; + + if (l2->get_world_position() == l->get_world_position() && l2->get_size() == l->get_size()) { + append = false; + break; + } + } + + if (append) + target.append(l); + } +} + Array VoxelChunk::get_lights() { Array target; @@ -807,6 +829,7 @@ void VoxelChunk::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_voxel_light", "light"), &VoxelChunk::remove_voxel_light); ClassDB::bind_method(D_METHOD("clear_voxel_lights"), &VoxelChunk::clear_voxel_lights); ClassDB::bind_method(D_METHOD("add_lights_into", "lights"), &VoxelChunk::add_lights_into); + ClassDB::bind_method(D_METHOD("add_unique_lights_into", "lights"), &VoxelChunk::add_unique_lights_into); ClassDB::bind_method(D_METHOD("get_lights"), &VoxelChunk::get_lights); ClassDB::bind_method(D_METHOD("bake_lights"), &VoxelChunk::bake_lights); diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 33278f4..0b1ef98 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -96,6 +96,7 @@ public: void clear_voxel_lights(); void add_lights_into(Array target); + void add_unique_lights_into(Array target); Array get_lights(); void bake_lights();