Networking · interface

Snapshotter

Somewhere state can be put and taken back.

Explained in Networking and rollback.

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

In depth

Generic over its own slot type, so a rewind needs no serialization at all: a snapshot never leaves the process. @driftengine/entities supplies one implementation through worldSnapshotter, and a consumer whose simulation state is four typed arrays writes another in thirty lines without touching anything here. That is the AGENTS.md rule about platform capabilities applied to state.

Methods

create

create(): S

A reusable slot. Called once per ring position, never on a tick.

save

save(into: S): void
ParameterTypeDescription
intoS

restore

restore(from: S): void
ParameterTypeDescription
fromS

digestoptional

digest?(from: S): string

A hash of what a slot holds, for comparing this peer's world against another's.

ParameterTypeDescription
fromS
More

On the snapshotter rather than beside it, because the thing that knows how to save state is the thing that knows how to hash it. A consumer with their own state writes one function and both mechanisms work; two seams would mean writing it twice and keeping them in step.

Optional: a session that never compares worlds needs none.