@clockwork2/engine
v0.11.0
Published
A deterministic, fixed-step game kernel for verifiable browser games
Readme
@clockwork2/engine
The simulation kernel behind Clockwork 2: a fixed-step loop, deterministic maths, seeded randomness and recordings that replay to the same bits on V8, JavaScriptCore and SpiderMonkey.
It has no runtime dependencies and imports no DOM types. Everything it needs is vendored, with attribution in the repository's NOTICE.
import { Prng, runSession } from "@clockwork2/engine"
import * as dmath from "@clockwork2/engine/dmath"A game implements eight methods and no base class: init, tick, view,
snapshot, restore, score, isOver, effects, and packsNeeded when it
reads data packs. tick() takes no time
delta, so a simulation cannot depend on the player's frame rate.
Math.sin, Math.pow and the rest of the transcendentals are
implementation-defined, and they really do differ: Math.cos(0.1) is
0x3FEFD712F9A817C1 on JavaScriptCore and 0x3FEFD712F9A817C0 on V8.
dmath ships the same function names, transcribed from fdlibm using only
operations ECMAScript specifies exactly.
The package carries clockwork2, an agent guide for writing a game on it, at
skill/clockwork2/: the rules a simulation has to follow, a section per error
code, scripts that run the engine's conformance checks, and two starter
templates. Point a coding agent's tools at
node_modules/@clockwork2/engine/skill/clockwork2/ to install it, and run its
scripts from the game's own root.
docs/engine.md in the repository explains the whole design from first
principles.
MIT.
