The Simulation Runtime IS the Spine.

A small engine and scripting language for story-driven games, written in Zig. The world is a list of plain facts, characters follow scripts that can pause and resume, and any moment can be rewound and replayed.

Proofs of Concept

Classic Adventure & Systemic Proofs

Thirteen proofs of concept drive the engine end to end. Each runs without a window and checks its own outcome; twelve also rewind and check the world matches (the Saltmarket does not yet). They live in proofs/, depend on the engine through its public module, and build as a separate bespoke-proofs binary. Each card below opens that proof on its own page, where the deck runs the proof's own script in your browser.

The Architectural Pillars

Simulation as First Principle

Drawing spiritual inspiration from the deterministic clockwork of Chris Sawyer's RollerCoaster Tycoon, the actor/cue architecture of Sierra's SCI and LucasArts' SCUMM, and the emergent relationship graphs of Dwarf Fortress. BeSpoke counts time in whole steps (ticks) and stores the world as facts, so the same inputs always produce the same story.

PILLAR 01

Engine-as-Spine

The engine runs the game; the screen only shows it. The engine owns the clock, the characters, the map, and the facts. The window (SDL2 on the desktop, a canvas in the browser) draws what the engine reports and passes player input back; it never changes the world itself.

// A host starts a script, then asks for ticks
_ = try host.start_script(&world, &spatial, &vm, &compiled);
_ = try host.tick(&vm, &compiled);
PILLAR 02

Flat Relational State

Everything the game knows is a row of four values: (subject, relation, object, expires_at_tick), such as "the Guard carries the Cheese". A fact can carry an expiry tick, so a charm, a distraction, or an alarm ends on its own without cleanup code.

remember Carries(Guard, Cheese)
remember CharmedBy(Guard, Bard) for 180 ticks
PILLAR 03

Fibers & Time Travel

Write behaviour like a play script: a routine walks, waits, and speaks, and pauses with wait or wait until without blocking anything else. The facts sit in four flat columns, so a snapshot copies those columns and the name tables as raw bytes; rewinding copies them back.

walk Guard to Cellar
wait 5 ticks
walk Guard to Hearth
Dialogue

Dialogue That Reads the World

Adventure-game dialogue usually tracks what the player has said with a pile of yes/no flags. In BeSpoke, each dialogue option carries a condition written against the world's facts, and the option appears only while that condition holds. Both examples below are excerpts from the Brackwater Barbs proof's script.

Pattern 01 · Brackwater Barbs

A Duel Declared as Data

The script lists barb and comeback pairs; the engine's duel module turns them into facts (HeardBarb, MasteredComeback, Counters). Each round, the comebacks the player may choose are the ones they have learned, filtered through the same dialogue engine as every other choice. The dialogue text is shortened here.

duel BrackwaterBarbs:
  pair Barb1:
    challenge "..."
    reply "..."
    variant 1 "..."
  # fifteen pairs in all
  fallback "..."
  fallback "..."
  win 3
  relations HeardBarb MasteredComeback Counters VellVariant FencingTier Advantage DuelsWon
  fatigue Inquiries "welcoming":
    stage AnnoyedWith 2 100 "annoyed"
    stage FuriousWith 3 250 "furious"
Pattern 02 · Repetition & Fatigue

Characters Who Lose Patience

Ask the barkeep the same question twice and the answer changes. Each option checks a fact, and the annoyance is a fact that expires after 100 ticks, so the barkeep calms down on their own.

on cue TalksTo(Tamsin, Barkeep):
  choice "Tell me about Harbourmaster Odell." if not Inquired(Tamsin, Odell, _):
    say Barkeep: "Odell? Counts every barrel twice and trusts nobody once."
    remember Inquired(Tamsin, Odell, 1)
  choice "Tell me more about Harbourmaster Odell." if Inquired(Tamsin, Odell, 1):
    say Barkeep: "I've told you already. His office is above the customs shed."
    remember Inquired(Tamsin, Odell, 2)
    remember AnnoyedWith(Barkeep, Tamsin) for 100 ticks
  choice "About Harbourmaster Odell..." if AnnoyedWith(Barkeep, Tamsin):
    say Barkeep: "Ask me once more and you'll be drinking from the canal!"
    remember FuriousWith(Barkeep, Tamsin) for 250 ticks
Architecture

How the Engine Is Built

Three views of the same design: what owns the clock, how a player's action becomes a story beat, and how one script reaches every platform.

Engine-as-Spine

The engine is main(). A host only asks for the next tick; one discrete tick runs the VM, the rules, and the declared subsystems, all reading and writing one World of facts.

Hosts call host.tick, which drives the VM, rules, and subsystems around the World of facts. Hosts: window, headless, browser, tests input in; frame, speech, music out host.tick: one discrete tick VM fibers routines, cue handlers, wait Rules when, arrives, forgets Subsystems agendas, grids, containers World: facts (subject, relation, object, expires) one arena; saved, rewound, and branched whole

From Action to Story Beat

Nothing calls a cutscene. A cue changes facts, rules notice the combination on the next tick, and routines pause or resume around them. Speech and music are read from the result.

A cue runs a handler that writes facts; rules react; routines are interrupted and resume; output is read after the tick. Cue use match on lantern Handler remember Lit for 30 Facts Lit, Rung, Signalled Rules when Rung and Lit Routines interrupt, then resume where paused Read after the tick speech, scene, music, choices

One Script, Every Platform

A game is a .bespoke script. The engine's compiler turns it into a checked .bspk package, which the same runtime plays in a desktop window, headless in tests, or in the browser. The window and the browser draw the same frame with the same code; only how it reaches the screen differs.

A script compiles to a package that runs in a native window, headless tests, a bundled release, and the browser; the window and the browser draw the same frame. main.bespoke scenes, rules, scores bespoke compile errors stop the build .bspk checked on load Desktop window SDL shows the frame Bundled release Headless tests Browser (wasm) same frame, same code
Engine Architecture

Comparing Engine Philosophies

General-purpose engines are built around drawing frames, with game logic attached to the render loop. BeSpoke starts from the simulation and treats drawing as one consumer of it. The left column describes the common default, not every engine.

Dimension Visual-First Scene Graph Engine Simulation-First Relational Spine (BeSpoke)
Who owns main()? Graphics pipeline & frame-rate render loop The simulation, one whole tick at a time (1 per second by default; the display redraws at 60 Hz)
World State Representation Transform hierarchies, heap pointers & GC objects Rows of facts in one fixed block of memory
Time-Travel & Save States Custom serializers & object-graph reconstruction Copy the fact columns and name tables as raw bytes, with a checksum
Temporal Logic (Waiting, Routines) Delta-time accumulation, per-frame callbacks, state booleans Routines that pause with wait and resume on a later tick
Ephemeral State (Buffs, Alerts) Explicit timer handles & manual polling loops An expiry tick on the fact itself; the engine drops it when the clock passes
Toolchain & Footprint A large editor and runtime to install The Zig 0.13 toolchain; the core needs nothing else, and SDL2 only for the desktop window