2024-01-29 18:48:56 +00:00
|
|
|
#include <state.h>
|
|
|
|
#include <librr/strutil.h>
|
|
|
|
#include <librr/memory.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtState * mt_initialize(char *app_name)
|
2024-01-29 18:48:56 +00:00
|
|
|
{
|
|
|
|
usz_t len_app_name = rr_measure_string(app_name);
|
2024-01-30 21:47:43 +00:00
|
|
|
MtState *state = malloc(sizeof(struct MtState));
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
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);
|
2024-01-30 21:31:31 +00:00
|
|
|
state->entity_registry = mt_create_entity_registry();
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
void mt_cleanup(MtState *state)
|
2024-01-29 18:48:56 +00:00
|
|
|
{
|
2024-01-30 21:31:31 +00:00
|
|
|
mt_delete_entity_registry(&state->entity_registry);
|
|
|
|
mt_delete_tag_registry(state->tag_registry);
|
|
|
|
if(state->app_name != NULL)
|
|
|
|
free(state->app_name);
|
2024-01-29 18:48:56 +00:00
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: This function should start a new thread with a worker system.
|
|
|
|
void mt_start(MtState state)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
2024-01-30 21:31:31 +00:00
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity * mt_summon(MtState *state)
|
2024-01-30 21:31:31 +00:00
|
|
|
{
|
|
|
|
return mt_create_entity(state, state->entity_registry.entity_id_counter++);
|
|
|
|
}
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
void mt_drop(MtEntity *entity)
|
2024-01-30 21:31:31 +00:00
|
|
|
{
|
2024-01-30 21:47:43 +00:00
|
|
|
MtState *state = entity->parent_state;
|
2024-01-30 21:31:31 +00:00
|
|
|
|
|
|
|
mt_delete_entity_data(entity);
|
|
|
|
mt_give_back_entity_pool_slot(&state->entity_registry.pool, state->entity_registry.pool.first_free);
|
|
|
|
}
|