mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
- Radio: stations, clusters, the selection and its brackets are point and sprite sets; clusters come from the layer's engine-neutral screen clusterer with Cesium's EntityCluster rules, and clicks go through the selection dispatcher. One style module holds the sizes and colours. - Transit: vehicles are two sprite sets from an up-front atlas, rotated with Cesium's projected-rotation maths. The selected vehicle's trail is engine.lines in two lanes and 29 age bands, so trails are no longer draped over terrain until the contract has ground corridors. The Cesium contact trail renderer and its re-export go. - CCTV: markers, wedges, the plane outline and the calibration gizmo (rings, arrows, handles, drags through engine.input) draw on the contract. The textured monitor plane and the viewshed volume, which no primitive expresses yet, sit behind one seam, render/meshes.js, with a Cesium backend and a Navara backend the Navara mode passes in. Known gaps against Cesium: transit trails are not draped, and the surveillance-lens click correction runs only where the engine reports its style stage (Navara). Coupling: layer renderer lines fall from 2638/8735 to 1636/6953 (Cesium/Navara), ScreenSpaceEventHandler files from 15 to 10, `viewer` lines from 2014 to 1901.
128 lines
4.9 KiB
JavaScript
128 lines
4.9 KiB
JavaScript
import * as geo from '../../geo/index.js';
|
|
import { createHistoryBudget } from '../../data/contactPlayback.js';
|
|
|
|
/**
|
|
* One Transit layer's mutable scene state. Every field lives on the instance,
|
|
* so two layers built from this factory never share a viewer, a primitive
|
|
* collection, a request map or a height cache.
|
|
* @param {{services: object}} context
|
|
* @returns {object}
|
|
*/
|
|
export function createState({ services }) {
|
|
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
|
|
services.overlays;
|
|
|
|
const state = {};
|
|
state._historyBudget = createHistoryBudget();
|
|
|
|
state.DEFAULT_OVERLAY_HOST = Object.freeze({
|
|
setEntries: setOverlayEntries,
|
|
setVisible: setOverlaySourceVisible,
|
|
clearSource: clearOverlaySource,
|
|
});
|
|
state._overlayHost = state.DEFAULT_OVERLAY_HOST;
|
|
|
|
/** The viewer the layer was initialized with (its renderer draws). */
|
|
state._viewer = null;
|
|
/** The renderer's marker collections: the fleet and the vehicles mid-glide. */
|
|
state._markers = null;
|
|
state._animatedMarkers = null;
|
|
state._visible = new Set();
|
|
state._visibilityTimer = null;
|
|
state._maintenanceTimer = null;
|
|
state._detectBuiltAt = -Infinity;
|
|
state._cameraRevision = 0;
|
|
state._rotationRevision = -1;
|
|
state._enabled = false;
|
|
state._generation = 0;
|
|
|
|
state._cameraChangedAttached = false;
|
|
state._cameraChangedRemove = null;
|
|
state._cameraDebounceTimer = null;
|
|
state._altitudeGateOpen = false;
|
|
/** Camera sensitivity as we found it, so disable() can hand it back. */
|
|
state._priorPercentageChanged = null;
|
|
/** The value this layer actually wrote, for an identity-guarded restore. */
|
|
state._appliedPercentageChanged = null;
|
|
|
|
/** @type {(() => void)|null} */
|
|
state._preRenderRemove = null;
|
|
state._renderHeld = false;
|
|
/** @type {{ destroy: () => void }|null} The renderer's click binding. */
|
|
state._clickHandler = null;
|
|
/**
|
|
* The vehicles currently mid-glide. The per-frame pass walks THIS, not the
|
|
* whole fleet, and the render hold is derived from it together with the
|
|
* height queue — so both track work that exists rather than a window of time
|
|
* the layer hoped would contain some.
|
|
* @type {Set<object>}
|
|
*/
|
|
state._moving = new Set();
|
|
/** Vehicles whose sampled height landed after they were drawn. @type {Set<object>} */
|
|
state._heightDirty = new Set();
|
|
/**
|
|
* Inflated camera view bounds in degrees, or null before the first camera
|
|
* read. Decides which vehicles are worth animating frame by frame.
|
|
* @type {{south:number,north:number,west:number,east:number}|null}
|
|
*/
|
|
state._viewBounds = null;
|
|
/** How many vehicles are currently drawn, as opposed to held. */
|
|
state._shownCount = 0;
|
|
/** Deferred shown/hidden sweep bookkeeping. */
|
|
state._visibilityDirty = true;
|
|
state._visibilityAt = 0;
|
|
/** Throttle bookkeeping for the screen-space rotation pass. */
|
|
state._rotationAt = 0;
|
|
state._rotationPose = null;
|
|
state._rotationDirty = false;
|
|
|
|
/** @type {Map<string, object>} feedId → registry entry currently polled */
|
|
state._activeFeeds = new Map();
|
|
/** @type {Map<string, {count:number, lastUpdate:number|null, error:string|null, stale:boolean, pollSeq:number, loading:boolean}>} */
|
|
state._feedStatus = new Map();
|
|
/** @type {Map<string, {controller: AbortController, promise: Promise<void>}>} */
|
|
state._inFlight = new Map();
|
|
/** @type {Map<string, object>} vehicle key → runtime entry */
|
|
state._vehicles = new Map();
|
|
|
|
/** Timer for the floor re-read cycle, and how many it has spent. */
|
|
state._floorTimer = null;
|
|
state._floorAttempts = 0;
|
|
/** Where the next warm window starts among the cold cells: no cell waits for ever. */
|
|
state._floorCursor = 0;
|
|
|
|
/** @type {string|null} */
|
|
state._selectedKey = null;
|
|
state._selectedCardAt = 0;
|
|
/** The card text last published, so an unchanged card is not re-sent. */
|
|
state._selectedCardText = null;
|
|
/**
|
|
* Bumped whenever the set of vehicles DETECT may see could have changed —
|
|
* a poll, a visibility sweep, a removal, a selection — so the candidate
|
|
* list is rebuilt on change rather than on every paint.
|
|
*/
|
|
state._detectRevision = 0;
|
|
/** The candidate list DETECT was last handed, and the revision it was built at. */
|
|
state._detectCache = null;
|
|
/**
|
|
* Active post-FX style the sprites are drawn for. Read from the document
|
|
* at init and followed through the style and cockpit-vision events; a
|
|
* cockpit override wins over the map style while it lasts.
|
|
*/
|
|
state._stylePreset = 'normal';
|
|
state._cockpitVision = false;
|
|
/** @type {Array<[string, EventListener]>} window listeners to remove on destroy. */
|
|
state._styleListeners = [];
|
|
/** @type {{ refreshLayerStats?: () => void }|null} */
|
|
state._dataManager = null;
|
|
/** @type {number|null} */
|
|
state._lastUpdate = null;
|
|
/** @type {string|null} */
|
|
state._error = null;
|
|
state._limitWarned = false;
|
|
|
|
state._scratchCartesian = geo.cartesian3.create();
|
|
|
|
return state;
|
|
}
|