added behaviour entity type
This commit is contained in:
parent
b7721baeb7
commit
7337592855
30
src/behaviour_entity.h
Normal file
30
src/behaviour_entity.h
Normal file
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue