mwg API
    Preparing search index...

    Class SyncGuard

    Compares the checksum peers compute for each tick. The first checksum seen for a tick is taken as the reference; a later observation of the same tick that disagrees marks the run divergent and is remembered as the first such tick, so a game can report exactly where the two peers parted.

    import { SyncGuard, stateChecksum } from '@datamoc/mw_games/core';

    const localState = { hp: 7 };
    const remoteState = { hp: 6 };

    const guard = new SyncGuard();
    guard.observe(12, stateChecksum(localState)); // true
    guard.observe(12, stateChecksum(remoteState)); // false if the two peers disagree
    if (guard.divergent) console.log('desync at tick', guard.atTick);
    Index
    • get atTick(): number | null

      the first tick that disagreed, or null while the run is in sync

      Returns number | null

    • Records checksum for tick; true when it matches the tick's reference (or is the first one), false on the first disagreement, which is then remembered.

      Parameters

      • tick: number
      • checksum: number

      Returns boolean