[qfvis] Make cluster reconstruction O(N)

For most (if not all) maps. The heapsort is needed only if the clustered
leafs are not contiguous, but most bsp compilers output contiguous leaf
clusters, so is just a bit of protection. The difference isn't really
noticeable on a fast machine, but no point in doing more work than
necessary.
This commit is contained in:
Bill Currie 2021-08-06 13:47:56 +09:00
parent b320c3352f
commit 9a93bf8d4a
1 changed files with 14 additions and 5 deletions

View File

@ -260,16 +260,25 @@ static void
reconstruct_clusters (void)
{
leafvis = malloc (num_leafs * sizeof (leafvis_t));
int sorted = 1;
num_clusters = 1;
for (unsigned i = 0; i < num_leafs; i++) {
leafvis[i].visoffs = bsp->leafs[i + 1].visofs;
leafvis[i].leafnum = i;
if (i > 0) {
num_clusters += leafvis[i].visoffs != leafvis[i - 1].visoffs;
if (leafvis[i].visoffs < leafvis[i - 1].visoffs) {
sorted = 0;
}
}
}
if (!sorted) {
heapsort (leafvis, num_leafs, sizeof (leafvis_t), leaf_compare);
num_clusters = 1;
for (unsigned i = 1; i < num_leafs; i++) {
num_clusters += leafvis[i].visoffs != leafvis[i - 1].visoffs;
}
}
leafcluster = malloc (num_leafs * sizeof (uint32_t));
leafmap = calloc (num_clusters, sizeof (leafmap_t));