Compare commits

..

No commits in common. "275dbdc748dc878bb21c0f9bc52ad3484f079771" and "2fa120c0249642b470ef97a071889fe1311019f1" have entirely different histories.

5 changed files with 7 additions and 85 deletions

View File

@ -1,3 +1,2 @@
tests/internal/basic-tag-registry-usage
tests/internal/entity-lookup
tests/interface/entity-creation

View File

@ -23,6 +23,6 @@ void mt_cleanup(MtState *state);
void mt_start(MtState *state);
MtEntity * mt_summon(MtState *state);
void mt_drop(MtEntity *entity);
void mt_delete(MtEntity *entity);
#endif // MT_STATE_H

View File

@ -31,7 +31,6 @@ MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier)
{
entity = mt_allocate_entity_pool_slot(&state->entity_registry.pool);
entity->parent_state = state;
entity->identifier = identifier;
level3->entities[identifier & 0xff] = entity;
}
return entity;

View File

@ -2,29 +2,23 @@
#include <state.h>
#include <stdlib.h>
i16_t mt_get_entity_tag_slot_index(MtEntity *entity, const char *name)
MtTag * mt_get_entity_tag_slot(MtEntity *entity, 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 tag_index;
return &entity->tags[tag_index];
++tag_index;
}
return -1;
}
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
// Create a new slot if needed
if(entity->num_tags >= entity->tags_capacity)
{
@ -80,97 +74,46 @@ void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector)
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;
}
void mt_untag(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);
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;
}

View File

@ -1,19 +0,0 @@
#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);
}