aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-10-25 05:24:51 +0000
committernathan <nathansmith@disroot.org>2025-10-25 05:24:51 +0000
commite7ef990a0a3b1ddf40a2f0d517e8eb4e261b1f80 (patch)
tree41eca7b2c9ec626b6522508efe400923165d624d /src/world.c
parent8874e4a585d66c16299ad45e79ea6c55960dee02 (diff)
downloadFindThings-e7ef990a0a3b1ddf40a2f0d517e8eb4e261b1f80.tar.gz
FindThings-e7ef990a0a3b1ddf40a2f0d517e8eb4e261b1f80.tar.bz2
FindThings-e7ef990a0a3b1ddf40a2f0d517e8eb4e261b1f80.zip
Lots of little things I should have done already
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/world.c b/src/world.c
index 42e3488..75fc0ab 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,5 +1,6 @@
#include "world.h"
#include "game.h"
+#include "entity.h"
size_t buildWorldBVHLeafs(BVHNode leafs[WORLD_ENTITY_MAX], const World* world)
{
@@ -935,8 +936,8 @@ float getWorldHeightAtLocation(const World* world, float x, float y)
return 0.0;
}
-void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests,
- WorldUID* closest, float* closestDistance)
+void castRayBVH(const World* world, BVHNode node, Ray ray, bool includePlaces,
+ int* tests, WorldUID* closest, float* closestDistance)
{
if (!GetRayCollisionBox(ray, node.box).hit)
{
@@ -962,6 +963,13 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests,
world->entities[node.entities[index]].position,
ray.position);
+ // Don't include places.
+ if (!includePlaces &&
+ entityIsPlace(world->entities[node.entities[index]].id))
+ {
+ continue;
+ }
+
if (distance < *closestDistance)
{
*closest = node.entities[index];
@@ -974,19 +982,20 @@ void castRayBVH(const World* world, BVHNode node, Ray ray, int* tests,
{
for (int index = 0; index < node.branchCount; ++index)
{
- castRayBVH(world, *node.branches[index], ray, tests, closest,
- closestDistance);
+ castRayBVH(world, *node.branches[index], ray, includePlaces, tests,
+ closest, closestDistance);
}
}
return;
}
-WorldUID castRayAtWorld(const World* world, Ray ray, int* tests)
+WorldUID castRayAtWorld(const World* world, Ray ray, bool includePlaces,
+ int* tests)
{
WorldUID uid = -1;
float distance = Vector3LengthSqr(world->size);
- castRayBVH(world, world->bvh, ray, tests, &uid, &distance);
+ castRayBVH(world, world->bvh, ray, includePlaces, tests, &uid, &distance);
return uid;
}