This repository has been archived on 2024-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
MainTree/core/src-c/state.c

47 lines
1.1 KiB
C

#include <state.h>
#include <librr/strutil.h>
#include <librr/memory.h>
#include <stdlib.h>
MtState * mt_initialize(char *app_name)
{
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);
}