/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "entitymanager.h" #include "assert/assert.h" #include "util/memory.h" #include "console/console.h" entitymanager_t ENTITY_MANAGER; void entityManagerInit(void) { memoryZero(&ENTITY_MANAGER, sizeof(entitymanager_t)); memorySet( ENTITY_MANAGER.entitiesWithComponent, COMPONENT_ID_INVALID, sizeof(entityid_t) * COMPONENT_TYPE_COUNT * ENTITY_COUNT_MAX ); consolePrint( "Entity Manager size: %zu bytes (%.2f KB)", sizeof(entitymanager_t), sizeof(entitymanager_t) / 1024.0f ); } entityid_t entityManagerAdd() { for(entityid_t i = 0; i < ENTITY_COUNT_MAX; i++) { if((ENTITY_MANAGER.entities[i].state & ENTITY_STATE_ACTIVE) != 0) continue; entityInit(i); return i; } assertUnreachable("No more entity IDs available"); return ENTITY_ID_INVALID; } void entityManagerDispose(void) { for(entityid_t i = 0; i < ENTITY_COUNT_MAX; i++) { if((ENTITY_MANAGER.entities[i].state & ENTITY_STATE_ACTIVE) == 0) continue; entityDispose(i); } }