Networking · class
StateInterpolator
Two authoritative states and where between them to draw.
Explained in Networking and rollback.
class StateInterpolatorimport { StateInterpolator } from '@driftengine/network';In depth
Rendering at a delay is what stops a remote body teleporting. States arrive every few ticks and unevenly; drawing the newest one puts a body wherever the last packet said, which on a jittery link is a stutter. Drawing between the two most recent, a fixed distance behind the newest, costs that distance in latency and buys smooth motion — and the latency is honest, because the position shown is one the authority actually published rather than one guessed forward.
This owns the timing and none of the content: sample answers which two payloads and how far
between, and the consumer decodes and blends. It cannot do otherwise, since the payload's shape is
the consumer's.
Constructor
new
constructor(capacity?: number, maxBytes?: number, delayTicks?: number)| Parameter | Type | Description |
|---|---|---|
capacity? | number | |
maxBytes? | number | |
delayTicks? | number |
Properties
| Name | Type | Description |
|---|---|---|
delayTicksreadonly | number |
Methods
push
push(tick: number, payload: Uint8Array): voidKeep a state. The bytes are copied, because the transport reuses its buffer.
| Parameter | Type | Description |
|---|---|---|
tick | number | |
payload | Uint8Array |
sample
sample(renderTick: number): { from: Uint8Array; to: Uint8Array; alpha: number; } | nullThe two states to blend at renderTick, and how far between them, or null.
| Parameter | Type | Description |
|---|---|---|
renderTick | number |
More
alpha is clamped to [0, 1]: past the newest state it holds there rather than extrapolating,
which is the same choice TickTrace.sample makes at the end of a recording and for the same
reason — a character who has finished should look like they finished.