mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-12-22 01:26:50 +01:00
Sort thread updates only when necessary
This commit is contained in:
parent
e79dd98d69
commit
bca6a72edd
@ -20,6 +20,8 @@ VoxelMeshUpdater::VoxelMeshUpdater(Ref<VoxelLibrary> 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<VoxelMeshUpdater::InputBlock, BlockUpdateComparator> sorter;
|
||||
|
@ -70,6 +70,8 @@ private:
|
||||
private:
|
||||
Input _shared_input;
|
||||
Mutex *_input_mutex;
|
||||
HashMap<Vector3i, int, Vector3iHasher> _block_indexes;
|
||||
bool _needs_sort;
|
||||
|
||||
Output _shared_output;
|
||||
Mutex *_output_mutex;
|
||||
@ -78,7 +80,6 @@ private:
|
||||
Ref<VoxelMesherSmooth> _smooth_mesher;
|
||||
|
||||
Input _input;
|
||||
HashMap<Vector3i, int, Vector3iHasher> _block_indexes;
|
||||
Output _output;
|
||||
Semaphore *_semaphore;
|
||||
Thread *_thread;
|
||||
|
Loading…
Reference in New Issue
Block a user