Quickstart
This page gives you a working SIECS program and a map of the concepts behind it. Each example is short; the linked manuals cover the details.
SIECS is an archetype ECS with a C17 runtime and a typed C++20 API. Both languages use the same active world.
Building SIECS
Section titled “Building SIECS”For a standalone project, copy distr/siecs.h and distr/siecs.c next to your
application. The single header contains both the C API and the C++ facade.
cc -std=c17 -I. main.c siecs.c -pthread -o app./appcc -std=c17 -I. -c siecs.c -pthread -o siecs.oc++ -std=c++20 -I. main.cpp siecs.o -pthread -o app./appUse #include <siecs.h> in either language. The C++ API is header-only, but
both programs link the C runtime. For a project using Bake, see the
Bake example in the repository.
Concepts
Section titled “Concepts”The diagram shows how SIECS stores data and finds the work to run. Start with an entity: its components and relations determine a structural type, which places it in an archetype table. A query caches matching tables; systems and observers use queries to select entities.
The world owns all ECS state: entities, tables, resources, queries, systems, observers, and registrations. Initialize it before creating anything and finalize it after ECS work stops.
#include <siecs.h>
int main(void) { ecs_init();
/* Create entities and run systems here. */
ecs_fini(); return 0;}#include <siecs.h>
int main() { ecs::init();
// Create entities and run systems here.
ecs::fini();}SIECS has one active world at a time. Component IDs, resource IDs, query
IDs, and entity handles belong to that world. ecs_init_w_features() /
ecs::init({...}) can also configure worker threads and a target frame rate.
Entity
Section titled “Entity”An entity is a generation-aware identity, not an object containing its components. A new entity is alive and has no user components.
ecs_entity_t e = ecs_new();bool alive = ecs_is_alive(e); /* true */ecs_kill(e);auto e = ecs::spawn();bool alive = e.is_alive(); // truee.kill();The 64-bit handle contains an index and generation. Reusing an index after deletion changes its generation, so an old handle does not become the new entity. See Entities and Components for lifetime and naming.
SIECS uses separate ID spaces for components and tags
(ecs_component_t), relations (ecs_relation_id_t), resources
(ecs_resource_t), queries, systems, observers, and modules. An entity handle
is not a component ID or a relation ID.
This matters when reading the API: ecs_id(Position) identifies a component,
while ecs_rid(ChildOf) identifies a relation. SIECS does not encode every
concept as an entity ID or a universal pair.
Component
Section titled “Component”A component stores typed data for each entity that owns it. C code declares and registers the type; the C++ facade registers ordinary C++ types when used.
ECS_COMPONENT(Position, { float x; float y; });
ECS_COMPONENT_REGISTER(Position);ecs_entity_t e = ecs_new();ecs_set(e, Position, { .x = 10, .y = 20 });
const Position *p = ecs_get(e, Position);ecs_remove(e, Position);struct Position { float x, y; };
auto e = ecs::spawn().set(Position{10, 20});const Position &p = e.get<Position>();e.remove<Position>();Setting a component adds it if needed. Adding or removing a component changes the entity’s structural type and can move it to another table. Changing the value of an existing component leaves it in the same table.
A tag is a component with no payload. It can mark entities and filter queries without allocating a data column.
ECS_TAG(Enemy);
ECS_COMPONENT_REGISTER(Enemy);ecs_add(e, Enemy);struct Enemy {};
e.add<Enemy>();A tag still contributes to the entity’s structural type. See Entities and Components.
Relation
Section titled “Relation”A relation connects one source entity to one target for a registered relation kind. Relations have their own registry and storage policies; they are not general-purpose pair IDs.
ECS_RELATION(Follows, { .storage = EcsRelationByTarget, .on_delete_target = EcsRemoveRelation, .acyclic = false,});
ECS_RELATION_REGISTER(Follows);ecs_relate(follower, Follows, leader);ecs_entity_t target = ecs_target(follower, Follows);struct Follows {};
ecs::relation<Follows>({ .storage = EcsRelationByTarget, .on_delete_target = EcsRemoveRelation, .acyclic = false,});follower.relate<Follows>(leader);auto target = follower.target<Follows>();SIECS supports dense, depth-indexed, and target-indexed relation storage. Choose according to the traversal or query you need. See Relationships for storage and target-deletion rules.
Hierarchy
Section titled “Hierarchy”ChildOf is SIECS’s built-in parent relation. A child stores an edge to its
parent; it does not contain a copy of its parent.
ecs_relate(child, ChildOf, parent);ecs_entity_t current_parent = ecs_target(child, ChildOf);child.child_of(parent);auto current_parent = child.target<ChildOf>();Killing a parent recursively cleans up its owned ChildOf subtree. Hierarchy
queries can order matching tables by depth. See Hierarchies.
Structural type and archetype table
Section titled “Structural type and archetype table”An entity’s structural type is its exact set of owned components, tags, and structural relation state. Each distinct type maps to an archetype table.
{Position} → table A{Position, Velocity} → table B{Position, Velocity, Enemy} → table CA table holds packed entity rows and a contiguous column for each data-bearing
component. Tags affect table identity but have no data column. Adding
Velocity to an entity in table A moves it to table B; updating the existing
Position.x value does not move it.
Applications normally change types with component and relation operations rather than manipulating structural types directly. See SIECS Archetype Storage for table migration and pointer lifetime.
Resource
Section titled “Resource”A resource is one typed value for the whole world. It is separate from per-entity components and never becomes a table column.
ECS_RESOURCE(Time, { float dt; });
ECS_RESOURCE_REGISTER(Time);ecs_set_resource(Time, { .dt = 1.0f / 60.0f });struct Time { float dt; };
ecs::resource<Time>().set(Time{1.0f / 60.0f});Systems can declare resource access so the scheduler can account for it. See Resources.
A query selects entities by matching their archetype tables. A persistent query caches those table matches, then exposes each non-empty table as a batch.
ecs_query_id_t q = ecs_query({ .components = { ecs_inout(Position), ecs_in(Velocity), },});
ecs_iter_t it = ecs_query_iter(q);while (ecs_iter_next(&it)) { Position *p = ecs_field(&it, 0); const Velocity *v = ecs_field(&it, 1); for (uint32_t i = 0; i < it.count; i++) { p[i].x += v[i].x; p[i].y += v[i].y; }}ecs_query_fini(q);auto q = ecs::query().build();q.each([](Position &p, const Velocity &v) { p.x += v.x; p.y += v.y;});The C access terms declare read/write intent. The typed C++ callback declares the component fields it needs. Queries also support optional and excluded components, relation filters, and inherited reads. See Queries.
System
Section titled “System”A system is a persistent query plus a callback and scheduling information. SIECS invokes its callback for each matching table batch.
static void Move(ecs_iter_t *it) { Position *p = ecs_field(it, 0); const Velocity *v = ecs_field(it, 1);
for (uint32_t i = 0; i < it->count; i++) { p[i].x += v[i].x; p[i].y += v[i].y; }}
ecs_system({ .name = "Move", .phase = EcsOnUpdate, .query.components = { ecs_inout(Position), ecs_in(Velocity), }, .callback = Move,});ecs::system("Move") .phase(EcsOnUpdate) .each([](Position &p, const Velocity &v) { p.x += v.x; p.y += v.y; });ecs_progress() / ecs::progress() runs enabled systems in phase order.
Structural mutations inside a normal system are deferred so table iteration
stays valid. See Systems.
A phase determines when scheduled systems run. The recurring sequence is:
EcsOnLoad → EcsPostLoad → EcsPreUpdate → EcsOnUpdate → EcsPostUpdate → EcsPreRender → EcsOnRender → EcsPostRenderSIECS also has one-shot startup phases. Custom phases and explicit system dependencies can refine the order. See Phases and scheduling.
Observer and event
Section titled “Observer and event”Observers react to events such as adding, removing, or setting a component. The event identifies what happened; the observer’s query filters which entities may trigger its callback.
static void OnPositionSet(ecs_observer_event_t *event) { const Position *value = event->trigger_data; /* event->entity received this Position value. */ (void)value;}
ecs_observer({ .on = EcsOnSet, .query.components = { ecs_in(Position) }, .callback = OnPositionSet,});ecs::observe<ecs::OnSet>() .each([](ecs::entity e, const Position &value) { // e received this Position value. (void)e; (void)value; });SIECS also supports relation events and custom events. Observer callbacks run as part of the event flow, rather than once per frame. See Observers.
Module
Section titled “Module”A module groups component, relation, system, and observer registrations behind one import. Importing it again does not duplicate its registrations.
ecs_module_id_t physics = ECS_MODULE_IMPORT(physics, { .gravity = 9.81f,});auto physics = ecs::import<Physics>(9.81f);Disabling a module disables systems and observers it registered without deleting entity data. The declarations and import callback live in Modules.
A complete minimal program
Section titled “A complete minimal program”This program creates an entity with Position and Velocity, runs a Move
system once, and checks the result.
#include <siecs.h>
ECS_COMPONENT(Position, { float x; float y; });ECS_COMPONENT(Velocity, { float x; float y; });
static void Move(ecs_iter_t *it) { Position *p = ecs_field(it, 0); const Velocity *v = ecs_field(it, 1);
for (uint32_t i = 0; i < it->count; i++) { p[i].x += v[i].x; p[i].y += v[i].y; }}
int main(void) { ecs_init(); ECS_COMPONENT_REGISTER(Position); ECS_COMPONENT_REGISTER(Velocity);
ecs_system({ .name = "Move", .phase = EcsOnUpdate, .query.components = { ecs_inout(Position), ecs_in(Velocity), }, .callback = Move, });
ecs_entity_t e = ecs_new(); ecs_set(e, Position, { .x = 0, .y = 0 }); ecs_set(e, Velocity, { .x = 1, .y = 0 });
ecs_progress(); const Position *p = ecs_get(e, Position); bool moved = p != NULL && p->x == 1.0f;
ecs_fini(); return moved ? 0 : 1;}#include <siecs.h>
struct Position { float x, y; };struct Velocity { float x, y; };
int main() { ecs::init();
ecs::system("Move") .phase(EcsOnUpdate) .each([](Position &p, const Velocity &v) { p.x += v.x; p.y += v.y; });
auto e = ecs::spawn() .set(Position{0, 0}) .set(Velocity{1, 0});
ecs::progress(); bool moved = e.get<Position>().x == 1.0f;
ecs::fini(); return moved ? 0 : 1;}Setting Position puts the entity in a {Position} table. Adding Velocity
moves it to {Position, Velocity}. The system’s query matches that table and
iterates its contiguous component columns. This is the execution path shown
in the concept map.
Continue learning
Section titled “Continue learning”Read Entities and Components for entity and component semantics, SIECS Archetype Storage for table transitions, Queries for matching, and Systems for scheduling and deferred changes.

