2026-03-06 12:56:38 +01:00
|
|
|
|
2026-06-05 14:48:27 +02:00
|
|
|
#ifdef WITH_PHYSICS
|
2026-03-06 12:56:38 +01:00
|
|
|
|
2026-03-07 21:12:59 +01:00
|
|
|
#include "../libs/asim.h"
|
2026-04-21 10:52:27 +02:00
|
|
|
#include "global.h"
|
2026-03-07 21:12:59 +01:00
|
|
|
|
2026-03-06 12:56:38 +01:00
|
|
|
physics_world_t *physics_world_create() {
|
|
|
|
|
asim_world_create();
|
|
|
|
|
physics_world_t *world = GC_ALLOC_INIT(physics_world_t, {0});
|
|
|
|
|
gc_unroot(physics_world_active);
|
|
|
|
|
physics_world_active = world;
|
|
|
|
|
gc_root(physics_world_active);
|
|
|
|
|
return world;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void physics_world_update(physics_world_t *world) {
|
|
|
|
|
asim_world_update(sys_delta());
|
|
|
|
|
|
|
|
|
|
i32_array_t *keys = imap_keys(physics_body_object_map);
|
|
|
|
|
for (i32 i = 0; i < keys->length; ++i) {
|
|
|
|
|
physics_body_t *body = any_imap_get(physics_body_object_map, keys->buffer[i]);
|
|
|
|
|
physics_body_update(body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
physics_pair_t_array_t *physics_world_get_contact_pairs(physics_world_t *world, physics_body_t *body) {
|
2026-03-08 08:39:29 +01:00
|
|
|
physics_pair_t_array_t *pairs = any_array_create_from_raw((void *[]){}, 0);
|
2026-05-11 19:48:30 +02:00
|
|
|
physics_pair_t *p = asim_world_get_contact(body->_body);
|
|
|
|
|
if (p->pos_a_x != 0 || p->pos_a_y != 0 || p->pos_a_z != 0) {
|
|
|
|
|
any_array_push(pairs, p);
|
|
|
|
|
}
|
2026-03-06 12:56:38 +01:00
|
|
|
return pairs;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 19:48:30 +02:00
|
|
|
float physics_world_get_speed(physics_world_t *world, physics_body_t *body) {
|
|
|
|
|
return asim_body_get_speed(body->_body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 12:56:38 +01:00
|
|
|
#endif
|