Added retrievable type field to tags
This commit is contained in:
parent
4f549290ab
commit
0776499c6f
|
@ -6,6 +6,18 @@
|
|||
#include <librr/types.h>
|
||||
#include <librr/linear_algebra.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MT_TAG_NONEXISTENT,
|
||||
MT_TAG_INT,
|
||||
MT_TAG_REAL,
|
||||
MT_TAG_STRING,
|
||||
MT_TAG_POINTER,
|
||||
MT_TAG_VEC2,
|
||||
MT_TAG_VEC3,
|
||||
MT_TAG_VEC4
|
||||
} MtTagType;
|
||||
|
||||
typedef void MtEntity;
|
||||
|
||||
/// @brief: An MtTask is a piece of functionality with an own state/context which will be executed on the same thread or set of threads.
|
||||
|
@ -60,6 +72,8 @@ void mt_tag_vec2(MtEntity *entity, char *name, rr_vec2f_s vector);
|
|||
void mt_tag_vec3(MtEntity *entity, char *name, rr_vec3f_s vector);
|
||||
void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector);
|
||||
|
||||
MtTagType mt_get_tag_type(MtEntity *entity, char *name);
|
||||
bool_t mt_has_tag(MtEntity *entity, const char *name);
|
||||
void mt_untag(MtEntity *entity, char *name);
|
||||
|
||||
i64_t mt_get_i64_tag(MtEntity *entity, char *name);
|
||||
|
|
|
@ -5,6 +5,18 @@
|
|||
#include <librr/types.h>
|
||||
#include <librr/linear_algebra.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MT_TAG_NONEXISTENT,
|
||||
MT_TAG_INT,
|
||||
MT_TAG_REAL,
|
||||
MT_TAG_STRING,
|
||||
MT_TAG_POINTER,
|
||||
MT_TAG_VEC2,
|
||||
MT_TAG_VEC3,
|
||||
MT_TAG_VEC4
|
||||
} MtTagType;
|
||||
|
||||
typedef struct MtEntityLookupTree MtEntityLookupTree;
|
||||
typedef struct MtEntityListL1 MtEntityListL1;
|
||||
typedef struct MtEntityListL2 MtEntityListL2;
|
||||
|
@ -63,6 +75,7 @@ struct MtEntity
|
|||
struct MtTag
|
||||
{
|
||||
u32_t identifier;
|
||||
MtTagType type;
|
||||
union MtTagData
|
||||
{
|
||||
i64_t integer;
|
||||
|
|
|
@ -44,6 +44,7 @@ void mt_tag_i64(MtEntity *entity, char *name, i64_t integer)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_INT;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.integer = integer;
|
||||
|
@ -53,6 +54,7 @@ void mt_tag_f64(MtEntity *entity, char *name, f64_t real)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_REAL;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.real = real;
|
||||
|
@ -62,6 +64,7 @@ void mt_tag_str(MtEntity *entity, char *name, char *string)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_STRING;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.string = string;
|
||||
|
@ -71,6 +74,7 @@ void mt_tag_ptr(MtEntity *entity, char *name, void *pointer)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_POINTER;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.pointer = pointer;
|
||||
|
@ -80,6 +84,7 @@ void mt_tag_vec2(MtEntity *entity, char *name, rr_vec2f_s vector)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_VEC2;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.vec2f = vector;
|
||||
|
@ -89,6 +94,7 @@ void mt_tag_vec3(MtEntity *entity, char *name, rr_vec3f_s vector)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_VEC3;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.vec3f = vector;
|
||||
|
@ -97,11 +103,20 @@ void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector)
|
|||
{
|
||||
MtState *state = entity->parent_state;
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
tag->type = MT_TAG_VEC4;
|
||||
|
||||
mt_add_entity_to_tag_lookup_list(&state->tag_registry, name, entity->identifier);
|
||||
tag->data.vec4f = vector;
|
||||
}
|
||||
|
||||
MtTagType mt_get_tag_type(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t tag_slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(tag_slot_index < 0)
|
||||
return MT_TAG_NONEXISTENT;
|
||||
return entity->tags[tag_slot_index].type;
|
||||
}
|
||||
|
||||
bool_t mt_has_tag(MtEntity *entity, const char *name)
|
||||
{
|
||||
MtState *state = entity->parent_state;
|
||||
|
|
|
@ -18,6 +18,14 @@ int main()
|
|||
return -1;
|
||||
}
|
||||
|
||||
if(mt_get_tag_type(entity, "test-tag") != MT_TAG_INT)
|
||||
{
|
||||
puts("The integer tag's type wasn't stored correctly.");
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
puts("Integer tags are correctly stored.");
|
||||
|
||||
mt_drop(entity);
|
||||
mt_cleanup(state);
|
||||
puts("The program reached the end; this test is considered as passed. SUCCESS!");
|
||||
|
|
Reference in New Issue