mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw Flights and Military 3D models through draw-port model sets
The two aircraft layers' fleet and tracked models are now draw-port models sets made each layer lifetime, re-posed and restyled in place, instead of Cesium models in a collection of their own. Model records are plain data; picks name the set and the contact, readiness comes from the set's ready event, the IR boost restyles in place (unlit, white tint, full blend), and the drawn scale comes from the camera pose and pixel floor. Fleet writes go out together at the end of each tick, before the icons they replace, and a failed write hands the contacts back to their icons. A model that has not loaded is rewritten every few seconds so the renderer can retry it, which replaces the tracked model's load-failure budget. Models load off the tile-contended job queue, as before. aircraftModelLayer.js, modelRecord.js and the flights and military lifecycle and testing files, plus flights rendering.js, come off the Cesium allow-list.
This commit is contained in:
1 parent
eed3b83858
commit
abe9f97768
28 files changed
+1310
-1255
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { findCamera, findFrame } from '../../render/rendererOf.js';
|
||||
import { JET_MODEL_URL } from './policy.js';
|
||||
|
||||
export function createLifecycle({
|
||||
@@ -31,7 +31,7 @@ export function createLifecycle({
|
||||
/**
|
||||
* Initialize the layer: create the icon set and its primitive, reset all state,
|
||||
* and install the click-to-track handler.
|
||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
|
||||
* @param {object} viewer - The Cesium viewer instance
|
||||
*/
|
||||
init(viewer) {
|
||||
if (flightState._viewer)
|
||||
@@ -43,33 +43,11 @@ export function createLifecycle({
|
||||
clearFocusTarget('militaryFlights');
|
||||
flightState._viewer = viewer;
|
||||
registerSpriteSet('military', parts.icons._createIcons(viewer));
|
||||
flightState._modelCollection = new Cesium.PrimitiveCollection();
|
||||
viewer.scene.primitives.add(flightState._modelCollection);
|
||||
// Warm the glTF cache so the tracked plane's model instantiates instantly when first needed
|
||||
// (keeps the retained instance referenced; never rendered). Captured against this epoch so a
|
||||
// destroy/re-init mid-load doesn't flip the flag for a torn-down lifecycle.
|
||||
if (!flightState._preloadModel) {
|
||||
const epoch = flightState._modelEpoch;
|
||||
Cesium.Model.fromGltfAsync({
|
||||
url: resolveAsset(JET_MODEL_URL),
|
||||
asynchronous: false,
|
||||
})
|
||||
.then((m) => {
|
||||
if (epoch === flightState._modelEpoch) {
|
||||
flightState._preloadModel = m;
|
||||
flightState._planeModelLoaded = true;
|
||||
} else {
|
||||
try {
|
||||
m.destroy();
|
||||
} catch {
|
||||
/* gone */
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
/* tracked plane just stays an icon a beat longer */
|
||||
});
|
||||
}
|
||||
// The models' draw sets; a hidden item keeps the tracked asset loaded so
|
||||
// the tracked plane's model draws as soon as it is wanted.
|
||||
parts.rendering._createModelSets(viewer, {
|
||||
preloadUrl: resolveAsset(JET_MODEL_URL),
|
||||
});
|
||||
flightState._iconFocusActive = 0;
|
||||
flightState._detectionObjects = new Map();
|
||||
flightState.records.data = new Map();
|
||||
@@ -107,13 +85,12 @@ export function createLifecycle({
|
||||
|
||||
/**
|
||||
* Show the layer and re-install the click handler.
|
||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
|
||||
* @param {object} viewer - The Cesium viewer instance
|
||||
*/
|
||||
enable(viewer) {
|
||||
if (flightState._icons) flightState._icons.show = true;
|
||||
holdContinuousRender('military'); // per-frame animator (perf wave 2)
|
||||
if (flightState._modelCollection)
|
||||
flightState._modelCollection.show = true;
|
||||
parts.rendering._setModelsShown(true);
|
||||
parts.tracking._setCockpitContactMode(
|
||||
document.body.classList.contains('cockpit-mode'),
|
||||
);
|
||||
@@ -137,26 +114,25 @@ export function createLifecycle({
|
||||
);
|
||||
// The flights layer suppresses its military duplicates while we render them
|
||||
setMilitaryLayerActive(true);
|
||||
if (!flightState._preRenderRemove && viewer?.scene) {
|
||||
flightState._preRenderRemove = viewer.scene.preRender.addEventListener(
|
||||
parts.rendering._fleetTick,
|
||||
const frame = findFrame(viewer);
|
||||
if (!flightState._preRenderRemove && frame) {
|
||||
flightState._preRenderRemove = frame.on('preRender', () =>
|
||||
parts.rendering._fleetTick(),
|
||||
);
|
||||
}
|
||||
if (!flightState._trackedModelPreUpdateRemove && viewer?.scene) {
|
||||
flightState._trackedModelPreUpdateRemove =
|
||||
viewer.scene.preUpdate.addEventListener(
|
||||
parts.rendering._updateTrackedModel,
|
||||
);
|
||||
if (!flightState._trackedModelPreUpdateRemove && frame) {
|
||||
flightState._trackedModelPreUpdateRemove = frame.on('preUpdate', () =>
|
||||
parts.rendering._updateTrackedModel(),
|
||||
);
|
||||
}
|
||||
if (!flightState._moveEndRemove && viewer?.camera) {
|
||||
const camera = findCamera(viewer);
|
||||
if (!flightState._moveEndRemove && camera) {
|
||||
// A settled camera move (voice fly-to, fast pan release) runs the fleet
|
||||
// pass on the very next preRender rather than up to FLEET_DR_INTERVAL_MS
|
||||
// later, so the model handoff and focus land with the camera.
|
||||
flightState._moveEndRemove = viewer.camera.moveEnd.addEventListener(
|
||||
() => {
|
||||
flightState._lastFleetTickMs = 0;
|
||||
},
|
||||
);
|
||||
flightState._moveEndRemove = camera.on('moveEnd', () => {
|
||||
flightState._lastFleetTickMs = 0;
|
||||
});
|
||||
}
|
||||
restoreSpriteOrder(viewer);
|
||||
},
|
||||
@@ -164,7 +140,7 @@ export function createLifecycle({
|
||||
/**
|
||||
* Hide the layer, clear any active tracking, and remove input handlers
|
||||
* so clicks do not get intercepted while the layer is off.
|
||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
|
||||
* @param {object} viewer - The Cesium viewer instance
|
||||
*/
|
||||
disable(viewer) {
|
||||
parts.controller._abortActiveUpdates();
|
||||
@@ -172,8 +148,7 @@ export function createLifecycle({
|
||||
if (flightState._icons) flightState._icons.show = false;
|
||||
releaseContinuousRender('military');
|
||||
parts.rendering._releaseModels();
|
||||
if (flightState._modelCollection)
|
||||
flightState._modelCollection.show = false;
|
||||
parts.rendering._setModelsShown(false);
|
||||
parts.tracking._clearTracking();
|
||||
parts.tracking._destroyTrail();
|
||||
// Remove click handler + keydown listener while disabled to avoid
|
||||
@@ -205,7 +180,7 @@ export function createLifecycle({
|
||||
/**
|
||||
* Tear down the layer: clear tracking, remove handlers, remove the icon
|
||||
* primitive from the scene, and release all state.
|
||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
|
||||
* @param {object} viewer - The Cesium viewer instance
|
||||
*/
|
||||
destroy(viewer) {
|
||||
flightState.lifetime.abort();
|
||||
@@ -243,22 +218,7 @@ export function createLifecycle({
|
||||
}
|
||||
parts.rendering._releaseModels();
|
||||
parts.icons._disposeIcons();
|
||||
if (flightState._modelCollection) {
|
||||
viewer.scene.primitives.remove(flightState._modelCollection); // removing destroys it + its models
|
||||
flightState._modelCollection = null;
|
||||
}
|
||||
flightState._modelEpoch += 1; // invalidate any in-flight load from this lifecycle (settles post-destroy)
|
||||
flightState._modelPending.clear();
|
||||
flightState._modelGen.clear();
|
||||
if (flightState._preloadModel) {
|
||||
try {
|
||||
flightState._preloadModel.destroy();
|
||||
} catch {
|
||||
/* gone */
|
||||
}
|
||||
flightState._preloadModel = null;
|
||||
}
|
||||
flightState._planeModelLoaded = false;
|
||||
parts.rendering._disposeModelSets();
|
||||
flightState._iconFocusActive = 0;
|
||||
flightState._detectionObjects.clear();
|
||||
flightState.records.data.clear();
|
||||
|
||||
@@ -330,7 +330,7 @@ export function createMotion({
|
||||
* The position the tracked aircraft is VISUALLY at this frame — the translation its 3D
|
||||
* model is actually rendering with when the model owns the visual, otherwise the cached
|
||||
* dead-reckoned position. Mirror of flights.js; see that copy for the full rationale.
|
||||
* Reads the modelMatrix the tracked-model update already wrote this frame: no sampling,
|
||||
* Reads the placement the tracked-model update already recorded this frame: no sampling,
|
||||
* no `_modelDisplayPosition` from postRender, and the entity record's `displayPosition` keeps its
|
||||
* follow-camera anti-jitter contract untouched.
|
||||
*/
|
||||
@@ -346,9 +346,7 @@ export function createMotion({
|
||||
return modelVisualAnchor(
|
||||
flightState._trackedModel.matrix,
|
||||
spec.visualCenterNative,
|
||||
Number.isFinite(flightState._trackedModel.model.computedScale)
|
||||
? flightState._trackedModel.model.computedScale
|
||||
: spec.scale,
|
||||
parts.rendering._modelDrawnScale(flightState._trackedModel, spec),
|
||||
flightState._trackedVisualPos,
|
||||
);
|
||||
}
|
||||
@@ -356,8 +354,8 @@ export function createMotion({
|
||||
}
|
||||
|
||||
/** The tracked model's rendered bounding radius (m), or 0 when no model of this
|
||||
* contact is drawing. Carries Cesium's effective `computedScale`, which may be
|
||||
* above `scale` to satisfy minimumPixelSize — the trail head has to be judged
|
||||
* contact is drawing. Carries the scale it is drawn at, which may be
|
||||
* above `scale` to satisfy its pixel floor — the trail head has to be judged
|
||||
* against the size the operator SEES, not the nominal one. */
|
||||
/** World-space origin of the tracked model, or null when no model of this
|
||||
* contact is drawing. This is the centre the rendered bounding sphere is
|
||||
@@ -386,10 +384,10 @@ export function createMotion({
|
||||
const spec = parts.rendering._modelSpec(
|
||||
flightState.records.data.get(flightState._trackedIcao)?.klass,
|
||||
);
|
||||
const scale = Number.isFinite(flightState._trackedModel.model.computedScale)
|
||||
? flightState._trackedModel.model.computedScale
|
||||
: spec.scale;
|
||||
return spec.nativeRadiusM * scale;
|
||||
return (
|
||||
spec.nativeRadiusM *
|
||||
parts.rendering._modelDrawnScale(flightState._trackedModel, spec)
|
||||
);
|
||||
}
|
||||
|
||||
/** Trail endpoint for the rendered tracked owner. Brackets/readouts stay on
|
||||
@@ -409,9 +407,7 @@ export function createMotion({
|
||||
return modelAnchorWorld(
|
||||
flightState._trackedModel.matrix,
|
||||
spec.trailAnchorNative,
|
||||
Number.isFinite(flightState._trackedModel.model.computedScale)
|
||||
? flightState._trackedModel.model.computedScale
|
||||
: spec.scale,
|
||||
parts.rendering._modelDrawnScale(flightState._trackedModel, spec),
|
||||
flightState._trackedTrailPos,
|
||||
);
|
||||
}
|
||||
@@ -527,11 +523,7 @@ export function createMotion({
|
||||
flightState._viewer?.scene,
|
||||
points,
|
||||
{
|
||||
excludeObjects: [
|
||||
...parts.icons._iconIds(),
|
||||
...[...flightState._models.values()].map((record) => record.model),
|
||||
flightState._trackedModel?.model,
|
||||
].filter(Boolean),
|
||||
excludeObjects: parts.icons._iconIds(),
|
||||
viewerLat,
|
||||
viewerLon,
|
||||
},
|
||||
|
||||
@@ -229,25 +229,3 @@ export const COURSE_SLEW_DT_MAX_SEC = 0.25;
|
||||
// camera, and trail head never visibly jump — with zero steady-state lag. --
|
||||
|
||||
export const DR_CORRECTION_MS = 900;
|
||||
|
||||
/** Bounded on-demand loading for the tracked model (mirror of flights.js). The
|
||||
* tracked regime is DEFAULT-ON and its driver runs every `scene.preUpdate`, so
|
||||
* a missing or corrupt GLB — or a dead network — would otherwise spin
|
||||
* load→reject at frame rate for as long as the contact stays selected.
|
||||
* Failures are counted PER SELECTION: a short backoff absorbs a transient
|
||||
* blip, then the layer stops asking until the operator selects something else.
|
||||
* The billboard is the visual throughout (the handoff only fades it once a
|
||||
* model actually renders), so a latched failure degrades to exactly the
|
||||
* pre-3D presentation. */
|
||||
|
||||
export const TRACKED_MODEL_MAX_LOAD_FAILS = 3;
|
||||
|
||||
export const TRACKED_MODEL_RETRY_BACKOFF_MS = 1500;
|
||||
|
||||
/** Boost flip = BATCHED release through the fleet tick (mirror of flights.js —
|
||||
* destroying the whole fleet synchronously in the style handler stalls the
|
||||
* render thread). Models tagged with their load-time boost state; stale queue
|
||||
* entries skip; in-flight loads invalidated immediately; tracked reloads
|
||||
* synchronously (single primitive). */
|
||||
|
||||
export const IR_RELOAD_BATCH = 40;
|
||||
@@ -440,6 +440,8 @@ export function createQueries({
|
||||
|
||||
const result = [];
|
||||
const ids = icons.ids();
|
||||
/** One camera and viewport for every model's drawn scale. */
|
||||
let view = null;
|
||||
for (let i = start; i < ids.length; i += stride) {
|
||||
const icao24 = ids[i];
|
||||
if (
|
||||
@@ -481,9 +483,11 @@ export function createQueries({
|
||||
? modelVisualAnchor(
|
||||
record.matrix,
|
||||
spec.visualCenterNative,
|
||||
Number.isFinite(record.model.computedScale)
|
||||
? record.model.computedScale
|
||||
: spec.scale,
|
||||
parts.rendering._modelDrawnScale(
|
||||
record,
|
||||
spec,
|
||||
(view ??= parts.rendering._drawnScaleView()),
|
||||
),
|
||||
object._weldPos || (object._weldPos = new Cesium.Cartesian3()),
|
||||
)
|
||||
: icons.position(icao24, t, object._iconPos);
|
||||
|
||||
@@ -132,6 +132,7 @@ export function createRendering({
|
||||
parts,
|
||||
resolveAsset,
|
||||
logLabel: 'Data:Military',
|
||||
setPrefix: 'military',
|
||||
policy,
|
||||
modelSpec: _modelSpec,
|
||||
modelColor: _modelColor,
|
||||
|
||||
@@ -27,32 +27,16 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._groundSnap = createGroundSnap();
|
||||
|
||||
flightState._scratchGroundCarto = new Cesium.Cartographic();
|
||||
/** The fleet and tracked model draw sets of this layer lifetime
|
||||
* (`_createModelSets`), or null. */
|
||||
|
||||
flightState._scratchGroundPos = new Cesium.Cartesian3();
|
||||
flightState._modelSets = null;
|
||||
|
||||
/** @type {Cesium.PrimitiveCollection|null} */
|
||||
|
||||
flightState._modelCollection = null;
|
||||
|
||||
/** @type {Map<string, Cesium.Model>} icao24 → model */
|
||||
/** @type {Map<string, import('../../data/modelRecord.js').ModelRecord>}
|
||||
* icao24 → the fleet model admitted for it (loading or drawn). */
|
||||
|
||||
flightState._models = new Map();
|
||||
|
||||
/** @type {Set<string>} icao24 currently loading (async) */
|
||||
|
||||
flightState._modelPending = new Set();
|
||||
|
||||
/** @type {Map<string, number>} icao24 → load generation; bumped on release to invalidate
|
||||
* an in-flight load (so a track/untrack/remove during fromGltfAsync can't add a stale model). */
|
||||
|
||||
flightState._modelGen = new Map();
|
||||
|
||||
/** Lifecycle epoch; bumped on destroy so an in-flight load from a PREVIOUS init can't settle
|
||||
* against a new lifecycle's globals (which destroy cleared). Captured by _ensureModel. */
|
||||
|
||||
flightState._modelEpoch = 0;
|
||||
|
||||
/** DEFAULT-ON in PROXIMITY (owner directive 2026-08-22). A fresh boot never runs
|
||||
* layer-state restoration, so this initializer — not the codec — is what the app
|
||||
* actually starts with; it must stay in lockstep with the `models3d` default in
|
||||
@@ -66,22 +50,6 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._lastModelCapWarnMs = 0;
|
||||
// throttle the "more planes in view than the cap" console notice
|
||||
// The tracked entity's billboard goes transparent (rather than hidden) once the model takes
|
||||
// over, so it keeps supplying a bounding sphere for follow-camera framing. We only drop its
|
||||
// alpha after the GLB is preloaded so the model is ready to render the instant the billboard
|
||||
// fades — no gap, no double-image. Preloaded once at init; the instance is retained (not
|
||||
// destroyed) purely to keep Cesium's glTF cache warm for fast tracked-model instantiation.
|
||||
|
||||
flightState._planeModelLoaded = false;
|
||||
|
||||
/** @type {Cesium.Model|null} retained preload that keeps the glTF cache warm */
|
||||
|
||||
flightState._preloadModel = null;
|
||||
|
||||
flightState._scratchModelHpr = new Cesium.HeadingPitchRoll(0, 0, 0);
|
||||
|
||||
flightState._scratchModelMtx = new Cesium.Matrix4();
|
||||
|
||||
flightState._scratchModelBS = new Cesium.BoundingSphere(
|
||||
new Cesium.Cartesian3(),
|
||||
1.0,
|
||||
@@ -124,16 +92,12 @@ export function createFlightState({ source, services }) {
|
||||
/** The FollowTarget the camera follows the tracked aircraft with. */
|
||||
flightState._followTarget = null;
|
||||
|
||||
/** @type {Cesium.Model|null} Standalone 3D model for the tracked aircraft — NOT a graphic on
|
||||
/** @type {import('../../data/modelRecord.js').ModelRecord|null} Standalone 3D model for the tracked aircraft — NOT a graphic on
|
||||
* _trackedEntity, which stays a plain, always-ready billboard (a model graphic reports PENDING
|
||||
* until loaded); the camera follows its own target. */
|
||||
|
||||
flightState._trackedModel = null;
|
||||
|
||||
flightState._trackedModelGen = 0;
|
||||
|
||||
flightState._trackedModelLoading = false;
|
||||
|
||||
/** @type {(() => void)|null} Unsubscribes the aircraft-selection click. */
|
||||
|
||||
flightState._clickSubscription = null;
|
||||
@@ -315,30 +279,12 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._trackedZoomLatchIcao = null;
|
||||
|
||||
flightState._trackedModelFailIcao = null;
|
||||
|
||||
flightState._trackedModelFailCount = 0;
|
||||
|
||||
flightState._trackedModelRetryAtMs = 0;
|
||||
|
||||
/** IR hot-target mode — mirror of flights.js: under the luminance-mapped
|
||||
* NVG/FLIR post-styles every model renders flat white (hottest); the dominant
|
||||
* amber/tracked tint restores on style exit. */
|
||||
|
||||
flightState._irBoost = false;
|
||||
|
||||
/** Boosted models render UNLIT — mirror of flights.js (owner cockpit-FLIR
|
||||
* field rounds): material-stage tint still sun-shades, so side-on planes
|
||||
* read near-black under a high sun; UNLIT emits flat white regardless.
|
||||
* customShader on a READY model is a silent no-op (field-verified), so the
|
||||
* boost flips by release-and-reload — creation-time options carry it. */
|
||||
|
||||
flightState._IR_UNLIT_SHADER = new Cesium.CustomShader({
|
||||
lightingModel: Cesium.LightingModel.UNLIT,
|
||||
});
|
||||
|
||||
flightState._irReloadQueue = null;
|
||||
|
||||
/** @type {Cesium.Cartographic} Scratch for _trailFloorPosition (per-frame safe). */
|
||||
|
||||
flightState._scratchTrailCarto = new Cesium.Cartographic();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { AMBER_TRANSPARENT, TRACKED_ICON_COLOR } from './policy.js';
|
||||
import { createModelRecord } from '../../data/modelRecord.js';
|
||||
import {
|
||||
@@ -23,16 +22,44 @@ export function createTesting({
|
||||
* @param {string} state.icao24
|
||||
* @param {object} state.entity
|
||||
* @param {object} state.meta
|
||||
* @param {{position?: Cesium.Cartesian3, show?: boolean}} [state.icon]
|
||||
* @param {{position?: {x: number, y: number, z: number}, show?: boolean}} [state.icon]
|
||||
* Where the contact's icon is held, and whether it is shown.
|
||||
* @param {{show?: boolean}} [state.iconLayer] Layer visibility.
|
||||
* @param {object} state.viewer
|
||||
* @param {Array<Object>} [state.history=[]]
|
||||
* @param {boolean} [state.tracked=true]
|
||||
* @param {Iterable<[string, object]>} [state.models=[]] - Fleet 3D models keyed
|
||||
* by icao24, for the icon-hidden/model-shown handoff state.
|
||||
* by icao24, for the icon-hidden/model-shown handoff state: each object
|
||||
* becomes the contact's model record (`ready`, `show`, and a placement
|
||||
* `modelMatrix` when given), so the test reads what the layer writes back.
|
||||
* @param {object|null} [state.draw] A draw port the layer's model sets are
|
||||
* made on (a test double); none keeps the records only.
|
||||
*/
|
||||
|
||||
/** Turn a test's model fields into the contact's model record, in place. */
|
||||
function _modelRecordForTest(fields, klass) {
|
||||
const spec = parts.rendering._modelSpec(klass);
|
||||
const base = createModelRecord({
|
||||
specKey: parts.rendering._specKeyFor(klass),
|
||||
bellyM: spec.bellyM,
|
||||
scale: spec.scale,
|
||||
});
|
||||
for (const key of Object.keys(base))
|
||||
if (!(key in fields)) fields[key] = base[key];
|
||||
fields.ready = fields.ready === true;
|
||||
fields.show = fields.show ?? true;
|
||||
if (fields.modelMatrix) {
|
||||
fields.matrix = Float64Array.from(fields.modelMatrix);
|
||||
fields.position = {
|
||||
x: fields.matrix[12],
|
||||
y: fields.matrix[13],
|
||||
z: fields.matrix[14],
|
||||
};
|
||||
fields.placed = true;
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
function _setTrackedMilitaryRefreshStateForTest({
|
||||
icao24,
|
||||
entity,
|
||||
@@ -43,16 +70,17 @@ export function createTesting({
|
||||
history = [],
|
||||
tracked = true,
|
||||
models = [],
|
||||
modelCollection = null,
|
||||
draw = null,
|
||||
}) {
|
||||
flightState._viewer = viewer;
|
||||
flightState._modelCollection = modelCollection;
|
||||
parts.rendering._disposeModelSets();
|
||||
if (draw) parts.rendering._createModelSets(viewer, { draw });
|
||||
flightState._icons = createContactIcons();
|
||||
flightState._icons.show = iconLayer?.show ?? true;
|
||||
_seedIconForTest(icao24, icon, tracked);
|
||||
flightState._models.clear();
|
||||
for (const [key, model] of models)
|
||||
flightState._models.set(key, createModelRecord(model));
|
||||
flightState._models.set(key, _modelRecordForTest(model, meta?.klass));
|
||||
flightState._detectionObjects = new Map();
|
||||
flightState.records.data = new Map([[icao24, meta]]);
|
||||
flightState._positionHistory = new Map([[icao24, history]]);
|
||||
@@ -63,7 +91,6 @@ export function createTesting({
|
||||
flightState._trackedEntity = tracked ? entity : null;
|
||||
flightState._trackedModel = null;
|
||||
parts.tracking._cancelPendingTrackingRestore();
|
||||
flightState._trackedModelLoading = false;
|
||||
// NOTE: deliberately does NOT reset the per-selection latches. They are
|
||||
// production state owned by the tracking lifecycle (_resetTrackedSelectionState),
|
||||
// and clearing them here would mask exactly the deselect→re-track hole this
|
||||
@@ -128,7 +155,7 @@ export function createTesting({
|
||||
}
|
||||
|
||||
/** Run one frame of the production tracked-model driver (normally a
|
||||
* `scene.preUpdate` listener) so tests can pin its bounded load retries. */
|
||||
* `preUpdate` listener). */
|
||||
|
||||
function _updateTrackedModelForTest() {
|
||||
return parts.rendering._updateTrackedModel();
|
||||
@@ -153,11 +180,24 @@ export function createTesting({
|
||||
);
|
||||
}
|
||||
|
||||
/** Exercise the exact asynchronous fleet loader and return its admitted model. */
|
||||
/** Exercise the exact fleet admission and return the admitted model's record. */
|
||||
|
||||
async function _ensureFleetModelForTest(icao24) {
|
||||
await parts.rendering._ensureModel(icao24);
|
||||
return flightState._models.get(icao24)?.model ?? null;
|
||||
function _ensureFleetModelForTest(icao24) {
|
||||
parts.rendering._ensureModel(icao24);
|
||||
return flightState._models.get(icao24) ?? null;
|
||||
}
|
||||
|
||||
/** The tracked model's record, or null. */
|
||||
|
||||
function _trackedModelForTest() {
|
||||
return flightState._trackedModel;
|
||||
}
|
||||
|
||||
/** The fleet and tracked model sets' ids, or null without sets. */
|
||||
|
||||
function _modelSetIdsForTest() {
|
||||
const [fleet, tracked] = parts.rendering._modelSetIds();
|
||||
return fleet ? { fleet, tracked } : null;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -174,5 +214,7 @@ export function createTesting({
|
||||
_iconForTest,
|
||||
_setIconForTest,
|
||||
_ensureFleetModelForTest,
|
||||
_trackedModelForTest,
|
||||
_modelSetIdsForTest,
|
||||
};
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import {
|
||||
} from '../../data/trackingClickGesture.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
TRACKED_MODEL_MAX_LOAD_FAILS,
|
||||
TRACKED_MODEL_RETRY_BACKOFF_MS,
|
||||
TRAIL_MAX_POINTS,
|
||||
RENDER_DELAY_SEC,
|
||||
TRAIL_COLOR,
|
||||
@@ -36,8 +34,8 @@ import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
|
||||
/**
|
||||
* The icao a pick carries: a draw-set item's id (the icon sets' rows), a
|
||||
* string pick id, or a model primitive's id.
|
||||
* The icao a pick carries: a draw-set item's id (the icon and model sets'
|
||||
* rows), a string pick id, or a primitive's id.
|
||||
*/
|
||||
function aircraftPickId(picked) {
|
||||
const id = picked?.id;
|
||||
@@ -210,7 +208,7 @@ export function createTracking({
|
||||
// The collection stays visible in cockpit. Near AIR contacts retain their
|
||||
// aircraft silhouette until a ready model takes over; far contacts are pips.
|
||||
// Never bulk-destroy here: that stalls the renderer exactly as cockpit begins.
|
||||
if (flightState._modelCollection) flightState._modelCollection.show = true;
|
||||
parts.rendering._setModelsShown(true);
|
||||
flightState._trail?.setVisible(!next);
|
||||
const icons = flightState._icons;
|
||||
for (const icao24 of icons?.ids() ?? [])
|
||||
@@ -314,8 +312,7 @@ export function createTracking({
|
||||
.toLowerCase();
|
||||
if (!id) return false;
|
||||
if (isTr3b(id)) {
|
||||
if (flightState._models.has(id) || flightState._modelPending.has(id))
|
||||
parts.rendering._releaseModel(id);
|
||||
if (flightState._models.has(id)) parts.rendering._releaseModel(id);
|
||||
if (flightState._icons?.has(id) && id !== flightState._trackedIcao)
|
||||
flightState._icons.setShown(id, true);
|
||||
if (id === flightState._trackedIcao) {
|
||||
@@ -341,8 +338,8 @@ export function createTracking({
|
||||
}
|
||||
}
|
||||
|
||||
/** Clear every per-SELECTION tracked-model latch: the zoom hysteresis band and
|
||||
* the load-failure bound. Called from each path that changes which contact is
|
||||
/** Clear the per-SELECTION tracked-model latch: the zoom hysteresis band.
|
||||
* Called from each path that changes which contact is
|
||||
* selected — deselect, re-track, cross-layer handoff, init, destroy.
|
||||
*
|
||||
* This must live in the production lifecycle, not only in the predicate's
|
||||
@@ -350,44 +347,11 @@ export function createTracking({
|
||||
* icao (Contacts re-entry, a cross-layer round trip back to this layer) never
|
||||
* makes `_trackedIcao` *observably* change, so the guard never fires. Without
|
||||
* the reset, a contact dropped inside the hysteresis band comes back as a
|
||||
* MODEL above the ENTER ceiling, and a contact whose GLB had already failed
|
||||
* out would never get its retries back. Mirror of flights.js. */
|
||||
* MODEL above the ENTER ceiling. Mirror of flights.js. */
|
||||
|
||||
function _resetTrackedSelectionState() {
|
||||
flightState._trackedZoomLatched = false;
|
||||
flightState._trackedZoomLatchIcao = null;
|
||||
flightState._trackedModelFailIcao = null;
|
||||
flightState._trackedModelFailCount = 0;
|
||||
flightState._trackedModelRetryAtMs = 0;
|
||||
}
|
||||
|
||||
/** Whether the driver may start another tracked-model load this frame. */
|
||||
|
||||
function _trackedModelLoadAllowed(nowMs = Date.now()) {
|
||||
if (flightState._trackedModelFailIcao !== flightState._trackedIcao)
|
||||
return true; // untried selection
|
||||
if (flightState._trackedModelFailCount >= TRACKED_MODEL_MAX_LOAD_FAILS)
|
||||
return false;
|
||||
return nowMs >= flightState._trackedModelRetryAtMs;
|
||||
}
|
||||
|
||||
/** Record a rejected tracked-model load and arm the backoff / give-up latch. */
|
||||
|
||||
function _noteTrackedModelLoadFailure(url, err) {
|
||||
if (flightState._trackedModelFailIcao !== flightState._trackedIcao) {
|
||||
flightState._trackedModelFailIcao = flightState._trackedIcao;
|
||||
flightState._trackedModelFailCount = 0;
|
||||
}
|
||||
flightState._trackedModelFailCount += 1;
|
||||
flightState._trackedModelRetryAtMs =
|
||||
Date.now() + TRACKED_MODEL_RETRY_BACKOFF_MS;
|
||||
if (flightState._trackedModelFailCount >= TRACKED_MODEL_MAX_LOAD_FAILS) {
|
||||
console.warn(
|
||||
`[Data:Military] tracked 3D model gave up after ${flightState._trackedModelFailCount} failed loads of ${url} — ` +
|
||||
'this contact stays 2D until another is selected',
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -797,7 +761,7 @@ export function createTracking({
|
||||
flightState._trackedEntity = null;
|
||||
}
|
||||
parts.rendering._releaseTrackedModel();
|
||||
_resetTrackedSelectionState(); // the zoom band + load-failure budget belong to the selection we just dropped
|
||||
_resetTrackedSelectionState(); // the zoom band belongs to the selection we just dropped
|
||||
flightState._trackedIcao = null;
|
||||
// Hand the contact back to its icon only now, once it no longer reads as
|
||||
// tracked (the settle plans it as a fleet contact).
|
||||
@@ -860,7 +824,7 @@ export function createTracking({
|
||||
const iconCourse = icons.course(icao24, t);
|
||||
flightState._displayCourse.set(icao24, iconCourse);
|
||||
flightState._trackedIcao = icao24;
|
||||
_resetTrackedSelectionState(); // fresh selection: enter at the ENTER ceiling, full load-retry budget
|
||||
_resetTrackedSelectionState(); // fresh selection: enter at the ENTER ceiling
|
||||
flightState._cachedDRFrame = -1;
|
||||
flightState._lastTrackedRotation =
|
||||
screenProjectedRotation(
|
||||
@@ -899,7 +863,7 @@ export function createTracking({
|
||||
// resolves into an aircraft.
|
||||
//
|
||||
// The billboard stays SHOWN at all times and is hidden by going TRANSPARENT (alpha 0), not by
|
||||
// show=false: it drops its alpha only once the model GLB is preloaded (_planeModelLoaded), so
|
||||
// show=false: it drops its alpha only once the tracked model is drawing, so
|
||||
// there's neither a billboard+model double-image nor a gap. The camera follows its own target
|
||||
// through the camera port, so nothing here frames the camera.
|
||||
// The tracked entity is a PURE BILLBOARD — no label or model graphic. The tracked plane's 3D
|
||||
@@ -1094,17 +1058,11 @@ export function createTracking({
|
||||
// any pick carrying its icao) — same no-op as the 2D tracked-entity click
|
||||
// above. H1: the model used to have no pick id, so this fell through to
|
||||
// "empty space" and deselected the very plane being tracked.
|
||||
if (flightState._trackedIcao) {
|
||||
const rawPick = aircraftPickId(picked);
|
||||
if (
|
||||
(flightState._trackedModel &&
|
||||
picked.primitive === flightState._trackedModel.model) ||
|
||||
rawPick === flightState._trackedIcao
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
// Its models are draw-set items keyed by icao, like its icons.
|
||||
const pickedIcao = aircraftPickId(picked);
|
||||
if (flightState._trackedIcao && pickedIcao === flightState._trackedIcao)
|
||||
return;
|
||||
|
||||
if (pickedIcao && flightState._icons?.has(pickedIcao)) {
|
||||
_cancelPendingTrackingRestore();
|
||||
_trackFlight(pickedIcao, { origin: 'user' });
|
||||
@@ -1147,8 +1105,6 @@ export function createTracking({
|
||||
_refreshTr3bContact,
|
||||
_refreshTr3bForStyle,
|
||||
_resetTrackedSelectionState,
|
||||
_trackedModelLoadAllowed,
|
||||
_noteTrackedModelLoadFailure,
|
||||
_trackedModelRegimeActive,
|
||||
_syncTracked2dRotation,
|
||||
_trailFloorPosition,
|
||||
|
||||
Reference in new issue
Block a user