aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-08 22:07:11 +0000
committernathan <nathansmith@disroot.org>2025-07-08 22:07:11 +0000
commit7c3eb38f22ec3cd951aa4af77d9b66a6d1973b46 (patch)
tree9c494c641e83b960c61111b08b66aeb744cdf6b6
parent7701d6048ec3511250274504279fdd7a72954d43 (diff)
downloadFindThings-7c3eb38f22ec3cd951aa4af77d9b66a6d1973b46.tar.gz
FindThings-7c3eb38f22ec3cd951aa4af77d9b66a6d1973b46.tar.bz2
FindThings-7c3eb38f22ec3cd951aa4af77d9b66a6d1973b46.zip
Still too much overlap. Time for a different method (:
-rw-r--r--src/world.c92
1 files changed, 11 insertions, 81 deletions
diff --git a/src/world.c b/src/world.c
index 02d6b9e..1958ffe 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,83 +1,6 @@
#include "world.h"
#include "game.h"
-/* int64_t hashWorldPosition(Vector3 position, Vector3 size) */
-/* { */
-/* return (((int64_t)position.x) << 32) | (((int64_t)position.z) << 16) */
-/* | ((int64_t)position.y); */
-/* } */
-
-/* void sortEntitiesUID(WorldUID entities[WORLD_ENTITY_MAX], const World* world) */
-/* { */
-/* // Lazy selection sort. */
-/* for (int outer = 0; outer < WORLD_ENTITY_MAX - 1; ++outer) */
-/* { */
-/* int minIndex = outer; */
-
-/* for (int inner = outer + 1; inner < WORLD_ENTITY_MAX; ++inner) */
-/* { */
-/* int64_t entityHash = hashWorldPosition( */
-/* world->entities[entities[inner]].position, world->size); */
-/* int64_t minHash = hashWorldPosition( */
-/* world->entities[entities[minIndex]].position, world->size); */
-
-/* if (entityHash < minHash) */
-/* { */
-/* minIndex = inner; */
-/* } */
-/* } */
-
-/* WorldUID temp = entities[outer]; */
-/* entities[outer] = entities[minIndex]; */
-/* entities[minIndex] = temp; */
-/* } */
-
-/* for (int index = 0; index < WORLD_ENTITY_MAX; ++index) */
-/* { */
-/* PRINT_VECTOR3(world->entities[entities[index]].position); */
-/* } */
-/* } */
-
-/* void buildWorldBVH(World* world) */
-/* { */
-/* WorldUID sorted[WORLD_ENTITY_MAX]; */
-
-/* for (int index = 0; index < WORLD_ENTITY_MAX; ++index) */
-/* { */
-/* sorted[index] = index; */
-/* } */
-
-/* sortEntitiesUID(sorted, world); */
-
-/* for (int index = 0; index < WORLD_ENTITY_MAX; index += BVH_MAX) */
-/* { */
-/* BVHNode leaf; */
-/* leaf.branch1 = NULL; */
-/* leaf.branch2 = NULL; */
-
-/* for (int leafIndex = 0; leafIndex < BVH_MAX; ++leafIndex) */
-/* { */
-/* leaf.entities[leafIndex] = sorted[index + leafIndex]; */
-/* } */
-
-/* // Create bounding box. */
-/* leaf.box.min = world->entities[leaf.entities[0]].position; */
-/* leaf.box.max = world->entities[leaf.entities[0]].position; */
-
-/* for (int index = 1; index < BVH_MAX; ++index) */
-/* { */
-/* leaf.box.min = Vector3Min( */
-/* leaf.box.min, */
-/* world->entities[leaf.entities[index]].position); */
-/* leaf.box.max = Vector3Max( */
-/* leaf.box.max, */
-/* world->entities[leaf.entities[index]].position); */
-/* } */
-
-/* world->bvhTest[index / 4] = leaf; */
-/* } */
-/* } */
-
// Bottom up method because bottom up better. Just if politicians agreed ):
// z curve broky, last metho was decent but was first come first serve and
// would leave leafs toward the end with shitty options and end up being big.
@@ -117,10 +40,17 @@ void buildWorldBVH(World* world)
{
continue;
}
-
- float distance = Vector3Distance(
- entities[leaf->entities[0]].position,
- entities[index].position);
+
+ float distance = 0.0;
+
+ for (int innerIndex = 0; innerIndex < leafIndex; ++innerIndex)
+ {
+ distance += Vector3Distance(
+ entities[leaf->entities[innerIndex]].position,
+ entities[index].position);
+ }
+
+ distance /= (float)leafIndex;
if (distance < closestDistance)
{