mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
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:
1 parent
36624cd329
commit
b041fea7a6
6 files changed
+248
-43
No files matched your search
+115
-31
@@ -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,
|
||||
};
|
||||
|
||||
@@ -449,3 +449,30 @@ test('models are drawn at their true size, with no minimum pixel size', () => {
|
||||
f.tick();
|
||||
assert.equal(f.fleet().items.get('a1').minPixelSize ?? 0, 0);
|
||||
});
|
||||
|
||||
test('the selected contact keeps a loaded, hidden fleet model that takes it back on deselect', () => {
|
||||
const positions = new Map([['a1', near(1)]]);
|
||||
const f = fleetFixture(positions);
|
||||
// Selected while an icon: the fleet pass admits its model all the same.
|
||||
f.state._trackedIcao = 'a1';
|
||||
f.shown.set('a1', false); // selecting it hides its icon
|
||||
f.tick();
|
||||
assert.ok(f.fleet().items.has('a1'), 'admitted and loading while selected');
|
||||
f.draw.ready(f.fleetId, 'a1');
|
||||
positions.set('a1', near(2));
|
||||
f.tick();
|
||||
const item = f.fleet().items.get('a1');
|
||||
assert.equal(item.show, false, 'never drawn while selected');
|
||||
assert.deepEqual(
|
||||
item.pos,
|
||||
{ x: near(2).x, y: near(2).y, z: near(2).z },
|
||||
'placed where its icon is',
|
||||
);
|
||||
assert.equal(f.shown.get('a1'), false, 'the icon stays hidden');
|
||||
|
||||
// Deselected: its model draws it in the same frame, its icon never shows.
|
||||
f.state._trackedIcao = null;
|
||||
f.models._handBackDeselected('a1');
|
||||
assert.equal(f.fleet().items.get('a1').show, true);
|
||||
assert.equal(f.shown.get('a1'), false);
|
||||
});
|
||||
@@ -1176,11 +1176,10 @@ for (const fixture of LAYERS) {
|
||||
|
||||
viewer.draw.ready(modelSet(fixture, viewer, 'tracked').spec.id, ICAO);
|
||||
fixture.driveTrackedModel();
|
||||
assert.equal(
|
||||
fixture.ensureFleetModel(ICAO),
|
||||
null,
|
||||
'once the tracked model draws, the fleet model lets go',
|
||||
);
|
||||
const kept = fixture.ensureFleetModel(ICAO);
|
||||
assert.ok(kept, 'once the tracked model draws, the fleet model is kept');
|
||||
assert.equal(kept.ready, true, 'loaded');
|
||||
assert.equal(kept.show, false, 'but hidden: one model draws the contact');
|
||||
assert.equal(
|
||||
fixture.trackedBillboardColor()[3],
|
||||
0,
|
||||
@@ -1192,6 +1191,99 @@ for (const fixture of LAYERS) {
|
||||
}
|
||||
});
|
||||
|
||||
test(`${fixture.name}: deselecting hands the contact straight back to its loaded fleet model, with no icon flash`, () => {
|
||||
clearTr3bRegistry();
|
||||
try {
|
||||
fixture.layer.setParams({ models3d: true });
|
||||
const viewer = viewerAtHeight(30_000);
|
||||
const position = Cesium.Cartesian3.fromDegrees(-97.71, 30.21, 10_668);
|
||||
const icon = fixture.seed({
|
||||
viewer,
|
||||
models: [
|
||||
[
|
||||
ICAO,
|
||||
{
|
||||
ready: true,
|
||||
show: true,
|
||||
modelMatrix: Cesium.Matrix4.fromTranslation(position),
|
||||
},
|
||||
],
|
||||
],
|
||||
trackedModelEligible: null,
|
||||
});
|
||||
fixture.driveTrackedModel();
|
||||
viewer.draw.ready(modelSet(fixture, viewer, 'tracked').spec.id, ICAO);
|
||||
fixture.driveTrackedModel();
|
||||
assert.equal(
|
||||
fixture.trackedModel().ready,
|
||||
true,
|
||||
'the tracked model draws',
|
||||
);
|
||||
icon.show = false; // as selecting it hides it
|
||||
|
||||
fixture.layer.stopTracking();
|
||||
const fleetItem = modelSet(fixture, viewer, 'fleet').items.get(ICAO);
|
||||
assert.equal(
|
||||
fleetItem?.show,
|
||||
true,
|
||||
'the kept fleet model draws the contact in the same frame',
|
||||
);
|
||||
assert.equal(icon.show, false, 'and its icon never shows');
|
||||
assert.equal(
|
||||
modelSet(fixture, viewer, 'tracked').items.has(ICAO),
|
||||
false,
|
||||
'the tracked model is gone',
|
||||
);
|
||||
} finally {
|
||||
fixture.layer.setParams({ models3d: false });
|
||||
fixture.layer.stopTracking();
|
||||
}
|
||||
});
|
||||
|
||||
test(`${fixture.name}: deselecting shows the icon only when no fleet model is loaded`, () => {
|
||||
clearTr3bRegistry();
|
||||
try {
|
||||
fixture.layer.setParams({ models3d: true });
|
||||
const viewer = viewerAtHeight(30_000);
|
||||
// Selected as an icon: no fleet model at all.
|
||||
let icon = fixture.seed({
|
||||
viewer,
|
||||
models: [],
|
||||
trackedModelEligible: null,
|
||||
});
|
||||
fixture.layer.stopTracking();
|
||||
assert.equal(icon.show, true, 'no fleet model: the icon');
|
||||
|
||||
// A fleet model still loading when it is deselected.
|
||||
icon = fixture.seed({
|
||||
viewer,
|
||||
models: [[ICAO, { ready: false, show: false }]],
|
||||
trackedModelEligible: null,
|
||||
});
|
||||
fixture.layer.stopTracking();
|
||||
assert.equal(icon.show, true, 'a fleet model not loaded yet: the icon');
|
||||
assert.notEqual(
|
||||
modelSet(fixture, viewer, 'fleet').items.get(ICAO)?.show,
|
||||
true,
|
||||
'and the model stays hidden until it loads',
|
||||
);
|
||||
|
||||
// 3D turned off meanwhile: the icon, and the fleet model goes.
|
||||
icon = fixture.seed({
|
||||
viewer,
|
||||
models: [[ICAO, { ready: true, show: false }]],
|
||||
trackedModelEligible: null,
|
||||
});
|
||||
fixture.layer.setParams({ models3d: false });
|
||||
fixture.layer.stopTracking();
|
||||
assert.equal(icon.show, true, '3D off: the icon');
|
||||
assert.equal(fixture.ensureFleetModel(ICAO), null, 'no fleet model kept');
|
||||
} finally {
|
||||
fixture.layer.setParams({ models3d: false });
|
||||
fixture.layer.stopTracking();
|
||||
}
|
||||
});
|
||||
|
||||
test(`${fixture.name}: the tracked model draws at the fleet's scale and minimum pixel size, even up close`, () => {
|
||||
clearTr3bRegistry();
|
||||
try {
|
||||
|
||||
@@ -703,10 +703,11 @@ export function createTracking({
|
||||
// Hand the contact back to its icon only now: settling floors a grounded
|
||||
// contact, and while it still read as tracked its tracked model owned the
|
||||
// visual, so the floor would have stepped aside.
|
||||
if (flightState._icons?.has(clearedIcao)) {
|
||||
flightState._icons.setShown(clearedIcao, true);
|
||||
// Its fleet model, kept loaded while it was selected, takes it back in
|
||||
// this frame; the icon shows only when there is no loaded one.
|
||||
parts.rendering._handBackDeselected(clearedIcao);
|
||||
if (flightState._icons?.has(clearedIcao))
|
||||
parts.icons._settleIcon(clearedIcao, { fromCourseDeg: trackedCourseDeg });
|
||||
}
|
||||
parts.icons._applyIconPresentation(clearedIcao);
|
||||
clearTrackedSubjectContext('flights');
|
||||
_emitAwarenessEvent('gev:awareness-subject-cleared', {
|
||||
|
||||
@@ -932,10 +932,11 @@ export function createTracking({
|
||||
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).
|
||||
if (flightState._icons?.has(clearedIcao)) {
|
||||
flightState._icons.setShown(clearedIcao, true);
|
||||
// Its fleet model, kept loaded while it was selected, takes it back in
|
||||
// this frame; the icon shows only when there is no loaded one.
|
||||
parts.rendering._handBackDeselected(clearedIcao);
|
||||
if (flightState._icons?.has(clearedIcao))
|
||||
parts.icons._settleIcon(clearedIcao, { fromCourseDeg: trackedCourseDeg });
|
||||
}
|
||||
parts.icons._applyIconPresentation(clearedIcao);
|
||||
clearTrackedSubjectContext('military');
|
||||
_emitAwarenessEvent('gev:awareness-subject-cleared', {
|
||||
|
||||
Reference in new issue
Block a user