Compare commits
2 Commits
2fa120c024
...
275dbdc748
Author | SHA1 | Date |
---|---|---|
Eric-Paul Ickhorn | 275dbdc748 | |
Eric-Paul Ickhorn | cea20bdaa2 |
|
@ -1,2 +1,3 @@
|
||||||
tests/internal/basic-tag-registry-usage
|
tests/internal/basic-tag-registry-usage
|
||||||
|
tests/internal/entity-lookup
|
||||||
tests/interface/entity-creation
|
tests/interface/entity-creation
|
|
@ -23,6 +23,6 @@ void mt_cleanup(MtState *state);
|
||||||
void mt_start(MtState *state);
|
void mt_start(MtState *state);
|
||||||
|
|
||||||
MtEntity * mt_summon(MtState *state);
|
MtEntity * mt_summon(MtState *state);
|
||||||
void mt_delete(MtEntity *entity);
|
void mt_drop(MtEntity *entity);
|
||||||
|
|
||||||
#endif // MT_STATE_H
|
#endif // MT_STATE_H
|
||||||
|
|
|
@ -31,6 +31,7 @@ MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier)
|
||||||
{
|
{
|
||||||
entity = mt_allocate_entity_pool_slot(&state->entity_registry.pool);
|
entity = mt_allocate_entity_pool_slot(&state->entity_registry.pool);
|
||||||
entity->parent_state = state;
|
entity->parent_state = state;
|
||||||
|
entity->identifier = identifier;
|
||||||
level3->entities[identifier & 0xff] = entity;
|
level3->entities[identifier & 0xff] = entity;
|
||||||
}
|
}
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
@ -2,23 +2,29 @@
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
#include <stdlib.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;
|
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);
|
u32_t tag_id = mt_get_tag_id(&state->tag_registry, name);
|
||||||
usz_t tag_index = 0;
|
usz_t tag_index = 0;
|
||||||
while(tag_index < entity->num_tags)
|
while(tag_index < entity->num_tags)
|
||||||
{
|
{
|
||||||
if(entity->tags[tag_index].identifier == tag_id)
|
if(entity->tags[tag_index].identifier == tag_id)
|
||||||
return &entity->tags[tag_index];
|
return tag_index;
|
||||||
|
|
||||||
++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)
|
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)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
|
|
||||||
return tag->data.integer;
|
return tag->data.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
f64_t mt_get_f64_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.real;
|
return tag->data.real;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * mt_get_str_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.string;
|
return tag->data.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * mt_get_ptr_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.pointer;
|
return tag->data.pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec2f_s mt_get_vec2_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec2f;
|
return tag->data.vec2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec3f_s mt_get_vec3_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec3f;
|
return tag->data.vec3f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec4f_s mt_get_vec4_tag(MtEntity *entity, char *name)
|
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);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec4f;
|
return tag->data.vec4f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include <state.h>
|
||||||
|
#include <entity.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
MtState *state = mt_initialize("Interface Test");;
|
||||||
|
MtEntity *entity = mt_summon(state);
|
||||||
|
MtEntity *looked_up_entity = mt_get_entity(state, entity->identifier);
|
||||||
|
|
||||||
|
if(entity != looked_up_entity)
|
||||||
|
printf("Failed looking up entity; the pointers don't match:\nOriginal: %p\nLooked Up: %p\n", entity, looked_up_entity);
|
||||||
|
else
|
||||||
|
puts("The entity which was looked up from the identifier does match the original. SUCCESS!");
|
||||||
|
|
||||||
|
mt_drop(entity);
|
||||||
|
mt_cleanup(state);
|
||||||
|
}
|
Reference in New Issue