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_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;

View file

@ -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,13 +22,13 @@ 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*);\
@ -39,7 +40,8 @@ static inline PhysicsEntity T##_as_PhysicsEntity(T* x) {\
.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