/** * Realtime (doc 14, §39–40, §62): how one frame of incremental changes is applied. Pure functions over the data * the runtime hands in — no scene, no renderer, no events of its own — so the rules (coalescing, stale and * out-of-order updates, clock skew, leaving the view, incremental index updates, trail growth) are testable alone. */ import { MapEngineError } from '../core/errors.js'; import type { BoundingBox, MapLayer, SpatialObject, Track } from '../core/types.js'; import type { SpatialPatch } from '../data/contracts.js'; import type { SpatialIndex } from '../spatial/spatial-index.js'; /** One stream event waiting for the next frame. `trail` events grow track layers instead of moving objects. */ export interface PendingPatch { layerIds: string[]; patch: SpatialPatch; trail?: boolean; } /** What one frame changed in one layer, so the scene and the index touch only those objects. */ export interface LayerChanges { upserted: Map; removed: Set; } export interface ApplyContext { layer(layerId: string): MapLayer | undefined; /** The objects the layer holds now. */ current(layerId: string): SpatialObject[]; /** The viewport data boundary: an object that moves out of it leaves the layer. */ bounds: BoundingBox; /** Held times after this are clock skew and cannot order updates (doc 14). */ trustUntil: number; counters: { applied: number; stale: number; outOfView: number; }; warn(warning: MapEngineError): void; /** Every valid incoming object, before ordering (for clock-skew reporting). */ saw(object: SpatialObject, layerId: string): void; /** Grows a track layer from a patch; true when it changed. */ trail(layerId: string, patch: SpatialPatch): boolean; } export interface AppliedFrame { /** Each touched layer's objects after the frame. */ touched: Map>; changes: Map; /** Fresh point readings (including ones that leave the view), for geofencing. */ fresh: Array<{ layerId: string; object: SpatialObject; }>; /** Track layers that grew. */ trails: Set; } /** * Is `next` older than what is held? A held time beyond `trustUntil` (clock skew) cannot order anything: a real * update must not be refused because a source once stamped the future. */ export declare function isOlder(next: SpatialObject, prev: SpatialObject, trustUntil: number): boolean; /** Applies one frame of stream events. Many events for one object collapse into its newest state. */ export declare function applyFrame(batch: PendingPatch[], ctx: ApplyContext): AppliedFrame; /** * Applies one frame's changes to the client index instead of rebuilding it. The index holds each object once * however many layers show it, so an object leaves only when no other layer still shows it. * * `displayed` is what every layer shows; `touched` holds the frame's new state for the layers it changed; * `skip` names layers kept out of the index (trails). */ export declare function patchIndex(index: SpatialIndex, changes: Map, touched: Map>, displayed: Map, skip: (layerId: string) => boolean): void; /** * Grows trails from live point updates and drops points older than `keepFrom`. Returns how many points were added * and whether anything changed (a removal changes a trail without adding points). */ export declare function growTrails(tracks: Map, patch: SpatialPatch, keepFrom: number, now: number): { changed: boolean; added: number; };