Skip to content

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 ParameterDefault type
Inputunknown
Simunknown

Constructors ​

Constructor ​

ts
new LockstepClient<Input, Sim>(url, options): LockstepClient<Input, Sim>;

Defined in: client/lockstep.ts:119

Parameters ​

ParameterType
urlstring | URL
optionsLockstepClientOptions<Input, Sim>

Returns ​

LockstepClient<Input, Sim>

Accessors ​

sim ​

Get Signature ​

ts
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 ​

ts
get turn(): number;

Defined in: client/lockstep.ts:156

The turn the simulation is at.

Returns ​

number


ready ​

Get Signature ​

ts
get ready(): boolean;

Defined in: client/lockstep.ts:161

True once the simulation has caught up with the room.

Returns ​

boolean


status ​

Get Signature ​

ts
get status(): ConnectionStatus;

Defined in: client/lockstep.ts:166

Where the connection stands.

Returns ​

ConnectionStatus


you ​

Get Signature ​

ts
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() ​

ts
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 ​

ParameterType
inputInput

Returns ​

Promise<void>


leave() ​

ts
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() ​

ts
close(): void;

Defined in: client/lockstep.ts:186

Close the connection for good, keeping the seat. No reconnect follows.

Returns ​

void

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