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
Simulation<Input,Sim>
Type Parameters
| Type Parameter |
|---|
Input |
Sim |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
hashEvery? | number | How often to report the hash, in turns. Defaults to 20. | client/lockstep.ts:32 |
bufferTurns? | number | How 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? | TokenSource | Supplies 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? | boolean | Ask the room for its patches in binary: see RoomClientOptions.binary. | client/lockstep.ts:54 |
Methods
hash()?
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
| Parameter | Type |
|---|---|
sim | Sim |
Returns
string | number
onTurn()?
onTurn?(sim, turn): void;Defined in: client/lockstep.ts:41
The simulation advanced to turn. Not called while catching up after (re)connecting.
Parameters
| Parameter | Type |
|---|---|
sim | Sim |
turn | number |
Returns
void
onReady()?
onReady?(sim, turn): void;Defined in: client/lockstep.ts:43
The simulation has caught up with the room and is live.
Parameters
| Parameter | Type |
|---|---|
sim | Sim |
turn | number |
Returns
void
onDesync()?
onDesync?(turn): void;Defined in: client/lockstep.ts:45
Two players' simulations differed at turn.
Parameters
| Parameter | Type |
|---|---|
turn | number |
Returns
void
onStatus()?
onStatus?(status, detail?): void;Defined in: client/lockstep.ts:47
The connection's status changed: see RoomClientOptions.onStatus.
Parameters
| Parameter | Type |
|---|---|
status | ConnectionStatus |
detail? | CloseDetail |
Returns
void
loadReplay()?
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
| Parameter | Type |
|---|---|
url | string |
Returns
Promise< | Replay<Input> | CatchUp<Input>>
sendSnapshot()?
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
| Parameter | Type |
|---|---|
url | string |
data | string |
Returns
Promise<unknown>
create()
create(seed): Sim;Defined in: lockstep.ts:114
Build the simulation at turn 0. Everything random must come from seed.
Parameters
| Parameter | Type |
|---|---|
seed | number |
Returns
Sim
Inherited from
step()
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
| Parameter | Type |
|---|---|
sim | Sim |
entries | TurnEntry<Input>[] |
turn | number |
Returns
void
Inherited from
save()?
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
| Parameter | Type |
|---|---|
sim | Sim |
Returns
unknown
Inherited from
load()?
load?(saved): Sim;Defined in: lockstep.ts:124
The simulation save was given, rebuilt from what it returned.
Parameters
| Parameter | Type |
|---|---|
saved | unknown |
Returns
Sim