diff --git a/voxel_mesh_updater.cpp b/voxel_mesh_updater.cpp index 1b314da..d01e5fa 100644 --- a/voxel_mesh_updater.cpp +++ b/voxel_mesh_updater.cpp @@ -20,6 +20,8 @@ VoxelMeshUpdater::VoxelMeshUpdater(Ref library, MeshingParams para _thread_exit = false; _semaphore = Semaphore::create(); _thread = Thread::create(_thread_func, this); + + _needs_sort = true; } VoxelMeshUpdater::~VoxelMeshUpdater() { @@ -75,6 +77,10 @@ void VoxelMeshUpdater::push(const Input &input) { } } + if(_shared_input.priority_position != input.priority_position || input.blocks.size() > 0) { + _needs_sort = true; + } + _shared_input.priority_position = input.priority_position; should_run = !_shared_input.is_empty(); } @@ -202,6 +208,7 @@ void VoxelMeshUpdater::thread_sync(int queue_index, Stats stats) { } stats.remaining_blocks = _input.blocks.size(); + bool needs_sort; { // Get input @@ -212,6 +219,9 @@ void VoxelMeshUpdater::thread_sync(int queue_index, Stats stats) { _shared_input.blocks.clear(); _block_indexes.clear(); + + needs_sort = _needs_sort; + _needs_sort = false; } if(!_output.blocks.empty()) { @@ -226,7 +236,7 @@ void VoxelMeshUpdater::thread_sync(int queue_index, Stats stats) { _output.blocks.clear(); } - if (!_input.blocks.empty()) { + if (!_input.blocks.empty() && needs_sort) { // Re-sort priority SortArray sorter; diff --git a/voxel_mesh_updater.h b/voxel_mesh_updater.h index 463a3b8..72760e6 100644 --- a/voxel_mesh_updater.h +++ b/voxel_mesh_updater.h @@ -70,6 +70,8 @@ private: private: Input _shared_input; Mutex *_input_mutex; + HashMap _block_indexes; + bool _needs_sort; Output _shared_output; Mutex *_output_mutex; @@ -78,7 +80,6 @@ private: Ref _smooth_mesher; Input _input; - HashMap _block_indexes; Output _output; Semaphore *_semaphore; Thread *_thread;