behaviour entity trait now requires drop trait and a draw function

This commit is contained in:
Sara 2023-11-02 14:26:21 +01:00
parent cf001bd2d6
commit 674d1b55fb

View file

@ -1,6 +1,7 @@
#ifndef _update_entity_h #ifndef _update_entity_h
#define _update_entity_h #define _update_entity_h
#include "drop.h"
#include "typeclass_helpers.h" #include "typeclass_helpers.h"
#include "vmath.h" #include "vmath.h"
@ -8,23 +9,29 @@ typedef struct {
void (*const spawn)(void* self, Vector at); void (*const spawn)(void* self, Vector at);
void (*const update)(void* self, float dt); void (*const update)(void* self, float dt);
void (*const start)(void* self); void (*const start)(void* self);
void (*const draw)(void* self);
} IEntityBehaviour; } IEntityBehaviour;
typedef struct { typedef struct {
void* data; void* data;
IEntityBehaviour const* tc; IEntityBehaviour const* tc;
IDrop const* drop;
} BehaviourEntity; } BehaviourEntity;
#define impl_BehaviourEntity_for(T, start_f, update_f, spawn_f)\ #define impl_BehaviourEntity_for(T, start_f, update_f, spawn_f, draw_f)\
static inline BehaviourEntity T##_as_BehaviourEntity(T* x) {\ static inline BehaviourEntity T##_as_BehaviourEntity(T* x) {\
TC_FN_TYPECHECK(void, start_f, T*);\ TC_FN_TYPECHECK(void, start_f, T*);\
TC_FN_TYPECHECK(void, update_f, T*, float);\ TC_FN_TYPECHECK(void, update_f, T*, float);\
TC_FN_TYPECHECK(void, draw_f, T*);\
static IEntityBehaviour const tc = {\ static IEntityBehaviour const tc = {\
.spawn = (void(*const)(void*, Vector)) spawn_f,\ .spawn = (void(*const)(void*, Vector)) spawn_f,\
.update = (void(*const)(void*, float)) update_f,\ .update = (void(*const)(void*, float)) update_f,\
.start = (void(*const)(void*)) start_f\ .start = (void(*const)(void*)) start_f,\
.draw = (void(*const)(void*)) draw_f,\
};\ };\
return (BehaviourEntity){.tc = &tc, .data = x};\ TC_FN_TYPECHECK(Drop, T##_as_Drop, T*);\
IDrop const* drop = T##_as_Drop(x).tc;\
return (BehaviourEntity){.tc = &tc, .drop = drop, .data = x};\
}\ }\
#endif // !_update_entity_h #endif // !_update_entity_h