diff options
author | nathan <nathan@disroot.org> | 2025-07-17 05:06:22 +0000 |
---|---|---|
committer | nathan <nathan@disroot.org> | 2025-07-17 05:06:22 +0000 |
commit | 19d6df5e710cfeec0408062f408e5ec3f447339c (patch) | |
tree | 7c952a0259cfb5f3d47282f6e3984e7361e99e17 | |
parent | ebc52f2a55c848b2915e5191757ea2790c0377f1 (diff) | |
download | FindThings-19d6df5e710cfeec0408062f408e5ec3f447339c.tar.gz FindThings-19d6df5e710cfeec0408062f408e5ec3f447339c.tar.bz2 FindThings-19d6df5e710cfeec0408062f408e5ec3f447339c.zip |
A tiny bit better
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/world.c | 56 | ||||
-rw-r--r-- | src/world.h | 2 |
3 files changed, 33 insertions, 27 deletions
diff --git a/src/Makefile b/src/Makefile index 0a01fd7..5088644 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -Isrc -I../include -std=c99 +CFLAGS = -I../include -std=c99 LDFLAGS = -lm -lraylib TARGET = FindThings diff --git a/src/world.c b/src/world.c index b4c21ae..37aa818 100644 --- a/src/world.c +++ b/src/world.c @@ -156,7 +156,7 @@ size_t buildWorldBVHSubtree(BVHNode* subtree, const BVHNode* nodes, size_t nodesSize, const World* world) { - size_t nodeCount = 0; + size_t subtreeSize = 0; bool grouped[nodesSize]; int ungroupedCount = nodesSize; memset(grouped, 0, sizeof(grouped)); @@ -170,7 +170,7 @@ size_t buildWorldBVHSubtree(BVHNode* subtree, ++branchIndex) { int closest = -1; - float closestDistance = world->size.x; + float closestDistance = Vector3LengthSqr(world->size); // Find closest. for (int index = 0; index < nodesSize; ++index) @@ -209,21 +209,20 @@ size_t buildWorldBVHSubtree(BVHNode* subtree, bool overlaps = false; // Too big (will count it as a overlap). - if (Vector3Distance(overlapBox.min, overlapBox.max) >= BVH_BOX_MAX) - { - overlaps = true; - } - - // Check if overlap is already happening. - for (int nodeIndex = 0; nodeIndex < nodesSize && !overlaps; - ++nodeIndex) - { - if (CheckCollisionBoxes(overlapBox, nodes[nodeIndex].box)) - { - overlaps = true; - break; - } - } + /* if (Vector3Distance(overlapBox.min, overlapBox.max) >= BVH_BOX_MAX) */ + /* { */ + /* overlaps = true; */ + /* } */ + + // Check for overlap. + /* for (int nodeIndex = 0; nodeIndex < nodesSize; ++nodeIndex) */ + /* { */ + /* if (CheckCollisionBoxes(overlapBox, nodes[nodeIndex].box)) */ + /* { */ + /* overlaps = true; */ + /* break; */ + /* } */ + /* } */ // Update distance. if (!overlaps && distance < closestDistance) @@ -235,9 +234,10 @@ size_t buildWorldBVHSubtree(BVHNode* subtree, if (closest == -1) { - continue; + break; } + // Add closest as a branch. node.branches[node.branchCount] = (BVHNode*)FT_MALLOC(sizeof(BVHNode)); if (node.branches[node.branchCount] == NULL) @@ -265,11 +265,11 @@ size_t buildWorldBVHSubtree(BVHNode* subtree, node.position = Vector3Scale(Vector3Add(node.box.min, node.box.max), 0.5); - subtree[nodeCount] = node; - ++nodeCount; + subtree[subtreeSize] = node; + ++subtreeSize; } - return nodeCount; + return subtreeSize; } void buildWorldBVH(World* world) @@ -277,9 +277,17 @@ void buildWorldBVH(World* world) Entity* entities = world->entities; // Get leafs. - BVHNode leafs[WORLD_ENTITY_MAX]; - size_t leafsSize = buildWorldBVHLeafs(leafs, world); - // world->bvh = buildWorldBVHTree(leafs, leafsSize, world); + BVHNode tree[WORLD_ENTITY_MAX]; + size_t treeSize = buildWorldBVHLeafs(tree, world); + + while (treeSize > 1) + { + BVHNode subtree[treeSize]; + treeSize = buildWorldBVHSubtree(subtree, tree, treeSize, world); + memcpy(tree, subtree, treeSize * sizeof(BVHNode)); + } + + world->bvh = tree[0]; world->bvhDebugSelect = 0; } diff --git a/src/world.h b/src/world.h index ada9fa1..21f5aec 100644 --- a/src/world.h +++ b/src/world.h @@ -2,8 +2,6 @@ #include "assets.h" #include "entity.h" -// This file is likely completely change. - #ifndef WORLD_H #define WORLD_H |