feat: physicsentity now requires messagereceiver

This commit is contained in:
Sara 2023-11-27 17:39:05 +01:00
parent a4253abfa1
commit 965ae37c7e
2 changed files with 8 additions and 5 deletions

View file

@ -26,6 +26,7 @@ void physics_entity_debug_draw(PhysicsEntity self) {
SDL_SetRenderDrawColor(g_renderer, 0, 255, 255, 255); SDL_SetRenderDrawColor(g_renderer, 0, 255, 255, 255);
SDL_RenderDrawLineF(g_renderer, lhs.x, lhs.y, rhs.x, rhs.y); SDL_RenderDrawLineF(g_renderer, lhs.x, lhs.y, rhs.x, rhs.y);
} }
static inline static inline
Vector _internal_calculate_contact_force(RigidBody* self, Contact* contact) { Vector _internal_calculate_contact_force(RigidBody* self, Contact* contact) {
const Vector velocity = contact->hit.velocity; const Vector velocity = contact->hit.velocity;

View file

@ -4,6 +4,7 @@
#include "typeclass_helpers.h" #include "typeclass_helpers.h"
#include "list.h" #include "list.h"
#include "transformable.h" #include "transformable.h"
#include "message_receiver.h"
typedef struct Collider Collider; typedef struct Collider Collider;
typedef struct Collision Collision; typedef struct Collision Collision;
@ -21,13 +22,13 @@ typedef struct PhysicsEntity {
void* data; void* data;
IPhysicsEntity const* tc; IPhysicsEntity const* tc;
ITransformable const* transformable; ITransformable const* transformable;
IMessageReceiver const* message_receiver;
} PhysicsEntity; } PhysicsEntity;
extern void physics_entity_debug_draw(PhysicsEntity self); extern void physics_entity_debug_draw(PhysicsEntity self);
extern void physics_entity_solve_contacts(PhysicsEntity self, List* contacts); extern void physics_entity_solve_contacts(PhysicsEntity self, List* contacts);
extern void physics_entity_update(PhysicsEntity self); extern void physics_entity_update(PhysicsEntity self);
#define impl_PhysicsEntity_for(T, get_rigidbody_f, on_collision_f, on_overlap_f)\ #define impl_PhysicsEntity_for(T, get_rigidbody_f, on_collision_f, on_overlap_f)\
static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\ static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
TC_FN_TYPECHECK(RigidBody*, get_rigidbody_f, T*);\ TC_FN_TYPECHECK(RigidBody*, get_rigidbody_f, T*);\
@ -39,7 +40,8 @@ static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
.on_overlap = (void(*const)(void*,Collider*)) on_overlap_f,\ .on_overlap = (void(*const)(void*,Collider*)) on_overlap_f,\
};\ };\
Transformable transformable = T##_as_Transformable(x);\ 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 #endif // !_fencer_collidable_h