import { createVesselFeed } from './ingestion.js'; import { VesselRecords } from './records.js'; import { DEFAULT_AIS_RUNTIME } from './policy.js'; export function createVesselState({ source, services }) { const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource, hitTestWorldOverlay, } = services.overlay; const vesselState = {}; vesselState._source = source; /** Camera pose signature at the last vessel rotation pass. */ vesselState._lastCamPoseSig = ''; vesselState.DEFAULT_VESSEL_OVERLAY_HOST = Object.freeze({ setEntries: setOverlayEntries, setVisible: setOverlaySourceVisible, clearSource: clearOverlaySource, hitTest: hitTestWorldOverlay, }); vesselState._vesselOverlayHost = vesselState.DEFAULT_VESSEL_OVERLAY_HOST; vesselState._aisRuntime = DEFAULT_AIS_RUNTIME; vesselState._aisSessionSequence = 0; /** * True once the EGM96 geoid grid has loaded (fire-and-forget warm at * enable(), aircraft idiom — see militaryFlights.js). Gates all synchronous * geoidHeight() reads so a poll can never throw pre-load. * @type {boolean} */ vesselState._geoidReady = false; /** @type {Map} `${cssColor}:${variant}` -> chevron SVG data URL */ vesselState.shipIconCache = new Map(); /** Row ids for unkeyed (no-MMSI) records, which are rebuilt every poll. */ vesselState._unkeyedIconSequence = 0; // The ship whose icon is hidden under the bridge camera (cockpit subject). vesselState._iconHiddenMmsi = null; vesselState.state = { feed: createVesselFeed(), records: new VesselRecords({ now: () => vesselState._aisRuntime.now() }), viewer: null, /** The vessels' icons as drawn (`iconBook.js`), and their draw set. */ icons: null, /** The click subscription's unsubscribe. */ clickSubscription: null, /** Exact EventTarget currently holding the Escape listener. */ keyTarget: null, /** Exact callback registered on keyTarget. */ keydownHandler: null, /** Follow-change listener disposer. */ trackedEntityRemover: null, /** Test-only key target for enable-time interaction installation. */ interactionKeyTarget: null, preRenderRemover: null, /** Pending timer that renders one frame after a cadence-skipped pass. */ trailingVisibilityTimer: null, lastVisibilityUpdate: 0, lastFocusUpdate: 0, /** Sprites whose animated emphasis remains outside the 1.0 deadband. */ activeFocusCount: 0, activeLabelCount: 0, selectedRecord: null, /** @type {string|null} MMSI whose bridge the Cockpit camera occupies; its sprite and card stay hidden. */ cockpitSubjectMmsi: null, /** @type {{setPositions: Function, clear: Function, destroy: Function}|null} Selected-vessel fading trail */ trail: null, /** @type {{x: number, y: number, z: number}[]} Chronological ECEF trail vertices (oldest first) */ trailPositions: [], /** @type {string|null} MMSI that owns the active selected-vessel trail. */ trailMmsi: null, /** @type {number} Monotonic token — invalidates in-flight backfill responses */ trailBackfillToken: 0, trailAbort: null, }; return vesselState; }