Networking · class
LockstepSession
Explained in Networking and rollback.
class LockstepSession<S>import { LockstepSession } from '@driftengine/network';Constructor
new
constructor(options: LockstepOptions<S>)| Parameter | Type | Description |
|---|---|---|
options | LockstepOptions<S> |
Properties
| Name | Type | Description |
|---|---|---|
selfreadonly | PeerId | |
participantsreadonly | number | |
inputDelayreadonly | number |
Accessors
| Name | Type | Description |
|---|---|---|
statusget | LockstepStatus | |
reasonget | string | Why the session halted, or an empty string. |
desyncget | Desync | null | The disagreement that halted it, naming the tick it began at. |
confirmedget | number | The highest tick every participant's real input has arrived for. |
rewindDepthget | number | How many ticks back the session can rewind: its loop's snapshot ring.MoreThe 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. |
digestBuilderget | Fingerprint | The shared digest builder, for a consumer whose digestAt wants one without allocating. |
Methods
submit
submit(tick: number, payload: Uint8Array): voidPublish this peer's input for tick + inputDelay, and record it locally at the same tick.
| Parameter | Type | Description |
|---|---|---|
tick | number | |
payload | Uint8Array |
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(): voidTake 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): voidAdvance one tick, then publish a fingerprint if this is a tick to publish one at.
| Parameter | Type | Description |
|---|---|---|
dt | number | |
tick | number |
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): voidStop the session with a reason. Public so a consumer can halt on their own condition.
| Parameter | Type | Description |
|---|---|---|
reason | string |