Added a test for the entity lookup and fixed a bug found through that test.

This commit is contained in:
Eric-Paul Ickhorn 2024-01-30 23:59:59 +01:00
parent cea20bdaa2
commit 275dbdc748
Signed by: epickh
GPG Key ID: F5EBBE013924D95F
4 changed files with 22 additions and 1 deletions

View File

@ -1,2 +1,3 @@
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_delete(MtEntity *entity);
void mt_drop(MtEntity *entity);
#endif // MT_STATE_H

View File

@ -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->parent_state = state;
entity->identifier = identifier;
level3->entities[identifier & 0xff] = entity;
}
return entity;

View File

@ -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);
}