@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
74 lines • 2.55 kB
TypeScript
/**
* Append-only record of action bytes per frame. Useful for offline replay,
* bug reproduction, and demos.
*
* Each entry stores a copy of the action bytes for one frame. The bytes
* typically come from the per-frame `ActionLog` buffer (the action portion
* after `Replicator.pack_for_peer` strips prior-state). The format on the wire
* is the same one `Replicator.unpack_from_peer` consumes, so a recorded
* session can be replayed by feeding the bytes back through a peer.
*
* Persistence to disk / IndexedDB / network is left to the application —
* `serialize_to_buffer` produces a single contiguous `BinaryBuffer` snapshot.
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class ReplayLog {
/**
* Build a ReplayLog from a previously-serialized buffer. Reads from the
* buffer's current position; advances the position past the consumed bytes.
*
* @param {BinaryBuffer} buffer
* @returns {ReplayLog}
*/
static deserialize_from_buffer(buffer: BinaryBuffer): ReplayLog;
/**
* Append a frame's bytes. The source array is copied; caller may reuse it.
*
* @param {number} frame
* @param {Uint8Array} bytes
* @param {number} length
*/
record(frame: number, bytes: Uint8Array, length: number): void;
/**
* @returns {number}
*/
size(): number;
/**
* Iterate frames in `[start_frame, end_frame]` (inclusive).
* @param {number} start_frame
* @param {number} end_frame
* @param {function(number, Uint8Array): void} callback receives (frame, bytes)
*/
for_each_in_range(start_frame: number, end_frame: number, callback: (arg0: number, arg1: Uint8Array) => void): void;
/**
* Drop all entries.
*/
clear(): void;
/**
* Frame number of the first entry, or -1 if empty.
*/
earliest_frame(): any;
/**
* Frame number of the last entry, or -1 if empty.
*/
latest_frame(): any;
/**
* Serialize the entire log to a fresh buffer. Format:
* ```
* varint: entry_count
* loop:
* varint: frame
* varint: bytes_length
* bytes: payload
* ```
*
* @param {BinaryBuffer} [buffer] if provided, written into; otherwise a fresh one is created
* @returns {BinaryBuffer}
*/
serialize_to_buffer(buffer?: BinaryBuffer): BinaryBuffer;
#private;
}
import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js";
//# sourceMappingURL=ReplayLog.d.ts.map