#include "ecs_core.h" // Define component id storage (global symbol used by ecs_id(Position)) ecs_entity_t ecs_id(Position) = 0; static bool g_ecs_core_inited = false; static draw_square_fn g_draw_square = 0; // Simple placeholder render system: iterates Positions static void RenderSys(ecs_iter_t* it) { Position* p = ecs_field(it, Position, 1); if (!g_draw_square) return; for (int i = 0; i < it->count; i++) { g_draw_square(p[i].x, p[i].y, 0.1f, 1.0f, 1.0f, 1.0f, 1.0f); } } void ecs_core_init(ecs_world_t* world) { if (g_ecs_core_inited) return; // Register components ECS_COMPONENT_DEFINE(world, Position); // Systems: run every frame on update for Position ECS_SYSTEM(world, RenderSys, EcsOnUpdate, Position); g_ecs_core_inited = true; } void ecs_spawn_test_entities(ecs_world_t* world) { // Two entities with different positions ecs_entity_t e1 = ecs_new(world); ecs_set(world, e1, Position, { -0.3f, 0.0f }); ecs_entity_t e2 = ecs_new(world); ecs_set(world, e2, Position, { 0.3f, 0.0f }); } void ecs_core_set_draw_api(draw_square_fn draw_square) { g_draw_square = draw_square; }