/**
 * @file entity.c
 * @author Piotr Krygier (piotrkrygier@everyonencancode.xyz)
 * @brief Entity from ECS
 * @version 0.1
 * @date 2025-09-25
 *
 * @copyright Copyright (c) 2025
 *
 */

#include "utilities/entity.h"
#include <stdint.h>

static entity_t g_free_list[ENTITY_MAX_COUNT];
static uint32_t g_free_count = 0U;
static uint32_t g_living_count = 0U;

entity_t entity_create(void)
{
    entity_t e = 0U;
    if (g_free_count > 0) {
        e = g_free_list[g_free_count--];
    } else {
        e = g_living_count++;
    }

    return e;
}

void entity_free(entity_t entity)
{
    g_free_list[g_free_count++] = entity;
}
