Skip to content

Interface: LockstepClientOptions<Input, Sim> ​

Defined in: client/lockstep.ts:21

The simulation to run, what to report and how to connect. create and step are required. With save and load as well, the client sends the room snapshots and starts from one when it joins late.

Extends ​

Type Parameters ​

Type Parameter
Input
Sim

Properties ​

PropertyTypeDescriptionDefined in
hashEvery?numberHow often to report the hash, in turns. Defaults to 20.client/lockstep.ts:32
bufferTurns?numberHow many turns to hold back so that the simulation advances at an even pace when the network delivers turns unevenly. Defaults to 1, which adds one turn of delay and absorbs up to one turn of jitter. 0 applies every turn the moment it arrives.client/lockstep.ts:39
token?TokenSourceSupplies the join token, instead of putting one in the URL: see RoomClientOptions.token. Also asked before the recording is loaded.client/lockstep.ts:52
binary?booleanAsk the room for its patches in binary: see RoomClientOptions.binary.client/lockstep.ts:54

Methods ​

hash()? ​

ts
hash?(sim): string | number;

Defined in: client/lockstep.ts:30

A fingerprint of the simulation, at most 64 characters long. It is sent to the room every hashEvery turns, and the room flags the match if two players disagree. A simulation with save needs none: its hash is then fingerprint of what save returns, which covers everything saved. Give your own to hash less than that, for speed; a snapshot is then checked only as far as your hash goes.

Parameters ​

ParameterType
simSim

Returns ​

string | number


onTurn()? ​

ts
onTurn?(sim, turn): void;

Defined in: client/lockstep.ts:41

The simulation advanced to turn. Not called while catching up after (re)connecting.

Parameters ​

ParameterType
simSim
turnnumber

Returns ​

void


onReady()? ​

ts
onReady?(sim, turn): void;

Defined in: client/lockstep.ts:43

The simulation has caught up with the room and is live.

Parameters ​

ParameterType
simSim
turnnumber

Returns ​

void


onDesync()? ​

ts
onDesync?(turn): void;

Defined in: client/lockstep.ts:45

Two players' simulations differed at turn.

Parameters ​

ParameterType
turnnumber

Returns ​

void


onStatus()? ​

ts
onStatus?(status, detail?): void;

Defined in: client/lockstep.ts:47

The connection's status changed: see RoomClientOptions.onStatus.

Parameters ​

ParameterType
statusConnectionStatus
detail?CloseDetail

Returns ​

void


loadReplay()? ​

ts
loadReplay?(url): Promise<
  | Replay<Input>
| CatchUp<Input>>;

Defined in: client/lockstep.ts:60

How to load the recording when (re)connecting. Defaults to fetch on the room's /replay URL. The URL says what the client has already, and the room may answer with only the rest: see CatchUp.

Parameters ​

ParameterType
urlstring

Returns ​

Promise< | Replay<Input> | CatchUp<Input>>


sendSnapshot()? ​

ts
sendSnapshot?(url, data): Promise<unknown>;

Defined in: client/lockstep.ts:62

How to send the room a snapshot. Defaults to a POST of data to url with fetch.

Parameters ​

ParameterType
urlstring
datastring

Returns ​

Promise<unknown>


create() ​

ts
create(seed): Sim;

Defined in: lockstep.ts:114

Build the simulation at turn 0. Everything random must come from seed.

Parameters ​

ParameterType
seednumber

Returns ​

Sim

Inherited from ​

Simulation.create


step() ​

ts
step(
   sim, 
   entries, 
   turn
): void;

Defined in: lockstep.ts:116

Advance by one turn. Must be deterministic: same simulation and entries in, same simulation out.

Parameters ​

ParameterType
simSim
entriesTurnEntry<Input>[]
turnnumber

Returns ​

void

Inherited from ​

Simulation.step


save()? ​

ts
save?(sim): unknown;

Defined in: lockstep.ts:122

The simulation as JSON: everything step reads, the random generator's state included. With load, it lets a player who joins or reloads late start from a recent snapshot instead of from turn 1.

Parameters ​

ParameterType
simSim

Returns ​

unknown

Inherited from ​

Simulation.save


load()? ​

ts
load?(saved): Sim;

Defined in: lockstep.ts:124

The simulation save was given, rebuilt from what it returned.

Parameters ​

ParameterType
savedunknown

Returns ​

Sim

Inherited from ​

Simulation.load

MIT licence. Tickflare is an independent project and is not affiliated with Cloudflare.