2024-01-29 18:48:56 +00:00
|
|
|
#include <entity.h>
|
|
|
|
#include <state.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier)
|
2024-01-29 18:48:56 +00:00
|
|
|
{
|
2024-01-30 21:47:43 +00:00
|
|
|
MtState *state = state_voidptr;
|
2024-01-30 21:31:31 +00:00
|
|
|
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
2024-01-29 18:48:56 +00:00
|
|
|
if(level1 == NULL)
|
|
|
|
{
|
2024-01-30 21:31:31 +00:00
|
|
|
state->entity_registry.lookup.sublists[identifier >> 24] = calloc(sizeof(MtEntityListL1), 1);
|
|
|
|
level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
2024-01-29 18:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MtEntityListL2 *level2 = level1->sublists[(identifier >> 16) & 0xff];
|
|
|
|
if(level2 == NULL)
|
|
|
|
{
|
|
|
|
level1->sublists[(identifier >> 16) & 0xff] = calloc(sizeof(MtEntityListL2), 1);
|
|
|
|
level2 = level1->sublists[(identifier >> 16) & 0xff];
|
|
|
|
}
|
|
|
|
|
|
|
|
MtEntityListL3 *level3 = level2->sublists[(identifier >> 8) & 0xff];
|
|
|
|
if(level3 == NULL)
|
|
|
|
{
|
|
|
|
level2->sublists[(identifier >> 8) & 0xff] = calloc(sizeof(MtEntityListL3), 1);
|
|
|
|
level3 = level2->sublists[(identifier >> 8) & 0xff];
|
|
|
|
}
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity *entity = level3->entities[identifier & 0xff];
|
2024-01-29 18:48:56 +00:00
|
|
|
if(entity == NULL)
|
|
|
|
{
|
2024-01-30 21:47:43 +00:00
|
|
|
entity = mt_allocate_entity_pool_slot(&state->entity_registry.pool);
|
2024-01-30 21:31:31 +00:00
|
|
|
entity->parent_state = state;
|
|
|
|
level3->entities[identifier & 0xff] = entity;
|
2024-01-29 18:48:56 +00:00
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity * mt_get_entity(void *state_voidptr, u32_t identifier)
|
2024-01-29 18:48:56 +00:00
|
|
|
{
|
2024-01-30 21:47:43 +00:00
|
|
|
MtState *state = state_voidptr;
|
2024-01-30 21:31:31 +00:00
|
|
|
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
2024-01-29 18:48:56 +00:00
|
|
|
if(level1 == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MtEntityListL2 *level2 = level1->sublists[(identifier >> 16) & 0xff];
|
|
|
|
if(level2 == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MtEntityListL3 *level3 = level2->sublists[(identifier >> 8) & 0xff];
|
|
|
|
if(level3 == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity *entity = level3->entities[identifier & 0xff];
|
2024-01-29 18:48:56 +00:00
|
|
|
if(entity == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|