Docs
Architecture
The library boundary
Emden gives an application a world it can build, query, and change. The application owns that world and calls its systems in the order its rules require. The host supplies input and timing and handles drawing, networking, or persistence. A headless test can drive the same systems with recorded inputs and compare the resulting view.
- Host inputSupply an action or a tick
- Application systemsValidate input and run the rules
- Emden worldRead and update typed components
- Application outputSend events and a view to the host
From entity handle to component
Each Store<T> is a sparse set. Its sparse index maps entity slots to rows in two packed arrays. One holds the entity slots and the other holds the component values. A join walks the smaller store and checks the other store’s index for the same slots.
Position component- Entity handleCheck world, slot 5, and generation
- Sparse indexSlot 5 maps to dense row 1
- Dense row 1Entity slot 5 and
Position { x: 8 } - Caller’s variable
readcopies out the position
When a removal leaves a gap, Emden fills it with the last row and repairs the moved entity’s sparse index. That entity keeps the same handle.
When edits become visible
A system can replace existing values while it walks a query. Queue edits that change which entities or components exist, then flush at the end of the pass. Each command gets its own result. The flush continues in order after a rejected command.
- Visit current rowsRead or replace component values
- Enqueue editsRecord a spawn, removal, or despawn
- Flush in FIFO orderApply pending edits and return outcomes
- Start a fresh queryVisit rows after the edits
A successful structural edit invalidates existing cursors. The next pass starts a new query over the updated world.
What Goose provides
- Concrete component types
- Goose specializes
Store<Position>and its operations forPosition. Systems read and replace ordinary typed values. - Compile-time schema traversal
const forexpands bundle checks and cleanup across the schema fields. The generated operations address the game’s stores directly.- Bounded, inline storage
- Goose’s limited arrays reserve capacity when the world is constructed. Emden reuses rows within that budget and reports
Capacitywhen a store is full. - Named functions as system building blocks
flushspecializes on the named apply function supplied by the game. The application composes systems with ordinary Goose calls.
Goose checks reference lifetimes, and Emden checks whether an entity handle still names a live entity. Copying component values through the public API keeps row reuse behind the storage boundary. See the Goose language reference for generics, limited arrays, and function values.
Worlds and stores
World ownership
Pass a nonzero owner ID to world<Schema>. Pick an ID unique among the world instances whose handles your application can still use. Assign a new ID when calling reset. Every entity is a world ID, slot, and generation. Use a game-defined ID for saves, networking, and presentation.
Storage and capacity
A schema is a Goose struct with one Store<T> per component column. Use fixed-size component values. Each store has dense values and an index from entity slot to dense row. Pass the world entity capacity and a row capacity to store. A rare component can have a smaller dense capacity. The sparse index reserves four bytes per possible entity slot in each store.
Declare each live world as an independent value. Worlds embed runtime-sized stores and cannot be randomly indexed in an array. Keep the schema with its owning world and use the API for access to storage.
Entities and components
spawn(world) makes an empty entity. To spawn a bundle, give a fixed-size struct whose field names and types match the target columns. spawn(world, bundle) checks those columns and the entity budget before changing the world. despawn clears every component, and the next occupant gets a new generation.
insert adds a missing component, replace updates a present component, and remove deletes a component. read copies a value into your output variable on success. has checks presence. These operations validate the entity and store against the world.
Queries and passes
Queries and joins
query visits one store. join visits entities in both stores and drives from the smaller column. Pass the same stores to next. The result is an entity on Ok and Done at the end.
For a typed selection, declare a projection struct whose field names and types match stores in the world. Call select<Projection>(world, filters), then next(world, cursor, values) to copy the matching values and return the entity. Filter field names also match stores. Give each filter field a value of Presence.With or Presence.Without. Emden drives from the smallest required store. Order game logic by a stable game ID when outcomes depend on ordering.
Creating or removing an entity or component invalidates active cursors. replace updates values while a cursor is active. Start a new cursor after applying structural edits.
Deferred changes
Define an enum for the structural edits your game queues. Construct a bounded queue<Command> and enqueue commands during a system. Pass a named apply function to flush after the pass. The queue is FIFO and reports Capacity when full.
flush processes the commands that were pending at entry. It returns an outcome for each command and continues after a rejected command. A successful spawn returns its entity in the outcome. Commands enqueued while applying the batch stay queued for the next flush. Use separately validated or staged game actions when a whole turn must commit together.
Host integration
A game owns its tick or turn, inputs, rules, events, and player-facing view. Call its named systems in the order you need. The host supplies timing and input and decides how to render or persist the result. The Godot example keeps engine handles, input mapping, and drawing in its adapter.
Pass a positive third argument to store<T> to keep a bounded history of added, updated, and removed components. Create a changes(store) cursor after taking a snapshot. Read next_change until it reports Done. Rebuild the snapshot on ChangesLost or world reset. The grid host uses these histories to refresh cached unit views after a turn.
Examples
Movement
Join position and velocity for two updates and inspect the final position. Download movement.goose.
mise run example:movementPosition after two steps: 8
Grid skirmish
Move a scout on a six-by-four grid, strike adjacent sentries, and watch the command flush remove defeated units. Enter l, r, u, d, strike, or wait. Enter q to quit.
mise run example:grid
mise run example:replayPerformance baseline
Run mise run bench to compare a direct indexed loop with a join and checked reads over 8,192 entities. The same program times despawn, slot reuse, and reinsertion for 4,096 entities. Both read paths verify their checksums.
Godot host
The optional Godot adapter runs the same grid module. Arrows move the scout, Enter or Space strikes, and Escape restarts. Configure CMake with a Godot Goose v0.0.2 checkout, Goose v2026.4, and Godot 4.7.2. Build the Godot example.