aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathan@disroot.org>2025-07-09 07:31:19 +0000
committernathan <nathan@disroot.org>2025-07-09 07:31:19 +0000
commit6bd4182fbed898ad68c6b425707bbd2c5ef1e115 (patch)
treed7ba8786ee3a079df4f0c905459cc29de38468be
parent97b16e669943025d367c2022a148026f338cf7f0 (diff)
downloadFindThings-6bd4182fbed898ad68c6b425707bbd2c5ef1e115.tar.gz
FindThings-6bd4182fbed898ad68c6b425707bbd2c5ef1e115.tar.bz2
FindThings-6bd4182fbed898ad68c6b425707bbd2c5ef1e115.zip
Going to move on to the next part of BVH
-rw-r--r--src/world.c41
-rw-r--r--src/world.h6
2 files changed, 27 insertions, 20 deletions
diff --git a/src/world.c b/src/world.c
index 5719c3c..14f7ed7 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,23 +1,20 @@
#include "world.h"
#include "game.h"
-// Very messy right now. Mostly been playing around.
-void buildWorldBVH(World* world)
+size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world)
{
- Entity* entities = world->entities;
+ size_t leafsSize = 0;
+ const Entity* entities = world->entities;
bool grouped[WORLD_ENTITY_MAX];
WorldUID groupedList[WORLD_ENTITY_MAX];
int ungroupedCount = WORLD_ENTITY_MAX;
-
+
for (int index = 0; index < WORLD_ENTITY_MAX; ++index)
{
grouped[index] = false;
groupedList[index] = index;
}
- world->bvhTestSize = 0;
-
- // This is going to be slow. Optimizjl;dsfz lajtklers (:
while (ungroupedCount > 0)
{
BVHNode leaf;
@@ -138,11 +135,11 @@ void buildWorldBVH(World* world)
world->entities[leaf.entities[index]].position);
}
- world->bvhTest[world->bvhTestSize] = leaf;
- ++world->bvhTestSize;
+ leafs[leafsSize] = leaf;
+ ++leafsSize;
}
- // test
+ // test
for (int index = 0; index < WORLD_ENTITY_MAX; ++index)
{
if (!grouped[index])
@@ -151,7 +148,19 @@ void buildWorldBVH(World* world)
}
}
- printf("size: %d\n", world->bvhTestSize);
+ printf("size: %ld\n", leafsSize);
+
+ return leafsSize;
+}
+
+// Very messy right now. Mostly been playing around.
+void buildWorldBVH(World* world)
+{
+ Entity* entities = world->entities;
+
+ // Get leafs
+ BVHNode leafs[WORLD_ENTITY_MAX];
+ size_t leafsSize = buildWorldBVHLeafs(leafs, world);
}
World createWorld(int seed)
@@ -204,11 +213,11 @@ void updateWorld(World* world, Game* game)
}
// Draw BVH leafs.
- for (int index = 0; index < world->bvhTestSize; ++index)
- {
- Color colors[] = {RED, GREEN, BLUE, ORANGE, YELLOW, PINK};
- DrawBoundingBox(world->bvhTest[index].box, colors[index % 6]);
- }
+ /* for (int index = 0; index < world->bvhTestSize; ++index) */
+ /* { */
+ /* Color colors[] = {RED, GREEN, BLUE, ORANGE, YELLOW, PINK}; */
+ /* DrawBoundingBox(world->bvhTest[index].box, colors[index % 6]); */
+ /* } */
}
void freeWorld(World world)
diff --git a/src/world.h b/src/world.h
index 69c2015..1840af3 100644
--- a/src/world.h
+++ b/src/world.h
@@ -10,6 +10,7 @@
#define BVH_MAX 4 // Max entities per node.
#define BVH_LEAF_COUNT 250
#define BVH_OVERLAP_MULTIPLIER 100.0
+#define BVH_MAX_BRANCH_COUNT 3
#define WORLD_ENTITY_MAX 1000
#define WORLD_SIZE (Vector3){1000.0, 100.0, 1000.0}
@@ -23,8 +24,7 @@ typedef int16_t WorldUID;
typedef struct BVHNode {
BoundingBox box;
WorldUID entities[BVH_MAX]; // Only for leafs.
- struct BVHNode* branch1;
- struct BVHNode* branch2;
+ struct BVHNode* branches[BVH_MAX_BRANCH_COUNT];
} BVHNode;
typedef struct {
@@ -33,8 +33,6 @@ typedef struct {
Model heightmap;
Entity entities[WORLD_ENTITY_MAX];
BVHNode bvh;
- BVHNode bvhTest[WORLD_ENTITY_MAX];
- int bvhTestSize;
} World;
World createWorld(int seed);