Implemented but didn't test the entity-untagging function and fixed a potentially unwanted behaviour when getting a tag's value.
This commit is contained in:
parent
2fa120c024
commit
cea20bdaa2
|
@ -2,23 +2,29 @@
|
|||
#include <state.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
MtTag * mt_get_entity_tag_slot(MtEntity *entity, char *name)
|
||||
i16_t mt_get_entity_tag_slot_index(MtEntity *entity, const char *name)
|
||||
{
|
||||
MtState *state = entity->parent_state;
|
||||
|
||||
// Find the correct slot if it already exist
|
||||
|
||||
u32_t tag_id = mt_get_tag_id(&state->tag_registry, name);
|
||||
usz_t tag_index = 0;
|
||||
while(tag_index < entity->num_tags)
|
||||
{
|
||||
if(entity->tags[tag_index].identifier == tag_id)
|
||||
return &entity->tags[tag_index];
|
||||
return tag_index;
|
||||
|
||||
++tag_index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create a new slot if needed
|
||||
MtTag * mt_get_entity_tag_slot(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t tag_slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(tag_slot_index >= 0)
|
||||
return &entity->tags[tag_slot_index];
|
||||
|
||||
// A new slot is needed
|
||||
|
||||
if(entity->num_tags >= entity->tags_capacity)
|
||||
{
|
||||
|
@ -74,46 +80,97 @@ void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector)
|
|||
|
||||
|
||||
|
||||
void mt_untag(MtEntity *entity, char *name);
|
||||
void mt_untag(MtEntity *entity, char *name)
|
||||
{
|
||||
i64_t tag_slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
entity->tags[tag_slot_index] = entity->tags[entity->num_tags-1];
|
||||
--entity->num_tags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
i64_t mt_get_i64_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
return 0;
|
||||
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
|
||||
return tag->data.integer;
|
||||
}
|
||||
|
||||
f64_t mt_get_f64_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
return 0.0f;
|
||||
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.real;
|
||||
}
|
||||
|
||||
char * mt_get_str_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
return NULL;
|
||||
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.string;
|
||||
}
|
||||
|
||||
void * mt_get_ptr_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
return NULL;
|
||||
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.pointer;
|
||||
}
|
||||
|
||||
rr_vec2f_s mt_get_vec2_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
{
|
||||
rr_vec2f_s err_vector;
|
||||
err_vector.x = 0.0f;
|
||||
err_vector.y = 0.0f;
|
||||
return err_vector;
|
||||
}
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.vec2f;
|
||||
}
|
||||
|
||||
rr_vec3f_s mt_get_vec3_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
{
|
||||
rr_vec3f_s err_vector;
|
||||
err_vector.x = 0.0f;
|
||||
err_vector.y = 0.0f;
|
||||
err_vector.z = 0.0f;
|
||||
return err_vector;
|
||||
}
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.vec3f;
|
||||
}
|
||||
|
||||
rr_vec4f_s mt_get_vec4_tag(MtEntity *entity, char *name)
|
||||
{
|
||||
i16_t slot_index = mt_get_entity_tag_slot_index(entity, name);
|
||||
if(slot_index < 0)
|
||||
{
|
||||
rr_vec4f_s err_vector;
|
||||
err_vector.x = 0.0f;
|
||||
err_vector.y = 0.0f;
|
||||
err_vector.z = 0.0f;
|
||||
err_vector.w = 0.0f;
|
||||
return err_vector;
|
||||
}
|
||||
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||
return tag->data.vec4f;
|
||||
}
|
||||
|
|
Reference in New Issue