mwg API
    Preparing search index...

    Class LockstepClient

    A client for this project's own reference lockstep server (tools/multiplayer-server.mjs): the transport, identity, and tick-authority piece item 129 asked for, without mwg inventing a full prediction/rollback netcode a real game would likely want to replace anyway. Every connected client submits at most one input per tick; the server broadcasts a tick message once every client in its room has submitted for that tick, or once a configured timeout elapses, substituting null for whoever is still missing - lockstep, the model turn-driven and RTS-shaped games have used for this for decades, chosen because it needs no client-side prediction to already be correct. A game wanting prediction or interpolation on top of this still can: onTick hands over the same ordered, authoritative input stream a prediction layer would reconcile against.

    This is deliberately the only network surface in mwg that assumes a server exists rather than a game's own endpoint - FeedbackClient/NewsClient/SaveSyncClient all assume the opposite, a one-shot request/response a game points at its own backend. Real-time multiplayer has no one-shot shape to hide a server behind, which is why mwg ships a reference one (tools/multiplayer-server.mjs) rather than assuming a game brings its own, the same reasoning that decided this the moment the item was sized.

    import { LockstepClient } from '@datamoc/mw_games/core';

    const client = new LockstepClient({ url: 'wss://example.com/room/1' });
    client.onTick.add(({ tick, inputs }) => console.log('tick', tick, inputs));
    client.connect();

    // each frame this client has an input for:
    client.submitInput({ move: 'left' });
    Index
    onClose: Signal<void> = ...
    onDesync: Signal<{ checksums: Record<string, number>; tick: number }> = ...
    onReject: Signal<{ reason: string }> = ...
    onTick: Signal<TickEvent> = ...
    onWelcome: Signal<LockstepWelcome> = ...
    • get id(): string | null

      this client's own id, assigned by the server's welcome message; null before it arrives

      Returns string | null

    • submits this client's input for the current tick; a no-op before the connection is open

      Parameters

      • payload: unknown
      • Optionalchecksum: number

      Returns void