From e853966be38ae6c5319df137c3b04a86e52b562b Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 11 Jan 2026 06:13:36 -0700 Subject: More inventory things --- src/world.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 0096dbe..b53fb57 100644 --- a/src/world.c +++ b/src/world.c @@ -1065,7 +1065,7 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, bool allowAll, { for (int index = 0; index < BVH_MAX; ++index) { - if (node.entities[index] != -1 && + if (node.entities[index] != ENTITY_NONE && GetRayCollisionBox( ray, world->entities[node.entities[index]].box).hit) @@ -1080,6 +1080,10 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, bool allowAll, { continue; } + else if (world->entities[node.entities[index]].id == ENTITY_NONE) + { + continue; + } if (distance < *closestDistance) { @@ -1108,4 +1112,57 @@ WorldUID castRayAtWorld(const World* world, Ray ray, bool allowAll, return uid; } +// This turned out to not be needed lol. +WorldUID checkBoxCollisionBVH(const World* world, BVHNode node, + BoundingBox box, bool allowAll) +{ + if (!CheckCollisionBoxes(box, node.box)) + { + return ENTITY_NONE; + } + + // Leaf node. + if (node.branchCount == 0) + { + for (int index = 0; index < BVH_MAX; ++index) + { + if (node.entities[index] != ENTITY_NONE && + CheckCollisionBoxes( + box, + world->entities[node.entities[index]].box)) + { + // Don't include things that can't be selected. + if (!allowAll && + !entityCanBeSelected(world->entities[node.entities[index]].id)) + { + continue; + } + + return node.entities[index]; + } + } + } + else // Subtree. + { + for (int index = 0; index < node.branchCount; ++index) + { + WorldUID uid = checkBoxCollisionBVH(world, *node.branches[index], box, + allowAll); + + if (uid != ENTITY_NONE) + { + return uid; + } + } + } + + return ENTITY_NONE; +} + +WorldUID checkBoxCollisionWithWorld(const World* world, BoundingBox box, + bool allowAll) +{ + return checkBoxCollisionBVH(world, world->bvh, box, allowAll); +} + // Abortions are good. Get more abortions. -- cgit v1.2.3