From 67b138741b3cb37dc7cb3086133dfdb3c94d2eb9 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 24 Nov 2023 23:23:27 +0100 Subject: [PATCH] feat(physics): added physics_world_query --- core/src/physics_world.c | 7 +++++++ core/src/physics_world.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/core/src/physics_world.c b/core/src/physics_world.c index 925e894..28a9c7e 100644 --- a/core/src/physics_world.c +++ b/core/src/physics_world.c @@ -29,6 +29,13 @@ void physics_world_remove_entity(PhysicsEntity entity) { ASSERT_RETURN(0,, "Physics entity with data at %p is not registered in physics world", entity.data); } +PhysicsEntity physics_world_query(PhysicsQuery query) { + list_foreach(PhysicsEntity*, entity, &_world_bodies) { + if(overlap_check(query, *entity)) + return *entity; + } +} + static inline void _internal_physics_narrow_collision() { size_t half_end = _world_bodies.len/2; diff --git a/core/src/physics_world.h b/core/src/physics_world.h index 088b251..e2aa674 100644 --- a/core/src/physics_world.h +++ b/core/src/physics_world.h @@ -2,6 +2,7 @@ #define _fencer_physics_world_h #include "physics_entity.h" +#include "collision.h" extern void physics_world_init(); extern void physics_world_clean(); @@ -9,6 +10,8 @@ extern void physics_world_clean(); extern void physics_world_add_entity(PhysicsEntity entity); extern void physics_world_remove_entity(PhysicsEntity entity); +extern PhysicsEntity physics_world_query(PhysicsQuery query); + extern void physics_world_tick(); #endif // !_fencer_physics_world_h