diff options
author | nathan <nathan@disroot.org> | 2025-07-16 06:45:37 +0000 |
---|---|---|
committer | nathan <nathan@disroot.org> | 2025-07-16 06:45:37 +0000 |
commit | 6641664d5218a6d9b4c120d539e7ac33d261ef99 (patch) | |
tree | d8dab25bb7f0f3a6bc30c3a95cf4f343a59fc147 | |
parent | bd11b477c5dc81d343ae42b288ffb98e470226c4 (diff) | |
download | FindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.tar.gz FindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.tar.bz2 FindThings-6641664d5218a6d9b4c120d539e7ac33d261ef99.zip |
WHYYYY
-rw-r--r-- | src/world.c | 24 | ||||
-rw-r--r-- | src/world.h | 3 |
2 files changed, 19 insertions, 8 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; diff --git a/src/world.h b/src/world.h index 16e6dbf..3f167f8 100644 --- a/src/world.h +++ b/src/world.h @@ -21,11 +21,12 @@ typedef int16_t WorldUID; typedef struct BVHNode { + int8_t level; BoundingBox box; Vector3 position; WorldUID entities[BVH_MAX]; // Only for leafs. struct BVHNode* branches[BVH_MAX_BRANCH_COUNT]; - int branchCount; + int8_t branchCount; } BVHNode; typedef struct { |