fencer/game/src/Damagable.h
Sara 0c6f1dd8cf feat: reworked typeclasses to forward-declare then define
forward declarations are simplified with decl_typeclass_impl
impl_Typeclass_for now instead only define
static inline impl_Typeclass_for can be used to achieve the old behaviour
2024-01-12 09:02:42 +01:00

32 lines
681 B
C

#ifndef FIGHT_DAMAGABLE_H
#define FIGHT_DAMAGABLE_H
#include "typeclass_helpers.h"
#include "vmath.h"
typedef struct DamageEventData {
int damageAmount;
Vector origin;
} DamageEventData;
typedef struct {
int (*const damage)(void*, DamageEventData*);
} IDamagable;
typedef struct {
void* data;
IDamagable const* tc;
} Damagable;
#define impl_Damagable_for(T, damage_f)\
Damagable T##_as_Damagable(T* x) {\
TC_FN_TYPECHECK(int, damage_f, T*, DamageEventData*);\
static const IDamagable tc = {\
.damage = (int(*const)(void*, DamageEventData*)) damage_f,\
};\
return (Damagable){.data = x, .tc = &tc};\
}
#endif // !FIGHT_DAMAGABLE_H