Networking · interface

LockstepOptions

Explained in Networking and rollback.

interface LockstepOptions<S>
import type { LockstepOptions } from '@driftengine/network';

Properties

NameTypeDescription
transportreadonlyTransport
loopreadonlyRewindLoop<S>
inputsreadonlyInputLog
selfreadonlyPeerIdThis peer's id, and the index its inputs occupy in the log.
participantsreadonlynumber
inputDelayreadonlyoptionalnumberHow many ticks ahead a local input is published. Two is 33 ms at 60 Hz.
More

See the header: inside this budget the session is exact rather than convergent.

fingerprintEveryreadonlyoptionalnumberHow often a fingerprint is published, in ticks. Every tick is wasteful and every hundred is slow to notice; the default is every eight, which at 60 Hz is seven a second.
compareStatesreadonlyoptionalbooleanPublish fingerprints at all. Off needs no digest from the snapshotter.
redundancyreadonlyoptionalnumberHow many recent inputs ride along in every packet. Four by default.
More

This is what makes lockstep survive loss, and one is not enough. An input is only useful for the tick it names, so asking for a lost one and waiting a round trip delivers it after that tick has gone — the peer's world is then permanently different and nothing local repairs it. Sending the last few in every packet covers a run of drops before anybody notices, for a handful of bytes on a message that already has a header.

Four covers three consecutive losses. A link losing four in a row at 60 Hz has stopped being a link.

It may reach further back than the rewind window without any arrangement between the two. The session forgets inputs below the oldest tick a rewind can reach, so past that depth every packet's oldest words name ticks the log can no longer say anything about. Those are skipped on the strength of what this world already applied, not on what the log still holds — see the watermark in receive. Choose this number for the link and the rewind depth for the game.