Networking · class

InputLog

Explained in Networking and rollback.

class InputLog
import { InputLog } from '@driftengine/network';

Constructor

new

constructor(options: InputLogOptions)
ParameterTypeDescription
optionsInputLogOptions

Properties

NameTypeDescription
participantsreadonlynumber
depthreadonlynumber
inputBytesreadonlynumber

Accessors

NameTypeDescription
windowStartgetnumberThe oldest tick this log holds. Everything below it has been dropped.
windowEndgetnumberOne past the newest tick this log will accept.

Methods

holds

holds(tick: number): boolean

Whether a tick is inside the window at all.

ParameterTypeDescription
ticknumber

retain

retain(oldest: number): void

Move the window so oldest is the earliest tick kept, forgetting what falls off.

ParameterTypeDescription
oldestnumber
More

The slots that leave are cleared rather than left, because their slotTick would otherwise match a tick a whole window later and answer a stale input as a confirmed one.

set

set(participant: number, tick: number, payload: Uint8Array): boolean

Record a real input. true when this changed what the slot held, which is what tells a rewind whether it has anything to do. false also means refused, for a tick outside the window — see holds to tell the two apart when it matters.

ParameterTypeDescription
participantnumber
ticknumber
payloadUint8Array
More

A confirmed input matching the guess is the common case on a held control, and replaying for it would burn a rewind to produce the identical world.

into

into(participant: number, tick: number, out: Uint8Array): boolean

The input to simulate with, guessing and storing one if none has arrived.

ParameterTypeDescription
participantnumber
ticknumber
outUint8Array
More

false means it was guessed, or that the tick is outside the window, in which case out is zeroed. A caller deciding whether a tick can be confirmed reads that; a caller simulating does not care, because either way out holds the bytes this tick ran with, now and on every replay.

isConfirmed

isConfirmed(participant: number, tick: number): boolean

Whether a real input for this participant and tick has arrived.

ParameterTypeDescription
participantnumber
ticknumber

isComplete

isComplete(tick: number): boolean

Whether every participant's input for this tick has arrived. What lockstep advances on.

ParameterTypeDescription
ticknumber

confirmedThrough

confirmedThrough(upTo: number): number

The highest tick at or below upTo such that every tick from the window's start up to it is complete, or -1.

ParameterTypeDescription
upTonumber
More

Walked upward from the start of the window and stopped at the first gap, which is the property that matters: ticks 40 and 42 confirmed with 41 missing is not a session confirmed to 42, and answering 42 would let a peer discard the snapshot it still needs to correct 41.