aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
authornathan <nathan@disroot.org>2025-07-16 06:45:37 +0000
committernathan <nathan@disroot.org>2025-07-16 06:45:37 +0000
commit6641664d5218a6d9b4c120d539e7ac33d261ef99 (patch)
treed8dab25bb7f0f3a6bc30c3a95cf4f343a59fc147 /src/world.c
parentbd11b477c5dc81d343ae42b288ffb98e470226c4 (diff)
downloadFindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.tar.gz
FindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.tar.bz2
FindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.zip
WHYYYY
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/world.c b/src/world.c
index 8d69970..157f759 100644
--- a/src/world.c
+++ b/src/world.c
@@ -118,6 +118,7 @@ size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world)
}
leaf.position = Vector3Scale(Vector3Add(leaf.box.min, leaf.box.max), 0.5);
+ leaf.level = 0;
memset(leaf.branches, 0, BVH_MAX_BRANCH_COUNT * sizeof(BVHNode*));
leafs[leafsSize] = leaf;
@@ -217,6 +218,11 @@ BVHNode buildWorldBVHTree(BVHNode* leafs, size_t leafsSize,
for (int index = 0; index < nodesSize; ++index)
{
alreadyUsed = false;
+
+ if (nodes[index].level > node.level)
+ {
+ continue;
+ }
for (int innerBranch = 0; innerBranch < node.branchCount;
++innerBranch)
@@ -236,12 +242,7 @@ BVHNode buildWorldBVHTree(BVHNode* leafs, size_t leafsSize,
}
}
- if (overlaps)
- {
- distance *= 2.0;
- }
-
- if (distance < closestDistance)
+ if (!overlaps && distance < closestDistance)
{
closest = nodeIndex;
closestDistance = distance;
@@ -261,7 +262,15 @@ BVHNode buildWorldBVHTree(BVHNode* leafs, size_t leafsSize,
ALLOCATION_ERROR;
}
- memcpy(node.branches[node.branchCount], &nodes[closest], sizeof(BVHNode));
+ memcpy(node.branches[node.branchCount], &nodes[closest],
+ sizeof(BVHNode));
+
+ // Update level.
+ if (nodes[closest].level > node.level)
+ {
+ node.level = nodes[closest].level;
+ }
+
branches[node.branchCount] = closest;
++node.branchCount;
}
@@ -276,6 +285,7 @@ BVHNode buildWorldBVHTree(BVHNode* leafs, size_t leafsSize,
}
node.position = Vector3Scale(Vector3Add(node.box.min, node.box.max), 0.5);
+ ++node.level;
// Remove taken nodes.
nodes[branches[0]] = node;