From 73aed51ea25774cc9ab539d252bade4bd5b94c34 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 2 May 2021 19:23:07 +0100 Subject: [PATCH] Optimized 16-bit voxel box copies (used when meshing) --- storage/voxel_buffer.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/storage/voxel_buffer.cpp b/storage/voxel_buffer.cpp index a7cec18d..87699213 100644 --- a/storage/voxel_buffer.cpp +++ b/storage/voxel_buffer.cpp @@ -5,6 +5,8 @@ #endif #include "../edition/voxel_tool_buffer.h" +#include "../util/funcs.h" +#include "../util/profiling.h" #include "voxel_buffer.h" #include @@ -550,7 +552,20 @@ void VoxelBuffer::copy_from(const VoxelBuffer &other, Vector3i src_min, Vector3i } } + } else if (channel.depth == DEPTH_16_BIT) { + Vector3i pos; + for (pos.z = 0; pos.z < area_size.z; ++pos.z) { + for (pos.x = 0; pos.x < area_size.x; ++pos.x) { + const unsigned int src_ri = + 2 * other.get_index(pos.x + src_min.x, pos.y + src_min.y, pos.z + src_min.z); + const unsigned int dst_ri = + 2 * get_index(pos.x + dst_min.x, pos.y + dst_min.y, pos.z + dst_min.z); + memcpy(&channel.data[dst_ri], &other_channel.data[src_ri], area_size.y * sizeof(uint16_t)); + } + } + } else { + VOXEL_PROFILE_SCOPE(); // TODO Optimized versions Vector3i pos; for (pos.z = 0; pos.z < area_size.z; ++pos.z) { @@ -812,7 +827,6 @@ void VoxelBuffer::for_each_voxel_metadata_in_area(Ref callback, Rect3i // TODO Can't provide detailed error because FuncRef doesn't give us access to the object // ERR_FAIL_COND_MSG(err.error != Variant::CallError::CALL_OK, false, // Variant::get_call_error_text(callback->get_object(), method_name, nullptr, 0, err)); - } elem = elem->next(); }