Files
gods-eye-view/src/layers/flights/rendering.js
T
Sameh Khamis 2b5fb51684 Contacts move back as smoothly as they move on
A snapshot timeline may declare spanMs: each record of a snapshot at a
time then carries its own fixes from spanMs before the time to spanMs
after it. Flights, military flights and vessels following the clock are
placed on those fixes, so a seek or a move back within the fixes loaded
is no jump: nothing is cleared and play does not wait. The step there is
asked for once and stands in for every contact; those it has keep their
place. Fixes are merged across snapshots at least 20 s apart, at most
240 a contact, and a contact is not drawn more than a minute before its
first fix.
2026-11-15 09:27:31 -08:00

134 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
aircraftLayerModelSpec,
aircraftModelSpecCacheKey,
} from './modelSpec.js';
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
import { isEmergency } from '../../data/aircraftEmergency.js';
import {
MIL_TINT,
EMERGENCY_TINT,
FLEET_TINT,
TRACKED_CYAN,
GROUND_SCALE,
COCKPIT_CIVILIAN_COLOR,
} from './policy.js';
import * as policy from './policy.js';
import { createAircraftModels } from '../../data/aircraftModelLayer.js';
export function createRendering({
flightState,
services,
parts,
layer,
resolveAsset,
}) {
const { isMilitaryIcao } = services.militaryRegistry;
const { tr3bIconKind } = services.aircraftPresentation;
/** True while this contact's latest poll broadcast an emergency code. */
function _isEmergency(icao24, info = flightState.records.data.get(icao24)) {
return isEmergency(info?.emergency);
}
/** Fleet (untracked) billboard tint: red while broadcasting an emergency,
* amber for known-military, white otherwise.
* Ground traffic gets NO special tint (owner verdict 2026-07-03 field test). */
function _fleetBillboardColor(
icao24,
info = flightState.records.data.get(icao24),
) {
if (_isEmergency(icao24, info)) return EMERGENCY_TINT;
return isMilitaryIcao(icao24) ? MIL_TINT : FLEET_TINT;
}
/** Cockpit far-contact dot tint: the emergency red outranks the category tint. */
function _cockpitContactColor(
icao24,
info = flightState.records.data.get(icao24),
) {
if (_isEmergency(icao24, info)) return EMERGENCY_TINT;
return isMilitaryIcao(icao24) ? MIL_TINT : COCKPIT_CIVILIAN_COLOR;
}
/** Fleet billboard scale: per-class scale, ×GROUND_SCALE while grounded. */
function _fleetBillboardScale(icao24, klass) {
return (
(CLASS_SCALE_2D[klass] || 1) *
(flightState.records.data.get(icao24)?.onGround ? GROUND_SCALE : 1)
);
}
/** The fleet model an aircraft draws with, by its type and emitter category. */
function _modelSpec(meta) {
const key = aircraftModelSpecCacheKey(meta);
const cached = flightState._specCache.get(key);
if (cached) return cached;
const spec = aircraftLayerModelSpec(meta);
// Not cached before the model set loads: the answer changes once it has.
if (spec.model) flightState._specCache.set(key, spec);
return spec;
}
/** Sprite kind for one contact's billboard. Identity for every aircraft except
* the ones the operator converted into a TR-3B (Easter egg), which draw the
* black-triangle glyph — its thermal-reactive variant while an IR style owns
* the scene. Routing EVERY `aircraftIcon()` call through this is what makes a
* conversion survive the poll reconciler and the two-tier raster swap. */
const _iconKind = (icao24, klass) =>
tr3bIconKind(icao24, klass, { hot: flightState._irBoost });
/** Model colour: the mesh's own (white), tinted cyan while tracked and red
* while broadcasting an emergency. */
function _modelColor(icao24) {
if (icao24 === flightState._trackedIcao) return TRACKED_CYAN;
return _isEmergency(icao24) ? EMERGENCY_TINT : policy.MODEL_WHITE;
}
const models = createAircraftModels({
state: flightState,
services,
parts,
resolveAsset,
logLabel: 'Data:Flights',
setPrefix: 'flights',
policy,
modelSpec: _modelSpec,
modelColor: _modelColor,
// About to render in 3D: jump the ambient type-enrichment backlog.
onModelEligible: (icao24) =>
parts.enrichment._requestTypeEnrichment(icao24, true),
afterReplan: (renderTime, t, nowMs, eye) =>
parts.icons._floorGroundedIcons(renderTime, t, nowMs, eye),
});
/**
* Sample the rendered mesh under the collected floor cells (see
* meshFloorSampler.js), leaving this layer's own icon and model sets out
* of the probe so it cannot land on an aircraft instead of the pavement.
*/
function _sampleMeshFloor(points, viewerLat, viewerLon) {
services.meshFloor.sampleMeshFloorCells(flightState._viewer, points, {
sets: models._groundSampleExclusions().sets,
viewerLat,
viewerLon,
});
}
return {
_sampleMeshFloor,
_fleetBillboardColor,
_fleetBillboardScale,
_cockpitContactColor,
_modelSpec,
_iconKind,
_modelColor,
...models,
};
}