Fix block processors' sorting function

This commit is contained in:
Marc Gilleron 2019-05-12 16:19:08 +01:00
parent 1065aa40ef
commit 8126d732b6
2 changed files with 17 additions and 5 deletions

View File

@ -247,9 +247,16 @@ void VoxelMeshUpdater::process_block(const InputBlock &block, OutputBlock &outpu
// Sorts distance to viewer
// The closest block will be the first one in the array
struct BlockUpdateComparator {
Vector3i center;
Vector3i center; // In LOD0 block coordinates
inline bool operator()(const VoxelMeshUpdater::InputBlock &a, const VoxelMeshUpdater::InputBlock &b) const {
return a.position.distance_sq(center) < b.position.distance_sq(center);
if (a.lod == b.lod) {
int da = (a.position * (1 << a.lod)).distance_sq(center);
int db = (b.position * (1 << b.lod)).distance_sq(center);
return da < db;
} else {
// Load highest lods first because they are needed for the octree to subdivide
return a.lod > b.lod;
}
}
};

View File

@ -153,9 +153,14 @@ struct BlockPositionComparator {
// In LOD0 block coordinates
Vector3i center;
inline bool operator()(const VoxelProviderThread::EmergeInput &a, const VoxelProviderThread::EmergeInput &b) const {
int da = (a.block_position * (1 << a.lod)).distance_sq(center);
int db = (b.block_position * (1 << b.lod)).distance_sq(center);
return da < db;
if (a.lod == b.lod) {
int da = (a.block_position * (1 << a.lod)).distance_sq(center);
int db = (b.block_position * (1 << b.lod)).distance_sq(center);
return da < db;
} else {
// Load highest lods first because they are needed for the octree to subdivide
return a.lod > b.lod;
}
}
};