diff --git a/src/behaviour_entity.h b/src/behaviour_entity.h new file mode 100644 index 0000000..c0d22ee --- /dev/null +++ b/src/behaviour_entity.h @@ -0,0 +1,30 @@ +#ifndef _update_entity_h +#define _update_entity_h + +#include "typeclass_helpers.h" +#include "vmath.h" + +typedef struct { + void (*const spawn)(void* self, Vector at); + void (*const update)(void* self, float dt); + void (*const start)(void* self); +} IEntityBehaviour; + +typedef struct { + void* data; + IEntityBehaviour const* tc; +} BehaviourEntity; + +#define impl_BehaviourEntity_for(T, start_f, update_f, spawn_f)\ +static inline BehaviourEntity T##_as_BehaviourEntity(T* x) {\ + TC_FN_TYPECHECK(void, start_f, T*);\ + TC_FN_TYPECHECK(void, update_f, T*, float);\ + static IEntityBehaviour const tc = {\ + .spawn = (void(*const)(void*, Vector)) spawn_f,\ + .update = (void(*const)(void*, float)) update_f,\ + .start = (void(*const)(void*)) start_f\ + };\ + return (BehaviourEntity){.tc = &tc, .data = x};\ +}\ + +#endif // !_update_entity_h diff --git a/src/player.c b/src/player.c index ba359e2..659c5ba 100644 --- a/src/player.c +++ b/src/player.c @@ -8,6 +8,10 @@ void player_start(Player* self) { self->transform = IdentityTransform; } +void player_update(Player* self, float dt) { + +} + Transform* player_get_transform(Player* self) { return &self->transform; } diff --git a/src/player.h b/src/player.h index eb1715c..c7a3034 100644 --- a/src/player.h +++ b/src/player.h @@ -2,7 +2,7 @@ #define _fencer_player_h #include "physics_entity.h" -#include "update_entity.h" +#include "behaviour_entity.h" #include "transformable.h" #include "sprite.h" @@ -18,6 +18,8 @@ extern void player_spawn(Player* self, Vector at); extern void player_start(Player* self); extern void player_update(Player* self, float dt); +extern void player_collision(Player* self, Collision hit); + extern Transform* player_get_transform(Player* self); extern RigidBody* player_get_rigidbody(Player* self); extern Shape* player_get_shape(Player* self); @@ -32,10 +34,13 @@ impl_Transformable_for(Player, player_get_scale, player_get_rotation ) + impl_PhysicsEntity_for(Player, player_get_rigidbody, - player_get_shape + player_get_shape, + player_collision ) + impl_BehaviourEntity_for(Player, player_start, player_update,