feat: replaced mirror_get_converter with a more direct mirror_get_typeclass
This commit is contained in:
parent
1a3c4c9676
commit
760d9f2879
|
@ -1,10 +1,10 @@
|
|||
#include "mirror.h"
|
||||
|
||||
void* mirror_get_converter(void* self, IMirror const* tc, const char* typeclass) {
|
||||
const void* mirror_get_typeclass(void* self, IMirror const* tc, const char* typeclass) {
|
||||
uintptr_t target_hash = strhash(typeclass);
|
||||
list_foreach(MirroredTypeclass*, class, tc->get_typeclasses(self)) {
|
||||
if(target_hash == class->name_hash && strcmp(typeclass, class->typeclass_name) == 0)
|
||||
return class->wrap;
|
||||
return class->typeclass;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
const char* typeclass_name;
|
||||
uintptr_t name_hash;
|
||||
void* (*const wrap)(void*);
|
||||
const void* typeclass;
|
||||
} MirroredTypeclass;
|
||||
|
||||
static inline int mirror_is_typeid(const Mirror* mirror, typeid id) {
|
||||
|
@ -36,7 +36,7 @@ static inline int mirror_eq(const Mirror* lhs, const Mirror* rhs) {
|
|||
return lhs->tc->get_typeid(lhs->data) == rhs->tc->get_typeid(rhs->data);
|
||||
}
|
||||
|
||||
extern void* mirror_get_converter(void* data, IMirror const* tc, const char* typeclass);
|
||||
extern const void* mirror_get_typeclass(void* data, IMirror const* tc, const char* typeclass);
|
||||
|
||||
#define MIRROR_TRY_WRAP(Into_, Mirror_, Typeclass_){\
|
||||
MirroredTypeclassWrapFunc fn_ = mirror_get_typeclass(Mirror_, #Typeclass_);\
|
||||
|
@ -85,13 +85,15 @@ List* T##_get_typeclasses(T* self) {\
|
|||
if(!init_flag) {\
|
||||
init_flag = 1,\
|
||||
typeclasses = list_init(sizeof(MirroredTypeclass));\
|
||||
MirroredTypeclass tc;\
|
||||
|
||||
#define REFLECT_TYPECLASS(T, TypeClass_)\
|
||||
list_add(&typeclasses, &(MirroredTypeclass){\
|
||||
tc = (MirroredTypeclass){\
|
||||
.name_hash = strhash(#TypeClass_),\
|
||||
.typeclass_name = #TypeClass_,\
|
||||
.wrap = (void*(*const)(void*)) T##_as_##TypeClass_\
|
||||
});
|
||||
.typeclass = (void*)T##_as_##TypeClass_(NULL).tc\
|
||||
};\
|
||||
list_add(&typeclasses, &tc);
|
||||
|
||||
#define END_REFLECT(T)\
|
||||
}\
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "PlayerStates.h"
|
||||
#include "mirror.h"
|
||||
#include "physics_world.h"
|
||||
|
||||
#include "Damagable.h"
|
||||
|
@ -59,14 +60,13 @@ void PlayerAttackTrigger(Player* self) {
|
|||
MakeVector(0.1f, 0.06f), PHYSICS_LAYER_COMBAT, self->rigidbody);
|
||||
if(found != NULL) {
|
||||
PhysicsEntity entity = collider_get_owner(found);
|
||||
Damagable(*const as_damagable)(void*) = mirror_get_converter(entity.data, entity.mirror, "Damagable");
|
||||
if(as_damagable) {
|
||||
Damagable damagable = as_damagable(entity.data);
|
||||
const IDamagable* damagable = mirror_get_typeclass(entity.data, entity.mirror, "Damagable");
|
||||
if(damagable) {
|
||||
DamageEventData data = {
|
||||
.damageAmount = 1,
|
||||
.origin = self->transform.position
|
||||
};
|
||||
damagable.tc->damage(entity.data, &data);
|
||||
damagable->damage(entity.data, &data);
|
||||
}
|
||||
}
|
||||
++self->animationTriggers;
|
||||
|
|
Loading…
Reference in a new issue