Skip to content

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.

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.

Terminal window
cc -std=c17 -I. main.c siecs.c -pthread -o app
./app

Use #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.

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.

How SIECS concepts fit togetherThe active world owns entities and resources. Components, tags, and relations give entities a structural type, which places them in an archetype table. Queries select tables. Systems run those queries in phases; observers react to events through query filters. Modules group registrations.SIECS / CONCEPT MAPWORLD DATASTORAGE & SELECTIONBEHAVIORORGANIZATION & ORDERWorldone active runtimeEntityidentity and lifetimeComponent / tagdata or markerRelationsource → targetResourceone value per worldStructural typethe entity's signatureArchetype tablepacked column storageQuerycached table matchesEventa change or custom signalObserverreacts when matchedSystemruns a query callbackModulegroups registrationsPhaseorders system execution
Worldone active runtime
owns ↓
Entityidentity and lifetime
Resourceone value per world
entity structure ↓
Component / tagdata or marker
Relationsource → target
determines ↓
Structural typethe entity's signature
places entities in ↓
Archetype tablepacked column storage
matched by ↓
Querycached table matches
drives ↓
Observerreacts to an event
Systemruns in a phase
registrations are grouped by ↓
Modulecomponents, systems, observers
Follow the arrows from entity structure to table storage, then to matching queries and behavior.

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;
}

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.

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);

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.

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);

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);

A tag still contributes to the entity’s structural type. See Entities and Components.

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);

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.

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);

Killing a parent recursively cleans up its owned ChildOf subtree. Hierarchy queries can order matching tables by depth. See Hierarchies.

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 C

A 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.

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 });

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);

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.

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_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 → EcsPostRender

SIECS also has one-shot startup phases. Custom phases and explicit system dependencies can refine the order. See Phases and scheduling.

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,
});

SIECS also supports relation events and custom events. Observer callbacks run as part of the event flow, rather than once per frame. See Observers.

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,
});

Disabling a module disables systems and observers it registered without deleting entity data. The declarations and import callback live in Modules.

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;
}

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.

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.