diff --git a/inc-c/entity.h b/inc-c/entity.h index 34b0a64..de7d6d0 100644 --- a/inc-c/entity.h +++ b/inc-c/entity.h @@ -2,7 +2,10 @@ #ifndef MT_ENTITY_H #define MT_ENTITY_H +#include #include +#include +#include typedef struct MtEntity MtEntity; @@ -21,4 +24,17 @@ struct MtEntity uint32_t shadow_id; }; +MtEntity mt_summon(void *context_ptr); +void mt_delete(MtEntity entity); + +void mt_tag_bool(MtEntity entity, const char *name, bool boolean); +void mt_tag_int(MtEntity entity, const char *name, int64_t integer); +void mt_tag_float(MtEntity entity, const char *name, double real); +void mt_tag_str(MtEntity entity, const char *name, char *string); +void mt_tag_ptr(MtEntity entity, const char *name, void *pointer); +void mt_tag_vec2f(MtEntity entity, const char *name, AuVec2f vec2f); +void mt_tag_vec3f(MtEntity entity, const char *name, AuVec3f vec3f); +void mt_tag_vec4f(MtEntity entity, const char *name, AuVec4f vec4f); +void mt_tag_ref(MtEntity entity, const char *name, MtEntity reference); + #endif // MT_ENTITY_H diff --git a/inc-c/shadow-tag.h b/inc-c/shadow-tag.h index 5508177..ec25bfc 100644 --- a/inc-c/shadow-tag.h +++ b/inc-c/shadow-tag.h @@ -16,15 +16,16 @@ typedef struct MtShadowTagSystem MtShadowTagSystem; typedef enum { + MT_SHADOW_TAG_UNUSED = 0, MT_SHADOW_TAG_INTEGER, MT_SHADOW_TAG_BOOLEAN, - MT_SHADOW_TAG_DECIMAL, + MT_SHADOW_TAG_REAL, MT_SHADOW_TAG_STRING, MT_SHADOW_TAG_RAW_POINTER, MT_SHADOW_TAG_VECTOR_2, MT_SHADOW_TAG_VECTOR_3, MT_SHADOW_TAG_VECTOR_4, - MT_SHADOW_TAG_SUB_ENTITY, + MT_SHADOW_TAG_REFERENCE, MT_SHADOW_TAG_RESOURCE } MtShadowTagType; @@ -40,13 +41,13 @@ struct MtShadowTag { bool boolean; int64_t integer; - double decimal; + double real; char *string; void *raw_pointer; AuVec2f vec2f; AuVec3f vec3f; AuVec4f vec4f; - MtEntity entity; + MtEntity reference; } data; }; diff --git a/src-c/entity.c b/src-c/entity.c new file mode 100644 index 0000000..42b7271 --- /dev/null +++ b/src-c/entity.c @@ -0,0 +1,98 @@ +#include +#include +#include + +MtEntity mt_summon(void *context_ptr) +{ + MtContext *context = context_ptr; + MtShadow *shadow = mt_create_shadow(context->shadow_registry); + MtEntity entity; + entity.context = context_ptr; + entity.shadow_id = shadow->identifier; + return entity; +} + +void mt_delete(MtEntity entity) +{ + MtContext *context = entity.context; + MtShadow *shadow = mt_lookup_shadow(context->shadow_registry, entity.shadow_id); + mt_delete_shadow(context->shadow_registry, shadow); +} + +MtShadowTag * mt_get_and_name_tag_for_entity(MtEntity entity, const char *name) +{ + MtContext *context = entity.context; + MtShadow *shadow = mt_lookup_shadow(context->shadow_registry, entity.shadow_id); + if(shadow->tag_chain_start == NULL) + shadow->tag_chain_start = (entity.context); + else + shadow->tag_chain_start = mt_alloc_shadow_tag_before(shadow->tag_chain_start); + return shadow->tag_chain_start; +} + +void mt_tag_bool(MtEntity entity, const char *name, bool boolean) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_BOOLEAN; + tag->data.boolean = boolean; +} + +void mt_tag_int(MtEntity entity, const char *name, int64_t integer) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_INTEGER; + tag->data.integer = integer; +} + +void mt_tag_float(MtEntity entity, const char *name, double real) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_REAL; + tag->data.real = real; +} + +void mt_tag_str(MtEntity entity, const char *name, char *string) +{ + // TODO: Allocate the string in an arena allocator which is + // stored in, and deleted with, the entity shadow. + + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_STRING; + tag->data.string = string; +} + +void mt_tag_ptr(MtEntity entity, const char *name, void *pointer) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_RAW_POINTER; + tag->data.raw_pointer = pointer; +} + +void mt_tag_vec2f(MtEntity entity, const char *name, AuVec2f vec2f) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_VECTOR_2; + tag->data.vec2f = vec2f; +} + +void mt_tag_vec3f(MtEntity entity, const char *name, AuVec3f vec3f) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_VECTOR_3; + tag->data.vec3f = vec3f; +} + +void mt_tag_vec4f(MtEntity entity, const char *name, AuVec4f vec4f) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_VECTOR_4; + tag->data.vec4f = vec4f; +} + +void mt_tag_ref(MtEntity entity, const char *name, MtEntity reference) +{ + MtShadowTag *tag = mt_get_and_name_tag_for_entity(entity, name); + tag->type = MT_SHADOW_TAG_REFERENCE; + tag->data.reference = reference; +} +