mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Draw military flights from the shared GPU icon set
The flights icon planning and presentation move into `createAircraftIcons` (src/data/aircraftIconLayer.js), and the motion regime both layers dead-reckon from into src/data/aircraftMotionRegime.js. Flights keeps only its grounded-floor pass on top. Military now draws every contact as a row of that icon set, like flights: the billboards, the cull positions and the rotation-pass signature go. Tracking hides the row and untracking re-plans it from the tracked course. Queries read the drawn row position and judge the horizon as the shader does. Snapshots that arrive before init or after destroy are ignored, and per-contact lookups find no contact then instead of throwing. With about 120 live military contacts, preRender p95 drops from 0.7-0.8 ms to 0.2 ms on the same views. Render time and frame gaps are unchanged or slightly lower.
This commit is contained in:
1 parent
2c4c66c710
commit
9fde0a2a59
33 files changed
+1256
-1376
No files matched your search
+37
-361
@@ -1,35 +1,11 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { courseSlewCapDps, norm180 } from '../../data/motionModel.js';
|
||||
import {
|
||||
COURSE_HOLD_SPEED_MPS,
|
||||
courseBetweenCartesians,
|
||||
courseSlewCapDps,
|
||||
norm180,
|
||||
speedRamp,
|
||||
staleCoastLimitSeconds,
|
||||
} from '../../data/motionModel.js';
|
||||
import {
|
||||
createIconSet,
|
||||
ICON_CULL_LIFT,
|
||||
ICON_RECEDES,
|
||||
ICON_ROTATES,
|
||||
} from '../../data/iconSet.js';
|
||||
import {
|
||||
segmentCourse,
|
||||
segmentTargetCourse,
|
||||
writeArcSegment,
|
||||
writeCourseGlide,
|
||||
writeHoldSegment,
|
||||
writeLerpSegment,
|
||||
} from '../../data/iconSegment.js';
|
||||
import { IconSetPrimitive } from '../../data/iconSetPrimitive.js';
|
||||
import { iconAtlas } from '../../data/iconAtlas.js';
|
||||
import {
|
||||
aircraftIcon,
|
||||
FLEET_ICON_PX,
|
||||
TRACKED_ICON_PX,
|
||||
} from '../../data/aircraftIcons.js';
|
||||
import { cockpitContactDotImage } from '../../data/cockpitContactDot.js';
|
||||
import { horizonOccluder } from '../../data/iconOrientation.js';
|
||||
import { createAircraftIcons } from '../../data/aircraftIconLayer.js';
|
||||
import {
|
||||
COCKPIT_CONTACT_SIZE_PX,
|
||||
COURSE_MAX_DPS,
|
||||
@@ -38,184 +14,48 @@ import {
|
||||
RENDER_DELAY_SEC,
|
||||
} from './policy.js';
|
||||
|
||||
/** Raster size of the cockpit contact pip (cockpitContactDot.js draws 16 px). */
|
||||
const COCKPIT_DOT_PX = 16;
|
||||
/** Pinned grounded rows rewrite only past this displayed move (m²) or turn (°). */
|
||||
const PIN_MOVE_SQ_M = 1;
|
||||
const PIN_TURN_DEG = 0.1;
|
||||
|
||||
/**
|
||||
* The flights layer's contacts as one icon set: each row's motion segment
|
||||
* mirrors `_deadReckon`'s regime for the delayed display time, so the GPU
|
||||
* moves every untracked contact between polls with no per-frame CPU pass.
|
||||
* The flights layer's contacts as one icon set (`createAircraftIcons`), plus
|
||||
* the grounded floor: a floor-pinned row holds a CPU position, so it is not
|
||||
* planned, and settling a grounded contact puts it straight onto the floor.
|
||||
*/
|
||||
export function createIcons({ flightState, services, parts }) {
|
||||
const { focusPassIsNeeded } = services.focus;
|
||||
const scratchTime = new Cesium.JulianDate();
|
||||
const scratchPosition = new Cesium.Cartesian3();
|
||||
const scratchCull = new Cesium.Cartesian3();
|
||||
const scratchScaleByDistance = new Cesium.NearFarScalar();
|
||||
let normalScaleByDistance = null;
|
||||
let cockpitScaleByDistance = null;
|
||||
|
||||
/** The delayed instant every untracked contact is drawn at. */
|
||||
function _displayTime(result = scratchTime) {
|
||||
return Cesium.JulianDate.addSeconds(
|
||||
Cesium.JulianDate.now(result),
|
||||
-RENDER_DELAY_SEC,
|
||||
result,
|
||||
);
|
||||
}
|
||||
|
||||
function _displayTau() {
|
||||
return flightState._icons.seconds(_displayTime());
|
||||
}
|
||||
|
||||
/** Create the set and its primitive for one layer lifetime. */
|
||||
function _createIcons(viewer) {
|
||||
flightState._icons = createIconSet({ epoch: _displayTime() });
|
||||
flightState._iconPrimitive = new IconSetPrimitive({
|
||||
set: flightState._icons,
|
||||
renderTime: () => _displayTime(flightState._scratchIconRenderTime),
|
||||
});
|
||||
viewer.scene.primitives.add(flightState._iconPrimitive);
|
||||
return flightState._iconPrimitive;
|
||||
}
|
||||
|
||||
/** Where a contact is drawn right now, or null when it has no row. */
|
||||
function _iconPosition(icao24, result = new Cesium.Cartesian3()) {
|
||||
const set = flightState._icons;
|
||||
const row = set.row(icao24);
|
||||
return row < 0 ? null : set.position(row, _displayTau(), result);
|
||||
}
|
||||
|
||||
/** The nose direction a contact is drawn with right now. */
|
||||
function _iconCourse(icao24) {
|
||||
const set = flightState._icons;
|
||||
const row = set.row(icao24);
|
||||
return row < 0 ? null : set.course(row, _displayTau());
|
||||
}
|
||||
|
||||
/** Whether the layer draws this contact's icon (not tracked, not model-owned). */
|
||||
function _iconShown(icao24) {
|
||||
const set = flightState._icons;
|
||||
const row = set.row(icao24);
|
||||
return row >= 0 && set.shown(row);
|
||||
}
|
||||
|
||||
/** The camera's horizon test, or null when there is no placed camera. */
|
||||
function _occluder() {
|
||||
const camera = flightState._viewer?.camera;
|
||||
return camera?.positionWC ? horizonOccluder(camera) : null;
|
||||
}
|
||||
|
||||
/** Whether a drawn row at `position` clears the camera's horizon, judged
|
||||
* exactly as the icon shader judges it. No camera, no horizon. */
|
||||
function _aboveHorizon(row, position, occluder) {
|
||||
return (
|
||||
!occluder ||
|
||||
occluder.isPointVisible(
|
||||
flightState._icons.cullPoint(row, position, scratchCull),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the segment `_deadReckon` would follow from now on: interpolation
|
||||
* between the bracketing fixes, the warm-up arc back from the oldest fix, or
|
||||
* the coast arc past the newest. The displayed nose glides from where it is
|
||||
* onto the new course at the fleet's slew cap; a hovering contact keeps its
|
||||
* nose. The row expires when the regime would change.
|
||||
* @param {string} icao24
|
||||
* @param {{fromCourseDeg?: number|null}} [options] Nose to glide from when
|
||||
* the row's own segment is not what was on screen (tracking handoff).
|
||||
*/
|
||||
function _planIcon(icao24, { fromCourseDeg } = {}) {
|
||||
const set = flightState._icons;
|
||||
const row = set.row(icao24);
|
||||
if (row < 0) return;
|
||||
if (flightState._focusEvidenceIds.has(icao24)) return;
|
||||
if (flightState._floorPinned.has(icao24)) return;
|
||||
const history = flightState._positionHistory.get(icao24);
|
||||
if (!history?.length) return;
|
||||
const info = flightState.records.data.get(icao24);
|
||||
const renderTime = _displayTime();
|
||||
const tau = set.seconds(renderTime);
|
||||
const seg = set.segments;
|
||||
const shownCourse =
|
||||
fromCourseDeg ??
|
||||
(set.expires(row) === -Infinity ? null : set.course(row, tau));
|
||||
|
||||
const regime = parts.motion._motionRegime(history, info, renderTime);
|
||||
let speed;
|
||||
let expiresAt = Infinity;
|
||||
if (regime.kind === 'between') {
|
||||
const { a, b, span, trackFrom, trackTo, chordCourse } = regime;
|
||||
speed = regime.speed;
|
||||
const blend = chordCourse == null ? 0 : regime.blend;
|
||||
const t0 = set.seconds(a.time);
|
||||
if (span > 0) {
|
||||
writeLerpSegment(seg, row, {
|
||||
from: a.position,
|
||||
to: b.position,
|
||||
t0,
|
||||
t1: set.seconds(b.time),
|
||||
course0Deg:
|
||||
trackFrom + blend * norm180((chordCourse ?? 0) - trackFrom),
|
||||
courseSlopeDeg: norm180(trackTo - trackFrom) * (1 - blend),
|
||||
});
|
||||
} else {
|
||||
writeHoldSegment(
|
||||
seg,
|
||||
row,
|
||||
b.position,
|
||||
trackTo + blend * norm180((chordCourse ?? 0) - trackTo),
|
||||
);
|
||||
}
|
||||
expiresAt = set.seconds(b.time);
|
||||
} else {
|
||||
const { fix, heading } = regime;
|
||||
speed = regime.speed;
|
||||
const t0 = set.seconds(fix.time);
|
||||
if (speed === 0) {
|
||||
writeHoldSegment(seg, row, fix.position, heading);
|
||||
} else {
|
||||
writeArcSegment(seg, row, {
|
||||
fix: fix.position,
|
||||
t0,
|
||||
minDt: regime.minDt,
|
||||
maxDt: regime.maxDt,
|
||||
speedMps: speed,
|
||||
trackDeg: heading,
|
||||
turnRateDps: regime.turnRateDps,
|
||||
});
|
||||
}
|
||||
// A warm-up's arc ends at its fix; a coast's runs to its limit.
|
||||
if (regime.maxDt === 0) expiresAt = t0;
|
||||
}
|
||||
// Below hover speed the nose holds what is on screen (or, for a new row,
|
||||
// where this segment starts); above it, it glides on at the slew cap.
|
||||
const hold = speed < COURSE_HOLD_SPEED_MPS;
|
||||
if (hold || shownCourse != null) {
|
||||
writeCourseGlide(
|
||||
seg,
|
||||
row,
|
||||
shownCourse ?? segmentCourse(seg, row, tau),
|
||||
tau,
|
||||
hold ? 0 : courseSlewCapDps(speed, COURSE_MAX_DPS),
|
||||
const icons = createAircraftIcons({
|
||||
state: flightState,
|
||||
services,
|
||||
parts,
|
||||
layerId: 'flights',
|
||||
renderDelaySec: RENDER_DELAY_SEC,
|
||||
courseMaxDps: COURSE_MAX_DPS,
|
||||
cockpitContactSizePx: COCKPIT_CONTACT_SIZE_PX,
|
||||
holdsPlan: (icao24) =>
|
||||
flightState._focusEvidenceIds.has(icao24) ||
|
||||
flightState._floorPinned.has(icao24),
|
||||
// A pin stops at the last floor pass, which skips a tracked contact.
|
||||
beforeSettle: (icao24) => flightState._floorPinned.delete(icao24),
|
||||
// Straight onto the floor under where it is drawn, not its fix's floor
|
||||
// until the next fleet tick raises it.
|
||||
afterSettle(icao24) {
|
||||
if (!flightState._grounded.has(icao24)) return;
|
||||
const renderTime = icons._displayTime();
|
||||
_floorIcon(
|
||||
icao24,
|
||||
renderTime,
|
||||
flightState._icons.seconds(renderTime),
|
||||
Date.now(),
|
||||
);
|
||||
}
|
||||
set.segmentWritten(row, expiresAt);
|
||||
}
|
||||
|
||||
/** Re-plan every row whose regime ended before `tau`. */
|
||||
function _replanExpired(tau) {
|
||||
const set = flightState._icons;
|
||||
const due = [];
|
||||
for (let row = 0; row < set.count; row++)
|
||||
if (set.expires(row) <= tau) due.push(set.idAt(row));
|
||||
for (const icao24 of due) _planIcon(icao24);
|
||||
}
|
||||
},
|
||||
onForget(icao24) {
|
||||
flightState._displayFloorState.delete(icao24);
|
||||
flightState._grounded.delete(icao24);
|
||||
flightState._floorPinned.delete(icao24);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Grounded contacts stand on the floor under where they are DRAWN, which the
|
||||
@@ -272,7 +112,7 @@ export function createIcons({ flightState, services, parts }) {
|
||||
);
|
||||
if (!display || display === raw) {
|
||||
if (flightState._floorPinned.delete(icao24))
|
||||
_planIcon(icao24, { fromCourseDeg: set.course(row, tau) });
|
||||
icons._planIcon(icao24, { fromCourseDeg: set.course(row, tau) });
|
||||
return;
|
||||
}
|
||||
const planned = set.expires(row) !== -Infinity;
|
||||
@@ -303,169 +143,5 @@ export function createIcons({ flightState, services, parts }) {
|
||||
set.segmentWritten(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance focus de-emphasis for every drawn row (and every row a fleet model
|
||||
* draws for, whose alpha reads it), only while a focus target exists or some
|
||||
* row is still relaxing back to full emphasis.
|
||||
*/
|
||||
function _focusIcons(tau, scene, camera, nowMs, target) {
|
||||
if (!focusPassIsNeeded(target, flightState._iconFocusActive)) return;
|
||||
const { advanceProjectedSpriteFocus, nearFarScalarValueAtDistance } =
|
||||
services.focus;
|
||||
const set = flightState._icons;
|
||||
let active = 0;
|
||||
for (let row = 0; row < set.count; row++) {
|
||||
if (!set.shown(row) && !flightState._models.has(set.idAt(row))) continue;
|
||||
const position = set.position(row, tau, scratchPosition);
|
||||
const distanceScale = nearFarScalarValueAtDistance(
|
||||
set.scaleByDistance(row, scratchScaleByDistance),
|
||||
Cesium.Cartesian3.distance(camera.positionWC, position),
|
||||
);
|
||||
const half = set.scale(row) * distanceScale * 0.5;
|
||||
const focus = advanceProjectedSpriteFocus(
|
||||
set.metaAt(row),
|
||||
position,
|
||||
scene,
|
||||
camera,
|
||||
nowMs,
|
||||
target,
|
||||
undefined,
|
||||
set.width(row) * half,
|
||||
set.height(row) * half,
|
||||
);
|
||||
set.setFocus(row, focus.factor);
|
||||
if (focus.active || focus.transitioning) active++;
|
||||
}
|
||||
flightState._iconFocusActive = active;
|
||||
}
|
||||
|
||||
/** Image, size, scale, tint and freshness for one row under the current
|
||||
* normal/cockpit contract. Motion and rotation stay with the segment. */
|
||||
function _applyIconPresentation(icao24) {
|
||||
const set = flightState._icons;
|
||||
const row = set.row(icao24);
|
||||
if (row < 0) return;
|
||||
const info = flightState.records.data.get(icao24);
|
||||
const tracked = icao24 === flightState._trackedIcao;
|
||||
const cockpitDot =
|
||||
flightState._cockpitContactMode &&
|
||||
!tracked &&
|
||||
!flightState._cockpitNearContacts.has(icao24);
|
||||
if (cockpitDot) {
|
||||
const dot = iconAtlas.slot(cockpitContactDotImage(), COCKPIT_DOT_PX);
|
||||
set.setImage(row, dot, dot);
|
||||
set.setSize(row, COCKPIT_CONTACT_SIZE_PX, COCKPIT_CONTACT_SIZE_PX);
|
||||
set.setScale(row, 1);
|
||||
cockpitScaleByDistance ??=
|
||||
parts.rendering._cockpitBillboardScaleByDistance();
|
||||
set.setScaleByDistance(row, cockpitScaleByDistance);
|
||||
set.setColor(row, parts.rendering._cockpitContactColor(icao24, info));
|
||||
set.setFlag(row, ICON_ROTATES, false);
|
||||
} else {
|
||||
set.setImage(
|
||||
row,
|
||||
iconAtlas.slot(
|
||||
aircraftIcon(parts.rendering._iconKind(icao24, info?.klass)),
|
||||
FLEET_ICON_PX,
|
||||
),
|
||||
iconAtlas.slot(
|
||||
aircraftIcon(
|
||||
parts.rendering._iconKind(icao24, info?.klass),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
);
|
||||
const size = tracked ? 24 : 20;
|
||||
set.setSize(row, size, size);
|
||||
set.setScale(
|
||||
row,
|
||||
parts.rendering._fleetBillboardScale(icao24, info?.klass),
|
||||
);
|
||||
normalScaleByDistance ??=
|
||||
parts.rendering._normalBillboardScaleByDistance();
|
||||
set.setScaleByDistance(row, normalScaleByDistance);
|
||||
set.setColor(row, parts.rendering._fleetBillboardColor(icao24, info));
|
||||
set.setFlag(row, ICON_ROTATES, true);
|
||||
}
|
||||
set.setFlag(row, ICON_RECEDES, true);
|
||||
set.setFlag(
|
||||
row,
|
||||
ICON_CULL_LIFT,
|
||||
Number.isFinite(info?.renderAltitudeM) && info.renderAltitudeM < 10,
|
||||
);
|
||||
set.setAlpha(row, flightState.records.missingPolls.get(icao24) ? 0.45 : 1);
|
||||
}
|
||||
|
||||
/** Add a row for a new contact, hidden while it is the tracked one. */
|
||||
function _addIcon(icao24) {
|
||||
const set = flightState._icons;
|
||||
const row = set.add(icao24, { layer: 'flights', id: icao24 });
|
||||
_applyIconPresentation(icao24);
|
||||
_settleIcon(icao24);
|
||||
set.setShown(row, icao24 !== flightState._trackedIcao);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plan a row afresh, dropping any floor pin (a pin stops at the last floor
|
||||
* pass, which skips a tracked contact), and let a dimmed row relax. A grounded contact goes straight onto
|
||||
* the floor under where it is drawn, not its fix's floor until the next fleet
|
||||
* tick raises it.
|
||||
* @param {string} icao24
|
||||
* @param {{fromCourseDeg?: number}} [options] The course on screen to glide from.
|
||||
*/
|
||||
function _settleIcon(icao24, options) {
|
||||
const set = flightState._icons;
|
||||
flightState._floorPinned.delete(icao24);
|
||||
// A row that sat out the focus pass (tracked) may come back dimmed after
|
||||
// the pass went idle; count it so the pass runs and relaxes it.
|
||||
if (set.focus(set.row(icao24)) < 1) flightState._iconFocusActive += 1;
|
||||
_planIcon(icao24, options);
|
||||
if (flightState._grounded.has(icao24)) {
|
||||
const renderTime = _displayTime();
|
||||
_floorIcon(icao24, renderTime, set.seconds(renderTime), Date.now());
|
||||
}
|
||||
}
|
||||
|
||||
/** Drop a contact and everything the layer keeps for it. */
|
||||
function _forgetContact(icao24) {
|
||||
flightState._icons?.remove(icao24);
|
||||
parts.rendering._releaseModel(icao24);
|
||||
flightState.records.forget(icao24);
|
||||
flightState._positionHistory.delete(icao24);
|
||||
flightState._displayCourse.delete(icao24);
|
||||
flightState._groundSnap.forget(icao24);
|
||||
flightState._displayFloorState.delete(icao24);
|
||||
flightState._grounded.delete(icao24);
|
||||
flightState._floorPinned.delete(icao24);
|
||||
}
|
||||
|
||||
/** Icon ids, so ray samples never land on an aircraft instead of the ground. */
|
||||
function _iconIds() {
|
||||
const set = flightState._icons;
|
||||
const ids = new Array(set?.count ?? 0);
|
||||
for (let row = 0; row < ids.length; row++) ids[row] = set.idAt(row);
|
||||
return ids;
|
||||
}
|
||||
|
||||
return {
|
||||
_displayTime,
|
||||
_displayTau,
|
||||
_createIcons,
|
||||
_iconPosition,
|
||||
_iconCourse,
|
||||
_iconShown,
|
||||
_occluder,
|
||||
_aboveHorizon,
|
||||
_planIcon,
|
||||
_settleIcon,
|
||||
_replanExpired,
|
||||
_floorGroundedIcons,
|
||||
_focusIcons,
|
||||
_applyIconPresentation,
|
||||
_addIcon,
|
||||
_forgetContact,
|
||||
_iconIds,
|
||||
};
|
||||
return { ...icons, _floorGroundedIcons };
|
||||
}
|
||||
+22
-113
@@ -2,9 +2,6 @@ import * as Cesium from 'cesium';
|
||||
import {
|
||||
COURSE_HOLD_SPEED_MPS,
|
||||
lerpAngleDeg,
|
||||
speedRamp,
|
||||
courseBetweenCartesians,
|
||||
staleCoastLimitSeconds,
|
||||
arcOffsetEnu,
|
||||
courseSlewCapDps,
|
||||
limitCourseStep,
|
||||
@@ -37,20 +34,15 @@ import {
|
||||
} from './policy.js';
|
||||
import { modelState } from '../../data/modelMirror.js';
|
||||
import { readEntityRecord } from '../../data/entityRecords.js';
|
||||
import {
|
||||
aircraftMotionRegime,
|
||||
createMotionRegime,
|
||||
fixSpeedMps,
|
||||
fixTrackDeg,
|
||||
} from '../../data/aircraftMotionRegime.js';
|
||||
|
||||
/** A fix's own ground speed, else the record's. */
|
||||
function fixSpeedMps(fix, info) {
|
||||
return Number.isFinite(fix.velocity)
|
||||
? fix.velocity
|
||||
: (info && info.velocity) || 0;
|
||||
}
|
||||
|
||||
/** A fix's own track, else the record's. */
|
||||
function fixTrackDeg(fix, info) {
|
||||
return Number.isFinite(fix.track)
|
||||
? fix.track
|
||||
: (info && info.true_track) || 0;
|
||||
}
|
||||
/** Where a flights record carries its reported speed and track. */
|
||||
const RECORD_FIELDS = { speed: 'velocity', track: 'true_track' };
|
||||
|
||||
export function createMotion({
|
||||
flightState,
|
||||
@@ -80,22 +72,7 @@ export function createMotion({
|
||||
// the local frame even when the existing Cartesian is mutated in place.
|
||||
const fixFrames = new WeakMap();
|
||||
/** `_motionRegime`'s reused result. */
|
||||
const regime = {
|
||||
kind: 'fix',
|
||||
a: null,
|
||||
b: null,
|
||||
span: 0,
|
||||
speed: 0,
|
||||
trackFrom: 0,
|
||||
trackTo: 0,
|
||||
chordCourse: null,
|
||||
blend: 0,
|
||||
fix: null,
|
||||
heading: 0,
|
||||
turnRateDps: 0,
|
||||
minDt: 0,
|
||||
maxDt: 0,
|
||||
};
|
||||
const regime = createMotionRegime();
|
||||
|
||||
// Round 5: the old `_warmGroundedAircraftSurfaceCache` (global exact-5-decimal
|
||||
// warm for every grounded contact on Earth) is GONE. Parked-aircraft GPS
|
||||
@@ -221,86 +198,18 @@ export function createMotion({
|
||||
|
||||
/**
|
||||
* Which motion a contact's history gives at `renderTime` — the one choice
|
||||
* `_deadReckon` (CPU) and the icon planner (GPU segment) both draw from.
|
||||
*
|
||||
* - `between`: interpolate the bracketing pair `a`→`b`, no extrapolation
|
||||
* error and no snap-back. The course of the DISPLAYED motion blends the
|
||||
* time-interpolated reported track toward the chord by `blend`: the chord
|
||||
* is only trustworthy when the segment covers real ground (at hover its
|
||||
* direction is GPS jitter; on a slow tight turn it STEPS the whole
|
||||
* per-segment turn at each boundary), and helicopters never use it
|
||||
* (rotorcraft chords are noise-dominated at their typical speeds).
|
||||
* - `fix`: extrapolate `fix` by the elapsed time clamped to [minDt, maxDt].
|
||||
* Warm-up (renderTime predates ALL history: freshly seen or just tracked,
|
||||
* before RENDER_DELAY_SEC of history exists) runs the OLDEST fix BACKWARD,
|
||||
* preserving the 30s-behind invariant, so as history fills the icon glides
|
||||
* FORWARD into interpolation with no freeze and no backward snap (holding
|
||||
* the oldest fix froze the icon; extrapolating the newest to wall-clock
|
||||
* made it jump back a poll interval when interpolation took over).
|
||||
* Otherwise the newest fix coasts. OpenSky can still be receiving fresh
|
||||
* contact messages for that aircraft; freezing 60 s after the position
|
||||
* produced a stop → catch-up → stop cadence, so it coasts through the latest
|
||||
* real contact plus a bounded grace, with an absolute cap so a stale cached
|
||||
* feed cannot drift forever.
|
||||
*
|
||||
* The returned object is a reused scratch: read it before the next call.
|
||||
* @param {Array<object>} history Non-empty, oldest first.
|
||||
* @param {object|undefined} info The contact's record.
|
||||
* @param {Cesium.JulianDate} renderTime
|
||||
* `_deadReckon` (CPU) and the icon planner (GPU segment) both draw from
|
||||
* (`aircraftMotionRegime`). The result is a reused scratch: read it before
|
||||
* the next call.
|
||||
*/
|
||||
function _motionRegime(history, info, renderTime) {
|
||||
for (let i = history.length - 1; i >= 1; i--) {
|
||||
const a = history[i - 1];
|
||||
const b = history[i];
|
||||
if (
|
||||
!Cesium.JulianDate.lessThanOrEquals(a.time, renderTime) ||
|
||||
!Cesium.JulianDate.lessThanOrEquals(renderTime, b.time)
|
||||
)
|
||||
continue;
|
||||
const span = Cesium.JulianDate.secondsDifference(b.time, a.time);
|
||||
const chordLenM = Cesium.Cartesian3.distance(a.position, b.position);
|
||||
const speed = span > 0 ? chordLenM / span : (info && info.velocity) || 0;
|
||||
const fallbackTrack = (info && info.true_track) || 0;
|
||||
const trackFrom = Number.isFinite(a.track) ? a.track : fallbackTrack;
|
||||
const blend = info && info.klass === 'helicopter' ? 0 : speedRamp(speed);
|
||||
regime.kind = 'between';
|
||||
regime.a = a;
|
||||
regime.b = b;
|
||||
regime.span = span;
|
||||
regime.speed = speed;
|
||||
regime.trackFrom = trackFrom;
|
||||
regime.trackTo = Number.isFinite(b.track) ? b.track : trackFrom;
|
||||
regime.chordCourse =
|
||||
blend > 0 ? courseBetweenCartesians(a.position, b.position) : null;
|
||||
regime.blend = blend;
|
||||
return regime;
|
||||
}
|
||||
const newest = history[history.length - 1];
|
||||
const warming = Cesium.JulianDate.lessThan(renderTime, history[0].time);
|
||||
regime.kind = 'fix';
|
||||
regime.fix = warming ? history[0] : newest;
|
||||
regime.speed = fixSpeedMps(regime.fix, info);
|
||||
regime.heading = fixTrackDeg(regime.fix, info);
|
||||
regime.turnRateDps = (info && info.turnRateDps) || 0;
|
||||
regime.minDt = -60;
|
||||
// A warm-up ends when real time reaches the oldest fix; a single fix keeps
|
||||
// coasting forward on the same arc.
|
||||
regime.maxDt =
|
||||
warming && history.length > 1
|
||||
? 0
|
||||
: staleCoastLimitSeconds({
|
||||
// `epochMs` is captured once when the poll is normalized. Avoid
|
||||
// allocating a Date per aircraft on every 12 Hz fleet tick.
|
||||
fixEpochMs: Number.isFinite(newest.epochMs)
|
||||
? newest.epochMs
|
||||
: Cesium.JulianDate.toDate(newest.time).getTime(),
|
||||
lastContactEpochMs: info?.lastContactEpochMs,
|
||||
// Permit one minute of contact grace but cap any cached-feed drift
|
||||
// at five minutes. Source backoff is exposed separately as a STALE cue.
|
||||
minimumSec: 60,
|
||||
maximumSec: 300,
|
||||
});
|
||||
return regime;
|
||||
return aircraftMotionRegime(
|
||||
history,
|
||||
info,
|
||||
renderTime,
|
||||
RECORD_FIELDS,
|
||||
regime,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,8 +224,8 @@ export function createMotion({
|
||||
*/
|
||||
|
||||
function _extrapolateFix(fix, info, dt, out, turnRateDps = 0) {
|
||||
const speed = fixSpeedMps(fix, info);
|
||||
const heading = fixTrackDeg(fix, info);
|
||||
const speed = fixSpeedMps(fix, info, RECORD_FIELDS);
|
||||
const heading = fixTrackDeg(fix, info, RECORD_FIELDS);
|
||||
flightState._drSpeedMps = speed;
|
||||
flightState._drCourseHold = speed < COURSE_HOLD_SPEED_MPS;
|
||||
flightState._drExtrapolating = true;
|
||||
@@ -533,7 +442,7 @@ export function createMotion({
|
||||
* readout run in postRender at a LATER frameNumber, so calling _trackedDisplayPosition there would
|
||||
* re-run the dead-reckon on a fresh sample and double-advance the reconciliation → the label jitters
|
||||
* against the now-stable plane (the model's jitter fix, resurfacing in the labels). Returns null when
|
||||
* there's no valid fix for the tracked aircraft, so callers fall back to the billboard position. */
|
||||
* there's no valid fix for the tracked aircraft, so callers fall back to the icon position. */
|
||||
|
||||
function _trackedDisplayCached() {
|
||||
return flightState._drReconcileValid &&
|
||||
|
||||
@@ -147,3 +147,17 @@ test('voice context reads a track that rounds to north as 0°, not 360°', () =>
|
||||
'0°',
|
||||
);
|
||||
});
|
||||
|
||||
test('a flight layer without an icon set declines contact refreshes', () => {
|
||||
// Before init and after destroy there are no icon rows: a TR-3B refresh
|
||||
// reports that the layer owns no such contact instead of throwing.
|
||||
const layer = createCivilFlightLayer({
|
||||
source: { label: 'Fixture aircraft', getSnapshot() {} },
|
||||
services: {
|
||||
...services(),
|
||||
aircraftPresentation: { isTr3b: () => true, tr3bConvertedIds: () => [] },
|
||||
},
|
||||
});
|
||||
assert.equal(layer.refreshTr3b('abc123'), false);
|
||||
assert.equal(layer.trackById('abc123'), false);
|
||||
});
|
||||
@@ -181,23 +181,17 @@ export const LANDED_SPEED_MAX_MPS = 23;
|
||||
/** @constant {number} Max viewer distance (km) for the fleet ground-floor clamp. */
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Icon orientation (2026-06-10 playtest fix): rotation is computed by
|
||||
// projecting each aircraft's course vector into WINDOW coordinates
|
||||
// (iconOrientation.js) with alignedAxis always ZERO — exact at every camera
|
||||
// pitch/heading, including tracked-entity orbit mode. Rotation passes run on
|
||||
// the fleet tick only when the camera pose changed (or 1s drift catch-up).
|
||||
// The same tick horizon-culls billboards: with the Cesium globe hidden there
|
||||
// is no far-side depth, so planes otherwise show through the planet.
|
||||
// Fleet icons are one GPU icon set (iconSet.js): the shader dead-reckons each
|
||||
// row's motion segment, projects its course into window coordinates and
|
||||
// horizon-culls it (with the Cesium globe hidden there is no far-side depth,
|
||||
// so planes otherwise show through the planet). The fleet tick only re-plans
|
||||
// expired rows and drives the model handoff.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** @constant {number} Fleet dead-reckoning tick interval (ms) — ~12Hz, not per-frame. */
|
||||
|
||||
export const FLEET_DR_INTERVAL_MS = 80;
|
||||
|
||||
/** @constant {number} Max ms between rotation passes while the camera is idle. */
|
||||
|
||||
export const ROTATION_REFRESH_MS = 1000;
|
||||
|
||||
/** Max course slew (deg/s) — well above real turns (≤4°/s), hides fix-boundary
|
||||
* steps. Scaled down toward COURSE_MIN_DPS at low speed (courseSlewCapDps). */
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ export function createRendering({
|
||||
id: icao24, // so scene.pick returns the icao for click-to-track
|
||||
});
|
||||
} catch {
|
||||
// asset/decode fail — stay billboard. Only touch this lifecycle's state if still current
|
||||
// asset/decode fail — stay an icon. Only touch this lifecycle's state if still current
|
||||
// (a destroy/re-init may have swapped the globals while this load was in flight).
|
||||
if (epoch === flightState._modelEpoch) {
|
||||
flightState._modelPending.delete(icao24);
|
||||
@@ -509,7 +509,7 @@ export function createRendering({
|
||||
visual.specKey = specKey; // class-change sync compares against this
|
||||
visual.irBoost = loadIrBoost; // boost-flip reload queue compares against this
|
||||
// Admitted, not yet the visual. Cesium's default is show=true, which would let
|
||||
// an unplaced primitive claim ownership from the billboard for the frames
|
||||
// an unplaced primitive claim ownership from the icon for the frames
|
||||
// between admission and the next fleet tick (and draw at the identity matrix,
|
||||
// i.e. the Earth's centre). The handoff turns it on once it has a matrix.
|
||||
setModel(model, 'show', false);
|
||||
|
||||
@@ -24,6 +24,8 @@ export function createFlightSnapshotRenderer({
|
||||
const { warmGroundFloor } = groundFloor;
|
||||
const { sampleMeshFloorCells } = meshFloor;
|
||||
return function applySnapshot(snapshot, viewer) {
|
||||
// Before init (or after destroy) there is no icon set to draw into.
|
||||
if (!flightState._icons) return { count: 0, ids: new Set() };
|
||||
const currentIcaos = new Set();
|
||||
const acceptedSnapshotIcaos = new Set();
|
||||
// Field-test round 3 (2026-07-06, Austin fleet-underground): viewer
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as Cesium from 'cesium';
|
||||
import { CYAN_TRANSPARENT } from './policy.js';
|
||||
import { mirrorModel } from '../../data/modelMirror.js';
|
||||
import { createIconSet } from '../../data/iconSet.js';
|
||||
import { writeHoldSegment } from '../../data/iconSegment.js';
|
||||
import { aircraftIconTestSeams } from '../../data/aircraftIconLayer.js';
|
||||
|
||||
export function createTesting({
|
||||
flightState,
|
||||
@@ -11,6 +11,8 @@ export function createTesting({
|
||||
layer,
|
||||
resolveAsset,
|
||||
}) {
|
||||
const { _seedIconForTest, _iconForTest, _setIconForTest } =
|
||||
aircraftIconTestSeams(flightState, parts, 'flights');
|
||||
/** Test seam for the display-floor clamp (unit-tested against real Cesium math
|
||||
* with seeded mesh cells — the drift mechanism is otherwise only reachable
|
||||
* through a live poll + render loop). */
|
||||
@@ -39,19 +41,6 @@ export function createTesting({
|
||||
flightState._displayFloorState.clear();
|
||||
}
|
||||
|
||||
/** Give a test contact an icon row held at `billboard.position`, shown as
|
||||
* `billboard.show` says (hidden by default while tracked). */
|
||||
|
||||
function _seedIconForTest(icao24, billboard, tracked) {
|
||||
const icons = flightState._icons;
|
||||
const row = icons.add(icao24, { layer: 'flights', id: icao24 });
|
||||
if (billboard?.position)
|
||||
writeHoldSegment(icons.segments, row, billboard.position, 0);
|
||||
icons.segmentWritten(row);
|
||||
icons.setShown(row, billboard?.show ?? !tracked);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed only the mutable state needed to exercise tracked-card refreshes through
|
||||
* the production poll reconciler. Tests still call `flightsLayer.update()`;
|
||||
@@ -212,38 +201,12 @@ export function createTesting({
|
||||
);
|
||||
}
|
||||
|
||||
/** Where a contact's icon is drawn now and whether the layer shows it. */
|
||||
|
||||
function _iconForTest(icao24) {
|
||||
const position = parts.icons._iconPosition(icao24);
|
||||
return position
|
||||
? {
|
||||
position,
|
||||
shown: parts.icons._iconShown(icao24),
|
||||
course: parts.icons._iconCourse(icao24),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
/** Exercise the exact asynchronous fleet loader and return its admitted model. */
|
||||
|
||||
async function _ensureFleetModelForTest(icao24) {
|
||||
await parts.rendering._ensureModel(icao24);
|
||||
return flightState._models.get(icao24) || null;
|
||||
}
|
||||
/** Show or hide a contact's icon as a handoff would, or hold it somewhere. */
|
||||
|
||||
function _setIconForTest(icao24, { shown, position } = {}) {
|
||||
const icons = flightState._icons;
|
||||
const row = icons?.row(icao24) ?? -1;
|
||||
if (row < 0) return;
|
||||
if (shown !== undefined) icons.setShown(row, shown);
|
||||
if (position) {
|
||||
writeHoldSegment(icons.segments, row, position, 0);
|
||||
icons.segmentWritten(row);
|
||||
}
|
||||
}
|
||||
|
||||
/** Run the fleet tick's grounded floor pass once, at `renderTime`. */
|
||||
|
||||
function _floorGroundedIconsForTest(renderTime, cameraPosition) {
|
||||
|
||||
@@ -164,7 +164,7 @@ export function createTracking({
|
||||
const distancesSquared = [];
|
||||
const icons = flightState._icons;
|
||||
const tau = parts.icons._displayTau();
|
||||
for (let row = 0; row < icons.count; row++) {
|
||||
for (let row = 0; row < (icons?.count ?? 0); row++) {
|
||||
const icao24 = icons.idAt(row);
|
||||
if (icao24 === flightState._trackedIcao) continue;
|
||||
const position = icons.position(row, tau, flightState._scratchCockpitPos);
|
||||
@@ -987,7 +987,7 @@ export function createTracking({
|
||||
alignedAxis: Cesium.Cartesian3.ZERO,
|
||||
// The tracked target must never vanish into tile geometry — tracking a
|
||||
// taxiing plane at street level would otherwise bury the cyan icon inside
|
||||
// the runway skin exactly like the fleet ground icons (_groundDepthDistance);
|
||||
// the runway skin, so it draws depth-test-free like the fleet icon set;
|
||||
// its shared-host tracked card is top-composited separately.
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
// Screen-projected rotation, evaluated per frame: exact in tracked-orbit
|
||||
|
||||
Reference in new issue
Block a user