UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

74 lines 2.98 kB
/** * Compute a 32-bit fingerprint of every replicated component on every entity * in the world. Used by `SyncTest` and as a general "did the world state change?" * primitive. * * The hash is FNV-1a — fast, stable, no dependencies. Not cryptographic. * * Iteration order: entities in the order yielded by `world` (the * EntityComponentDataset's iterator), then components in `type_id` order. * As long as both sides iterate identically, the fingerprint is comparable. * * @param {EntityComponentDataset} world * @param {ReplicatedComponentRegistry} component_registry * @param {BinaryBuffer} [scratch] optional reusable scratch; resets to position 0 each call * @returns {number} 32-bit unsigned hash */ export function fingerprint_world(world: EntityComponentDataset, component_registry: ReplicatedComponentRegistry, scratch?: BinaryBuffer): number; /** * Diagnostic harness for catching rewind / replay bugs. * * Usage: * - `harness.checkpoint()` — records the current world fingerprint. * - … run tick logic … * - `harness.assert_recoverable_to_checkpoint(rewind_engine, current_frame, target_frame)` * rewinds and asserts the world's fingerprint matches the checkpoint. * * For full nondeterminism detection (GGPO-style "save → advance → load → * advance → diff"), the application's tick logic must be re-runnable; that * coordination is left to the caller. This harness provides the fingerprint + * compare primitives and the assertion shape. * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class SyncTest { /** * @param {{ * world: EntityComponentDataset, * component_registry: ReplicatedComponentRegistry, * }} options */ constructor({ world, component_registry }: { world: EntityComponentDataset; component_registry: ReplicatedComponentRegistry; }); /** @type {EntityComponentDataset} */ world: EntityComponentDataset; /** @type {ReplicatedComponentRegistry} */ component_registry: ReplicatedComponentRegistry; /** * Capture the current world state as the reference point for the next * `assert_recoverable_to_checkpoint` call. */ checkpoint(): void; /** * @returns {number} */ current_fingerprint(): number; /** * Rewind from `current_frame` back to `target_frame` (typically the frame * at which `checkpoint()` was called) and assert the resulting world state * matches the checkpoint. * * Throws on mismatch with a diagnostic message including both fingerprints. * * @param {RewindEngine} rewind_engine * @param {number} current_frame * @param {number} target_frame */ assert_recoverable_to_checkpoint(rewind_engine: RewindEngine, current_frame: number, target_frame: number): void; #private; } import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js"; //# sourceMappingURL=SyncTest.d.ts.map