physics entity interface now requires a callback for collisions
This commit is contained in:
parent
37008f455e
commit
a108aa21f7
|
@ -7,9 +7,12 @@
|
|||
#include "rigidbody.h"
|
||||
#include "shape.h"
|
||||
|
||||
typedef struct Collision Collision;
|
||||
|
||||
typedef struct {
|
||||
RigidBody* (*const get_rigidbody)(void* self);
|
||||
Shape* (*const get_shape)(void* self);
|
||||
void(*const on_collision)(void* self, Collision collision);
|
||||
} IPhysicsEntity;
|
||||
|
||||
typedef struct {
|
||||
|
@ -18,14 +21,16 @@ typedef struct {
|
|||
ITransformable const* transformable;
|
||||
} PhysicsEntity;
|
||||
|
||||
#define impl_PhysicsEntity_for(T, get_rigidbody_f, get_shape_f)\
|
||||
#define impl_PhysicsEntity_for(T, get_rigidbody_f, get_shape_f, on_collision_f)\
|
||||
static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
|
||||
TC_FN_TYPECHECK(Transformable, T##_as_Transformable, T*);\
|
||||
TC_FN_TYPECHECK(RigidBody*, get_rigidbody_f, T*);\
|
||||
TC_FN_TYPECHECK(Shape*, get_shape_f, T*);\
|
||||
TC_FN_TYPECHECK(void, on_collision_f, T*, Collision);\
|
||||
static IPhysicsEntity const tc = {\
|
||||
.get_rigidbody = (RigidBody*(*const)(void*)) get_rigidbody_f,\
|
||||
.get_shape = (Shape*(*const)(void*)) get_shape_f,\
|
||||
.get_rigidbody = (RigidBody*(*const)(void*)) get_rigidbody_f,\
|
||||
.get_shape = (Shape*(*const)(void*)) get_shape_f,\
|
||||
.on_collision = (void(*const)(void*,Collision)) on_collision_f,\
|
||||
};\
|
||||
Transformable transformable = T##_as_Transformable(x);\
|
||||
return (PhysicsEntity){.data = x, .tc = &tc, .transformable = transformable.tc};\
|
||||
|
|
Loading…
Reference in a new issue