aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-12 03:19:46 +0000
committernathan <nathansmith@disroot.org>2025-07-12 03:19:46 +0000
commit3b70a886ebff7f1aaa8cae47994b351ba6c8d7b5 (patch)
treee18ca4dfcb355ee7f1cb713a6ec2a46e99417354
parent47b7fa79e792339bf161a2877d2af10a885b255b (diff)
downloadFindThings-3b70a886ebff7f1aaa8cae47994b351ba6c8d7b5.tar.gz
FindThings-3b70a886ebff7f1aaa8cae47994b351ba6c8d7b5.tar.bz2
FindThings-3b70a886ebff7f1aaa8cae47994b351ba6c8d7b5.zip
UGGG
-rw-r--r--src/world.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/world.c b/src/world.c
index 098f15a..51f5692 100644
--- a/src/world.c
+++ b/src/world.c
@@ -157,10 +157,14 @@ size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world)
BVHNode buildWorldBVHTree(BVHNode* nodes, size_t nodesSize, const World* world)
{
BVHNode node;
- /* BVHNode usedNodes[nodesSize]; */
- /* size_t usedNodesSize = 0; */
+ int taken[BVH_MAX_BRANCH_COUNT];
memset(&node, 0, sizeof(BVHNode));
+ for (int index = 1; index < BVH_MAX_BRANCH_COUNT; ++index)
+ {
+ taken[index] = -1;
+ }
+
// Add first node to branch.
node.branches[0] = (BVHNode*)FT_MALLOC(sizeof(BVHNode));
@@ -171,6 +175,7 @@ BVHNode buildWorldBVHTree(BVHNode* nodes, size_t nodesSize, const World* world)
}
memcpy(node.branches[0], &nodes[0], sizeof(BVHNode));
+ taken[0] = 0;
node.branchCount = 1;
for (int branchIndex = 1; branchIndex < BVH_MAX_BRANCH_COUNT; ++branchIndex)
@@ -181,6 +186,22 @@ BVHNode buildWorldBVHTree(BVHNode* nodes, size_t nodesSize, const World* world)
// Find closest node.
for (int nodeIndex = 0; nodeIndex < nodesSize; ++nodeIndex)
{
+ bool alreadyUsed = false;
+
+ for (int index = 0; index < node.branchCount; ++index)
+ {
+ if (taken[index] == nodeIndex)
+ {
+ alreadyUsed = true;
+ break;
+ }
+ }
+
+ if (alreadyUsed)
+ {
+ continue;
+ }
+
float distance = 0.0;
BoundingBox box;
box = nodes[nodeIndex].box;
@@ -207,11 +228,7 @@ BVHNode buildWorldBVHTree(BVHNode* nodes, size_t nodesSize, const World* world)
}
}
- if (closest == -1)
- {
- node.branches[branchIndex] = NULL;
- }
- else
+ if (closest != -1)
{
node.branches[branchIndex] = (BVHNode*)FT_MALLOC(sizeof(BVHNode));
@@ -221,6 +238,7 @@ BVHNode buildWorldBVHTree(BVHNode* nodes, size_t nodesSize, const World* world)
}
memcpy(node.branches[branchIndex], &nodes[closest], sizeof(BVHNode));
+ ++node.branchCount;
}
}