51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
#include <state.h>
|
|
#include <librr/strutil.h>
|
|
#include <librr/memory.h>
|
|
#include <stdlib.h>
|
|
|
|
MtState * mt_initialize(char *app_name)
|
|
{
|
|
if(app_name == NULL)
|
|
{
|
|
app_name = "Unnamed Application";
|
|
}
|
|
usz_t len_app_name = rr_measure_string(app_name);
|
|
MtState *state = malloc(sizeof(struct MtState));
|
|
|
|
state->app_name = malloc(len_app_name + 1);
|
|
rr_memcopy(state->app_name, app_name, len_app_name + 1);
|
|
state->tag_registry = mt_create_tag_registry(state);
|
|
state->entity_registry = mt_create_entity_registry();
|
|
|
|
return state;
|
|
}
|
|
|
|
void mt_cleanup(MtState *state)
|
|
{
|
|
mt_delete_entity_registry(&state->entity_registry);
|
|
mt_delete_tag_registry(state->tag_registry);
|
|
if(state->app_name != NULL)
|
|
free(state->app_name);
|
|
free(state);
|
|
}
|
|
|
|
/* TODO: This function should start a new thread with a worker system.
|
|
void mt_start(MtState state)
|
|
{
|
|
|
|
}
|
|
*/
|
|
|
|
MtEntity * mt_summon(MtState *state)
|
|
{
|
|
return mt_create_entity(state, state->entity_registry.entity_id_counter++);
|
|
}
|
|
|
|
void mt_drop(MtEntity *entity)
|
|
{
|
|
MtState *state = entity->parent_state;
|
|
|
|
mt_delete_entity_data(entity);
|
|
mt_give_back_entity_pool_slot(&state->entity_registry.pool, state->entity_registry.pool.first_free);
|
|
}
|