From 4819292821b51083538d4d4880e90d0d3314f839 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 8 Jul 2025 21:23:05 -0600 Subject: Making BVN faster --- src/world.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/world.c b/src/world.c index e670d6f..c633e44 100644 --- a/src/world.c +++ b/src/world.c @@ -6,13 +6,10 @@ void buildWorldBVH(World* world) { Entity* entities = world->entities; bool grouped[WORLD_ENTITY_MAX]; + WorldUID groupedList[WORLD_ENTITY_MAX]; + int groupedListSize = 0; int ungroupedCount = WORLD_ENTITY_MAX; - - // This is a mess thats not going to work. - for (int index = 0; index < WORLD_ENTITY_MAX; ++index) - { - grouped[index] = false; - } + memset(grouped, 0, sizeof(grouped)); world->bvhTestSize = 0; @@ -62,14 +59,10 @@ void buildWorldBVH(World* world) bool overlaps = false; // Check if overlap will be caused. - for (int overlapIndex = 0; overlapIndex < WORLD_ENTITY_MAX; - ++overlapIndex) + for (int groupedIndex = 0; groupedIndex < groupedListSize; + ++groupedIndex) { - if (!grouped[overlapIndex]) - { - continue; - } - + int overlapIndex = groupedList[groupedIndex]; bool isPartOf = false; for (int partOfIndex = 0; partOfIndex < leafIndex + 1; ++partOfIndex) @@ -111,6 +104,8 @@ void buildWorldBVH(World* world) { leaf.entities[leafIndex] = closest; grouped[closest] = true; + groupedList[groupedListSize] = closest; + ++groupedListSize; --ungroupedCount; } } -- cgit v1.2.3