Deselecting a plane drawn as a model no longer flashes its icon

A selected plane is drawn by its own model, and its fleet model was let go once
that model drew. Deselecting showed the icon at once, and the icon stayed for
about a second while a new fleet model loaded.

The fleet model now stays loaded but hidden while the plane is selected, kept
where the plane is. Deselecting hands the plane back to it in the same frame,
and the icon shows only when there is no loaded fleet model. Military aircraft
share this code. Vessels never swap models on selection, so they had no flash.
This commit is contained in:
Sameh Khamis committed 2026-11-17 11:27:21 -08:00
1 parent 36624cd329
commit b041fea7a6
6 files changed
+248 -43

No files matched your search

+115 -31
View File
@@ -562,12 +562,11 @@ export function createAircraftModels({
state._lastFleetTickMs = 0;
}
/** Admit a fleet model for an aircraft; the icon shows until it is ready. */
/** Admit a fleet model for an aircraft; the icon shows until it is ready.
* The selected aircraft's is admitted too, and kept loaded but hidden
* while its tracked model draws it (`_keepTrackedFleetModel`). */
function _ensureModel(icao24) {
// Never model the TRACKED aircraft — it owns a separate entity billboard, and the fleet
// tick skips it, so a model here would be orphaned + double-rendered.
if (icao24 === state._trackedIcao) return;
onModelEligible(icao24);
if (state._models.has(icao24)) return;
// Without model sets (the renderer draws none) the icon stays.
@@ -672,14 +671,106 @@ export function createAircraftModels({
);
}
/** A fleet model still drawing the tracked contact (it was a model when
* it was selected) lets go once the tracked model draws, or once the
* contact is no longer drawn as a model at all. */
/** The tracked contact's fleet model lets go once the contact is no
* longer drawn as a model at all (out of range, 3D off, cockpit). */
function _releaseTrackedFleetModel() {
if (state._trackedIcao && state._models.has(state._trackedIcao))
_releaseModel(state._trackedIcao);
}
/** The tracked contact's fleet model (it was a model when it was
* selected, or was admitted since) stops drawing once the tracked model
* draws, or while the tracked icon carries the contact, but stays loaded:
* deselecting hands the contact straight back to it
* (`_handBackDeselected`), with no load and no icon in between. */
function _hideTrackedFleetModel() {
const icao24 = state._trackedIcao;
const record = icao24 ? state._models.get(icao24) : null;
if (!record?.show) return;
showModel(record, false);
_send(state._modelSets?.fleet, icao24, record, _modelSpec(_metaOf(icao24)));
}
/** Keep the tracked contact's fleet model loaded and placed where its icon
* is, one fleet tick at a time, so it is ready to take the contact back
* the moment it is deselected. It never shows here: it draws the contact
* only while the tracked model loads, as it did before the selection. */
function _keepTrackedFleetModel(icao24, position, course, out) {
_ensureModel(icao24);
const record = state._models.get(icao24);
if (!record) return;
const meta = _metaOf(icao24);
const set = state._modelSets?.fleet ?? null;
_retryFailedFleetModel(set, icao24, record);
const displayPos = _modelDisplayPosition(icao24, position);
if (displayPos) placeModel(record, displayPos, _modelHeading(course, meta));
else showModel(record, false); // nowhere safe to draw it
_send(set, icao24, record, _modelSpec(meta), out);
}
/**
* Hand a contact just deselected back to the fleet in the same frame: to
* its fleet model when one is loaded (kept while it was selected), placed
* where its icon is and shown, else to its icon. Runs once the contact no
* longer reads as tracked.
* @param {string} icao24
*/
function _handBackDeselected(icao24) {
const icons = state._icons;
const record = state._models.get(icao24);
if (!icons?.has(icao24)) {
if (record) _releaseModel(icao24);
return;
}
if (!record) {
icons.setShown(icao24, true);
return;
}
const pose = _pose();
if (!pose || !_modelRegimeActive(pose) || isTr3b(icao24)) {
_releaseModel(icao24); // the icon takes it back
return;
}
const t = parts.icons._displayMs();
const position = icons.position(icao24, t);
_driveFleetModelHandoff(
icao24,
record,
position,
icons.course(icao24, t),
() =>
_treatFleetModel(
icao24,
record,
distance(pose.position, position),
pose,
),
);
}
/** A fleet model's tint and alpha this tick: the contact's colour, faded
* as its icon is (focus, recession), or the IR boost's full-strength
* white. */
function _treatFleetModel(icao24, record, cameraDistanceM, pose) {
const icons = state._icons;
_treat(record, {
// IR boost must survive the per-tick treatment write — otherwise
// any alpha change would repaint the ordinary tint over the hot
// white. Boosted models also skip the recession fade: hot targets
// stay full-strength at any range (icons keep their normal
// fade — full-opacity glyph walls read as overwhelming).
base: state._irBoost ? WHITE : rgba(_modelColor(icao24)),
alpha: state._irBoost
? 1
: aircraftTreatmentAlpha({
baseAlpha: icons.alpha(icao24),
focusFactor: icons.focus(icao24),
cameraDistanceM,
cameraHeightM: pose.height,
}),
});
}
/** Per-frame driver for the standalone tracked model. Runs every preUpdate (not the 80 ms fleet
* cadence) so the centered plane moves smoothly. The tracked entity stays a pure billboard, so the
* follow-camera's bounding sphere is ALWAYS ready — toggling 3D, or tracking while already zoomed
@@ -713,7 +804,7 @@ export function createAircraftModels({
parts.icons._iconPosition(state._trackedIcao);
if (!pos) {
_hideTrackedModel();
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
const icao24 = state._trackedIcao;
@@ -725,7 +816,7 @@ export function createAircraftModels({
// The icon carries it: after the load budget is spent, or until the
// fleet model set has loaded.
if (!_trackedModelLoadAllowed() || !spec.url) {
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
const record = createModelRecord({
@@ -753,7 +844,7 @@ export function createAircraftModels({
const displayPos = _modelDisplayPosition(icao24, pos);
if (!displayPos) {
_hideTrackedModel(); // no ground evidence → the icon carries it
_releaseTrackedFleetModel();
_hideTrackedFleetModel();
return;
}
placeModel(
@@ -763,7 +854,7 @@ export function createAircraftModels({
);
showModel(record, record.ready);
_send(state._modelSets.tracked, icao24, record, spec);
if (record.ready) _releaseTrackedFleetModel();
if (record.ready) _hideTrackedFleetModel();
}
/**
@@ -915,8 +1006,6 @@ export function createAircraftModels({
const items = pendingItems;
for (const icao24 of modelEligible) {
if (isTr3b(icao24)) continue;
// The tracked contact's model is `_updateTrackedModel`'s.
if (icao24 === state._trackedIcao) continue;
if (!icons.has(icao24)) continue;
const position = icons.position(icao24, t);
if (
@@ -939,6 +1028,17 @@ export function createAircraftModels({
}
continue;
}
// The tracked contact draws as `_updateTrackedModel` says; its fleet
// model is only kept ready for when it is deselected.
if (icao24 === state._trackedIcao) {
_keepTrackedFleetModel(
icao24,
position,
icons.course(icao24, t),
items,
);
continue;
}
_ensureModel(icao24);
const record = state._models.get(icao24);
const cameraDistanceM = distance(camPos, position);
@@ -947,24 +1047,7 @@ export function createAircraftModels({
record,
position,
icons.course(icao24, t),
() => {
_treat(record, {
// IR boost must survive the per-tick treatment write — otherwise
// any alpha change would repaint the ordinary tint over the hot
// white. Boosted models also skip the recession fade: hot targets
// stay full-strength at any range (icons keep their normal
// fade — full-opacity glyph walls read as overwhelming).
base: state._irBoost ? WHITE : rgba(_modelColor(icao24)),
alpha: state._irBoost
? 1
: aircraftTreatmentAlpha({
baseAlpha: icons.alpha(icao24),
focusFactor: icons.focus(icao24),
cameraDistanceM,
cameraHeightM: pose.height,
}),
});
},
() => _treatFleetModel(icao24, record, cameraDistanceM, pose),
items,
);
}
@@ -992,6 +1075,7 @@ export function createAircraftModels({
_releaseModels,
_showReleasedIcon,
_releaseTrackedModel,
_handBackDeselected,
_updateTrackedModel,
_fleetTick,
};