feat: physicsentity now requires messagereceiver
This commit is contained in:
parent
a4253abfa1
commit
965ae37c7e
|
@ -26,6 +26,7 @@ void physics_entity_debug_draw(PhysicsEntity self) {
|
|||
SDL_SetRenderDrawColor(g_renderer, 0, 255, 255, 255);
|
||||
SDL_RenderDrawLineF(g_renderer, lhs.x, lhs.y, rhs.x, rhs.y);
|
||||
}
|
||||
|
||||
static inline
|
||||
Vector _internal_calculate_contact_force(RigidBody* self, Contact* contact) {
|
||||
const Vector velocity = contact->hit.velocity;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "typeclass_helpers.h"
|
||||
#include "list.h"
|
||||
#include "transformable.h"
|
||||
#include "message_receiver.h"
|
||||
|
||||
typedef struct Collider Collider;
|
||||
typedef struct Collision Collision;
|
||||
|
@ -21,25 +22,26 @@ typedef struct PhysicsEntity {
|
|||
void* data;
|
||||
IPhysicsEntity const* tc;
|
||||
ITransformable const* transformable;
|
||||
IMessageReceiver const* message_receiver;
|
||||
} PhysicsEntity;
|
||||
|
||||
extern void physics_entity_debug_draw(PhysicsEntity self);
|
||||
extern void physics_entity_solve_contacts(PhysicsEntity self, List* contacts);
|
||||
extern void physics_entity_update(PhysicsEntity self);
|
||||
|
||||
|
||||
#define impl_PhysicsEntity_for(T, get_rigidbody_f, on_collision_f, on_overlap_f)\
|
||||
static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
|
||||
TC_FN_TYPECHECK(RigidBody*, get_rigidbody_f, T*);\
|
||||
TC_FN_TYPECHECK(void, on_collision_f, T*, Collision);\
|
||||
TC_FN_TYPECHECK(void, on_overlap_f, T*, Collider*);\
|
||||
static IPhysicsEntity const tc = {\
|
||||
.get_rigidbody = (RigidBody*(*const)(void*)) get_rigidbody_f,\
|
||||
.on_collision = (void(*const)(void*,Collision)) on_collision_f,\
|
||||
.on_overlap = (void(*const)(void*,Collider*)) on_overlap_f,\
|
||||
.get_rigidbody = (RigidBody*(*const)(void*)) get_rigidbody_f,\
|
||||
.on_collision = (void(*const)(void*,Collision)) on_collision_f,\
|
||||
.on_overlap = (void(*const)(void*,Collider*)) on_overlap_f,\
|
||||
};\
|
||||
Transformable transformable = T##_as_Transformable(x);\
|
||||
return (PhysicsEntity){.data = x, .tc = &tc, .transformable = transformable.tc};\
|
||||
MessageReceiver receiver = T##_as_MessageReceiver(x);\
|
||||
return (PhysicsEntity){.data = x, .tc = &tc, .transformable = transformable.tc, .message_receiver = receiver.tc};\
|
||||
}
|
||||
|
||||
#endif // !_fencer_collidable_h
|
||||
|
|
Loading…
Reference in a new issue