UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

66 lines 2.44 kB
/** * Walks the {@link ActionLog} backwards to restore prior component state. * * For each frame to undo, the engine: * 1. Parses the frame's records forward to find record start positions * (a record's full length isn't fixed; it's discovered by reading headers). * 2. Iterates record positions in reverse. * 3. For each record, reads its prior_state entries and writes them back into * live components via the replication adapter for that component class. * * Reverse iteration is necessary because multiple actions in the same frame may * have mutated the same component; the most recent mutation must be undone * first, then the next-most-recent, and so on, ending at the start-of-frame state. * * Forward replay is just running the existing simulation tick again — that's the * orchestrator's job. RewindEngine only handles the backward direction. * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class RewindEngine { /** * @param {{ * action_log: ActionLog, * world: EntityComponentDataset, * component_registry: ReplicatedComponentRegistry, * }} options */ constructor({ action_log, world, component_registry }: { action_log: ActionLog; world: EntityComponentDataset; component_registry: ReplicatedComponentRegistry; }); /** * @type {ActionLog} */ action_log: ActionLog; /** * @type {EntityComponentDataset} */ world: EntityComponentDataset; /** * @type {ReplicatedComponentRegistry} */ component_registry: ReplicatedComponentRegistry; /** * Undo all action records in a single frame, in reverse order. * Throws if the frame is not present in the log. * * @param {number} frame */ undo_frame(frame: number): void; /** * Undo every frame in `(target_frame, current_frame]` so that the world is * left in start-of-`target_frame + 1` state. Equivalently: the world ends * up as it was at the END of `target_frame`. * * Throws if any frame in the range is missing from the log. * * @param {number} current_frame the most recent frame whose actions are applied * @param {number} target_frame the frame whose end-state we want to restore to */ rewind_to(current_frame: number, target_frame: number): void; #private; } //# sourceMappingURL=RewindEngine.d.ts.map