Class: LockstepClient<Input, Sim>
Defined in: client/lockstep.ts:80
Plays in a lockstep room: sends this player's inputs, and runs the simulation over the turns the room sends back.
On every (re)connect the simulation catches up with the room and then follows the live turns, so a reload or a dropped connection ends up in exactly the same state as everyone else. A client that still has its simulation is sent the turns it missed. One that has none starts from the room's latest snapshot if the simulation has save, load and hash, and from turn 1 of the recording otherwise.
In a room whose turnClock is "players" the client also keeps time for it: one player's client at a time asks the room for each turn as it falls due, and the others stand by to take over. There is nothing to set up.
Type Parameters
| Type Parameter | Default type |
|---|---|
Input | unknown |
Sim | unknown |
Constructors
Constructor
new LockstepClient<Input, Sim>(url, options): LockstepClient<Input, Sim>;Defined in: client/lockstep.ts:119
Parameters
| Parameter | Type |
|---|---|
url | string | URL |
options | LockstepClientOptions<Input, Sim> |
Returns
LockstepClient<Input, Sim>
Accessors
sim
Get Signature
get sim(): Sim | undefined;Defined in: client/lockstep.ts:151
The simulation. Undefined until the first catch-up finishes.
Returns
Sim | undefined
turn
Get Signature
get turn(): number;Defined in: client/lockstep.ts:156
The turn the simulation is at.
Returns
number
ready
Get Signature
get ready(): boolean;Defined in: client/lockstep.ts:161
True once the simulation has caught up with the room.
Returns
boolean
status
Get Signature
get status(): ConnectionStatus;Defined in: client/lockstep.ts:166
Where the connection stands.
Returns
you
Get Signature
get you(): string | undefined;Defined in: client/lockstep.ts:171
This player's id, as the server knows it. Set once connected.
Returns
string | undefined
Methods
input()
input(input): Promise<void>;Defined in: client/lockstep.ts:176
Send an input. It takes effect in the turn the room puts it in, for everyone at once.
Parameters
| Parameter | Type |
|---|---|
input | Input |
Returns
Promise<void>
leave()
leave(): Promise<void>;Defined in: client/lockstep.ts:181
Give up the seat. Every simulation sees the player leave in the same turn. See RoomClient.leave.
Returns
Promise<void>
close()
close(): void;Defined in: client/lockstep.ts:186
Close the connection for good, keeping the seat. No reconnect follows.
Returns
void