API Reference
The current public authoring surface: defineGame, schema-backed performance mode, ctx.world(), and mirror rendering.
defineGame(spec)
Creates a sealed, plain game module. It is a factory, not a constructor.
| Key | Required | Description |
|---|---|---|
initialState | Yes | Factory or plain object. Each call must produce object or array state. |
step(state, ctx) | Yes | Deterministic transition for one tick. No DOM, wall-clock, ambient randomness, or network access. |
draw(state, ctx) | No | Presentation callback for simple hosts. Performance-mode renderers usually read RenderMirror instead. |
sampleInput(ctx) | No | Default local input sampler. Hosts may override or wrap it. |
Schema Helpers
V0.2/V0.3 performance mode uses declared schemas so the backend can snapshot, hash, patch, transfer, and mirror canonical rows.
| Helper | Description |
|---|---|
schemaScalar(type) | Declares one scalar field: 'number', 'string', or 'boolean'. |
schemaRecord(fields) | Declares a flat row of scalar fields. |
schemaTable(record, options) | Declares a keyed table. Use { id: 'string', order: 'id' } for stable game-owned ids. |
step(ctx) In Schema-Generated Mode
The engine creates PerformanceModeEngineContext for schema-backed steps. Prefer ctx.world() for release-facing authoring.
| World member | Description |
|---|---|
world.tick, world.dt | Deterministic tick metadata. |
world.get(Class, id) | Returns a wrapper for Class.table and id, or null. |
world.all(Class) | Iterates wrappers from the class-bound table. |
world.spawn(Class, id, record, options?) | Creates a schema row and returns a wrapper. |
world.destroy(entityOrClass, id?, options?) | Destroys a row by wrapper or class/id. |
world.input(playerId) | Reads the game input payload through the engine query path. |
world.query(id, queryCtx, predicate) | Lower-level routed query access for rollback-aware input reads. |
world.participants() | Returns current admitted participants. |
world.discoverParticipants(predicate, limit) | Admits discoverable participants deterministically. |
world.table(name), world.state | Advanced access to declared schema tables and live schema state. |
Lower-Level Context Members
The lower-level context API remains available when explicit table handles are clearer: ctx.entity, ctx.entities, ctx.spawn, ctx.destroy, ctx.query, ctx.participants, and ctx.discoverParticipants.
Rendering API
Performance-mode renderers read RenderMirror. A mirror consumes mirror.snapshot anchors and mirror.patch updates carried over em.bus.anchor and em.bus.mirror frames. Render code must not read live backend wrappers or make renderer state authoritative.
const pacmen = mirror.tryTable('pacmen');
if (pacmen) {
for (const row of pacmen.values()) drawPacman(row);
}
Runtime Infrastructure
TrysteroTransport is the browser P2P transport used by standalone demos. BusManager, BusRuntimeAdapter, WorkerRenderHost, scheduled buses, and workers are V0.3 runtime infrastructure for moving inputs and mirror data. They are not a separate authoring API; the same schema-backed step(ctx) and mirror renderer stay in use.
Legacy Facade
The older EasyMultiplayer callback facade with defineInput, on('tick'), on('draw'), and manageState still exists for compatibility and historical examples. New docs and new games should start with defineGame or schema-backed performance mode.