Networking · class

LockstepSession

Explained in Networking and rollback.

class LockstepSession<S>
import { LockstepSession } from '@driftengine/network';

Constructor

new

constructor(options: LockstepOptions<S>)
ParameterTypeDescription
optionsLockstepOptions<S>

Properties

NameTypeDescription
selfreadonlyPeerId
participantsreadonlynumber
inputDelayreadonlynumber

Accessors

NameTypeDescription
statusgetLockstepStatus
reasongetstringWhy the session halted, or an empty string.
desyncgetDesync | nullThe disagreement that halted it, naming the tick it began at.
confirmedgetnumberThe highest tick every participant's real input has arrived for.
rewindDepthgetnumberHow many ticks back the session can rewind: its loop's snapshot ring.
More

The loop stays private, because a caller stepping it beside the session would desynchronise the two; this is the one number a readout wants from it.

digestBuildergetFingerprintThe shared digest builder, for a consumer whose digestAt wants one without allocating.

Methods

submit

submit(tick: number, payload: Uint8Array): void

Publish this peer's input for tick + inputDelay, and record it locally at the same tick.

ParameterTypeDescription
ticknumber
payloadUint8Array
More

Recorded locally as well as sent, and that is not redundancy. A peer's own input is not echoed back to it, so without this the local simulation would predict its own controls — and a player would feel their own input arrive late and get corrected, which is the one thing prediction is supposed to prevent.

poll

poll(): void

Take everything the transport has and apply it.

More

Called once per tick, before advancing. Never from a transport callback — see transport.ts for why a message must not arrive in the middle of a step.

advance

advance(dt: number, tick: number): void

Advance one tick, then publish a fingerprint if this is a tick to publish one at.

ParameterTypeDescription
dtnumber
ticknumber
More

The rewind loop performs any pending correction first, so a late input that arrived during poll is applied before this tick runs rather than after it.

halt

halt(reason: string): void

Stop the session with a reason. Public so a consumer can halt on their own condition.

ParameterTypeDescription
reasonstring