Files
game-engine/src/game/ecs/ecs.c
2024-04-11 01:05:03 -04:00

67 lines
1.3 KiB
C

#include "ecs.h"
static void _ecs_function(ECS* self, ECSFunctionType type);
static void
_ecs_function(ECS* self, ECSFunctionType type)
{
for (s32 i = 0; i < ECS_COMPONENT_COUNT; i++)
{
ECSComponentList* list;
list = &self->lists[i];
ecs_component_list_function(list, type);
}
}
void
ecs_tick(ECS* self)
{
_ecs_function(self, ECS_FUNCTION_TICK);
}
void
ecs_update(ECS* self)
{
_ecs_function(self, ECS_FUNCTION_UPDATE);
}
void
ecs_draw(ECS* self)
{
vector_sort(&self->lists[ECS_COMPONENT_TEXTURE_QUAD].components, (SortCompareFunction)component_texture_quad_sort);
_ecs_function(self, ECS_FUNCTION_DRAW);
}
void
ecs_init(ECS* self, Renderer* renderer, Input* input, Resources* resources, Postprocessing* postprocessing)
{
self->renderer = renderer;
self->input = input;
self->resources = resources;
self->postprocessing = postprocessing;
for (s32 i = 0 ; i < ECS_COMPONENT_COUNT; i++)
ecs_component_list_init(&self->lists[i], self, ECS_COMPONENT_INFO[i]);
}
void
ecs_clear(ECS* self)
{
for (s32 i = 0 ; i < ECS_COMPONENT_COUNT; i++)
ecs_component_list_clear(&self->lists[i]);
self->nextID = 0;
}
void
ecs_free(ECS* self)
{
for (s32 i = 0 ; i < ECS_COMPONENT_COUNT; i++)
ecs_component_list_free(&self->lists[i]);
memset(self, '\0', sizeof(ECS));
}