aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-07 21:40:54 +0000
committernathan <nathansmith@disroot.org>2025-07-07 21:40:54 +0000
commit7701d6048ec3511250274504279fdd7a72954d43 (patch)
treed7eebee742f8e27068b81804f96696f10a370b10
parent4d1db458d366981fd65f221430145e6e83f094b5 (diff)
downloadFindThings-7701d6048ec3511250274504279fdd7a72954d43.tar.gz
FindThings-7701d6048ec3511250274504279fdd7a72954d43.tar.bz2
FindThings-7701d6048ec3511250274504279fdd7a72954d43.zip
Might not be the way forward tbh
-rw-r--r--src/world.c13
-rw-r--r--src/world.h6
2 files changed, 8 insertions, 11 deletions
diff --git a/src/world.c b/src/world.c
index 13a1c7e..02d6b9e 100644
--- a/src/world.c
+++ b/src/world.c
@@ -85,7 +85,6 @@ void buildWorldBVH(World* world)
{
Entity* entities = world->entities;
bool grouped[WORLD_ENTITY_MAX];
- BVHNode leafs[250];
// This is a mess thats not going to work.
for (int index = 0; index < WORLD_ENTITY_MAX; ++index)
@@ -95,15 +94,15 @@ void buildWorldBVH(World* world)
for (int leafIndex = 0; leafIndex < BVH_MAX; ++leafIndex)
{
- for (int nodeIndex = 0; nodeIndex < 250; ++nodeIndex)
+ for (int nodeIndex = 0; nodeIndex < BVH_LEAF_COUNT; ++nodeIndex)
{
- BVHNode* leaf = &leafs[nodeIndex];
+ BVHNode* leaf = &world->bvhTest[nodeIndex];
// First entity.
if (leafIndex == 0)
{
- leaf->entities[0] = nodeIndex * 4;
- grouped[nodeIndex * 4] = true;
+ leaf->entities[0] = nodeIndex * BVH_MAX;
+ grouped[nodeIndex * BVH_MAX] = true;
continue;
}
@@ -152,8 +151,6 @@ void buildWorldBVH(World* world)
leaf->box.max,
world->entities[leaf->entities[index]].position);
}
-
- world->bvhTest[nodeIndex] = leafs[nodeIndex];
}
}
}
@@ -215,7 +212,7 @@ void updateWorld(World* world, Game* game)
updateEntity(&world->entities[index], game);
}
- for (int index = 0; index < 250; ++index)
+ for (int index = 0; index < BVH_LEAF_COUNT; ++index)
{
Color colors[] = {RED, GREEN, BLUE, ORANGE, YELLOW, PINK};
DrawBoundingBox(world->bvhTest[index].box, colors[index % 6]);
diff --git a/src/world.h b/src/world.h
index d5c1a46..4bf5d79 100644
--- a/src/world.h
+++ b/src/world.h
@@ -7,8 +7,8 @@
#ifndef WORLD_H
#define WORLD_H
-// Max entities per node.
-#define BVH_MAX 4
+#define BVH_MAX 2 // Max entities per node.
+#define BVH_LEAF_COUNT 500
#define WORLD_ENTITY_MAX 1000
#define WORLD_SIZE (Vector3){1000.0, 100.0, 1000.0}
@@ -32,7 +32,7 @@ typedef struct {
Model heightmap;
Entity entities[WORLD_ENTITY_MAX];
BVHNode bvh;
- BVHNode bvhTest[250];
+ BVHNode bvhTest[BVH_LEAF_COUNT];
} World;
World createWorld(int seed);