mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(localAdsb): Cesium rendering behind a renderer interface
Task 12a. The Local ADS-B logic (index.js, models.js) no longer imports
Cesium. src/layers/localAdsb/render/cesium.js holds what it built, one
for one: the CustomDataSource of marker entities (billboard with
per-frame position/rotation/visibility CallbackProperties, the 2,000 km
DistanceDisplayCondition, the 978 MHz UAT ring as a PointGraphics), the
model PrimitiveCollection (models load, pose and leave through the shared
aircraft renderer's model part, adopting that collection), the selected
aircraft's trail (data/trailRenderer, as before) and live head segment,
and the camera reads. Registered for 'local-adsb' in the renderer
registry, created at init(viewer, {engine}).
- Clicks go through the engine's selection dispatcher (drill 8) instead of
the layer's ScreenSpaceEventHandler, with the layer's own rule kept as is
— a new `lookUnder` owner kind: its marker on top, or under picks no
layer owns and under trail lines, is selected (and re-selected);
another layer's contact on top, or empty map, releases only its own
selection; a trail line alone does nothing; no gesture rule. To the
other owners it is another layer, as its pick-owner registration made
it before. (The dispatcher's `drillThrough` would have taken the marker
from under another layer's contact, which the old handler never did.)
- models.js reads the camera through the renderer's view (frustum and
horizon tests, ground snap owner) and draws through renderer.models
(loadFleet/add/remove/destroy/setPose: the same MIX-tinted glTF options,
the same HPR frame with the Flights nose offset). The shared aircraft
renderer gains a loadModel seam (default Cesium.Model.fromGltfAsync).
- Cesium math → src/geo; the model tint is an Rgba equal to the old
Cesium.Color; check-import-directions: src/layers/localAdsb/ joins the
rendered layers.
Tests moved with the code, same meaning:
- index.test: the services fixture creates the layer's Cesium renderer and
the selection dispatcher; the click harness scripts the picks on a fake
engine registered for the fake viewer (was a fake ScreenSpaceEventHandler)
and the app's pick owners (trails, a Flights contact) are registered in
the pick registry (was an injected picking service).
- cockpitModels.test: the GLB loads are the aircraft renderer's loadModel
calls (Cesium.Model.fromGltfAsync by default), each asynchronous:false.
- trackingClickGesture.test: the dispatcher's empty click goes to the
plain owners (filter(plain)).
- renderers.test: local-adsb has an extracted Cesium renderer.
New: the dispatcher's look-under rule beside a plain owner (7 click cases).
W1 replay (flights, military, localAdsb) vs a fresh 7c7422e2 run: counts,
known objects, screen points, tracking poses, requests and every shot's
sha256 identical.
This commit is contained in:
1 parent
941b308c29
commit
0b8cb855fa
15 files changed
+549
-306
No files matched your search
@@ -29,7 +29,10 @@ for (const layer of LAYERS) {
|
||||
const source = readLayerSource(layer.path);
|
||||
|
||||
test(`${layer.name}: every GLB creation bypasses the tile-contended frame-spread queue`, () => {
|
||||
const calls = [...source.matchAll(/Cesium\.Model\.fromGltfAsync\(\{([\s\S]*?)\}\)/g)];
|
||||
// The aircraft renderer loads through its `loadModel`, Cesium.Model.fromGltfAsync
|
||||
// unless a test injects a loader (phase 3).
|
||||
assert.match(source, /loadModel = \(options\) => Cesium\.Model\.fromGltfAsync\(options\)/);
|
||||
const calls = [...source.matchAll(/(?:Cesium\.Model\.fromGltfAsync|\bloadModel)\(\{([\s\S]*?)\}\)/g)];
|
||||
assert.ok(calls.length >= 3, `expected fleet, tracked, and preload model calls; found ${calls.length}`);
|
||||
for (const [index, call] of calls.entries()) {
|
||||
assert.match(call[1], /\basynchronous:\s*false\b/,
|
||||
|
||||
@@ -10,10 +10,16 @@
|
||||
// onEscape() Escape.
|
||||
// The rules are the old handlers': a pick another layer owns is not empty
|
||||
// space (a pick nobody owns is); `passThrough` picks (trails) never take the
|
||||
// click, the next pick does; a `drillThrough` owner (local ADS-B) takes its object from under
|
||||
// another layer's; a drag selects nothing; a pointer owned by a tool
|
||||
// click, the next pick does; a `drillThrough` owner takes its object from
|
||||
// under another layer's; a drag selects nothing; a pointer owned by a tool
|
||||
// (inputOwnership) selects nothing. Layers not moved yet keep their own
|
||||
// handlers: the dispatcher never acts on an id it does not own.
|
||||
// A `lookUnder` owner (local ADS-B) keeps its own old click rule instead:
|
||||
// its object on top, or under picks no layer owns and picks it looks under
|
||||
// (`lookUnder(id)`: trails), is selected; another layer's object on top, or
|
||||
// nothing, is empty space for it (it releases its selection); a click that
|
||||
// only meets what it looks under does nothing; no gesture rule (its old
|
||||
// handler took every click). To the others it is another layer.
|
||||
|
||||
import { isPointerFree as pointerFree } from './inputOwnership.js';
|
||||
import {
|
||||
@@ -75,6 +81,31 @@ export function createSelectionDispatcher(
|
||||
return { id, owner: findPickOwner(id) };
|
||||
};
|
||||
|
||||
// The look-under rule (local ADS-B's old click handler, kept as is).
|
||||
const lookUnderTarget = (name, owner, event) => {
|
||||
const ownedElsewhere = (id) => {
|
||||
if (id === null) return false;
|
||||
for (const [other, entry] of owners)
|
||||
if (other !== name && safely(() => entry.owns(id))) return true;
|
||||
const found = findPickOwner(id);
|
||||
return found !== null && found !== undefined && found !== name;
|
||||
};
|
||||
const mine = (id) => id !== null && safely(() => owner.owns(id));
|
||||
const under = (id) => id !== null && safely(() => owner.lookUnder(id));
|
||||
const top = resolvePickId(event.picked);
|
||||
if (mine(top)) return { id: top, picked: event.picked };
|
||||
const lookedUnder = under(top);
|
||||
if (ownedElsewhere(top) && !lookedUnder) return 'other';
|
||||
for (const hit of event.drilled ?? []) {
|
||||
const id = resolvePickId(hit);
|
||||
if (mine(id)) return { id, picked: hit };
|
||||
if (under(id)) continue;
|
||||
if (ownedElsewhere(id)) return 'other';
|
||||
}
|
||||
return lookedUnder ? 'under' : null;
|
||||
};
|
||||
const plain = (owner) => typeof owner.lookUnder !== 'function';
|
||||
|
||||
const onClick = (event) => {
|
||||
if (press) finish(event.position);
|
||||
const gesture = completed ?? { travelPx: 0, durationMs: 0 };
|
||||
@@ -86,6 +117,14 @@ export function createSelectionDispatcher(
|
||||
drilled: event.drilled ?? [],
|
||||
gesture,
|
||||
};
|
||||
for (const [name, owner] of [...owners]) {
|
||||
if (plain(owner)) continue;
|
||||
const target = lookUnderTarget(name, owner, event);
|
||||
if (target === 'under') continue;
|
||||
if (target && target !== 'other')
|
||||
owner.onSelect?.(target.id, { ...ctx, picked: target.picked });
|
||||
else owner.onEmptyClick?.(ctx);
|
||||
}
|
||||
const candidates = [event.picked, ...(event.drilled ?? [])].filter(
|
||||
(picked) =>
|
||||
picked &&
|
||||
@@ -104,15 +143,16 @@ export function createSelectionDispatcher(
|
||||
});
|
||||
if (!picks.length) {
|
||||
if (!isTrackingClickGesture(gesture)) return;
|
||||
for (const owner of [...owners.values()]) owner.onEmptyClick?.(ctx);
|
||||
for (const owner of [...owners.values()].filter(plain))
|
||||
owner.onEmptyClick?.(ctx);
|
||||
return;
|
||||
}
|
||||
if (!isTrackingSelectionGesture(gesture)) return;
|
||||
const first = ownerOf(picks[0]);
|
||||
if (owners.has(first.owner)) {
|
||||
owners
|
||||
.get(first.owner)
|
||||
.onSelect?.(first.id, { ...ctx, picked: picks[0] });
|
||||
const owner = owners.get(first.owner);
|
||||
if (plain(owner))
|
||||
owner.onSelect?.(first.id, { ...ctx, picked: picks[0] });
|
||||
return;
|
||||
}
|
||||
// Another layer's object on top: a drill-through owner may still take
|
||||
@@ -120,7 +160,7 @@ export function createSelectionDispatcher(
|
||||
for (const picked of picks.slice(1)) {
|
||||
const below = ownerOf(picked);
|
||||
const owner = owners.get(below.owner);
|
||||
if (owner?.drillThrough) {
|
||||
if (owner?.drillThrough && plain(owner)) {
|
||||
owner.onSelect?.(below.id, { ...ctx, picked });
|
||||
return;
|
||||
}
|
||||
@@ -128,7 +168,8 @@ export function createSelectionDispatcher(
|
||||
// A pick no layer owns (an unclaimed entity) is empty space, as it was
|
||||
// for the old handlers: only another layer's object is not.
|
||||
if (first.owner === null && isTrackingClickGesture(gesture))
|
||||
for (const owner of [...owners.values()]) owner.onEmptyClick?.(ctx);
|
||||
for (const owner of [...owners.values()].filter(plain))
|
||||
owner.onEmptyClick?.(ctx);
|
||||
};
|
||||
|
||||
const onKey = (event) => {
|
||||
@@ -163,7 +204,8 @@ export function createSelectionDispatcher(
|
||||
/**
|
||||
* @param {string} name the owning layer's id
|
||||
* @param {{ owns: (id: string) => boolean, onSelect?: Function, onEmptyClick?: Function,
|
||||
* onEscape?: Function, passThrough?: (picked: object) => boolean, drillThrough?: boolean }} owner
|
||||
* onEscape?: Function, passThrough?: (picked: object) => boolean, drillThrough?: boolean,
|
||||
* lookUnder?: (id: string) => boolean }} owner
|
||||
* @returns {() => void} unregister
|
||||
*/
|
||||
register(name, owner) {
|
||||
|
||||
@@ -205,3 +205,54 @@ test('the application has one dispatcher per engine', () => {
|
||||
selectionDispatcherFor(engine).destroy();
|
||||
selectionDispatcherFor(other).destroy();
|
||||
});
|
||||
|
||||
test('a look-under owner (local ADS-B) keeps its own click rule beside the others', () => {
|
||||
// x: what lies under each column, top first.
|
||||
const { dispatcher, click } = setup({
|
||||
10: [{ id: 'local-adsb:a' }], // its own marker
|
||||
20: [{ primitive: { tileset: true } }, { id: 'local-adsb:a' }], // under a tile
|
||||
30: [{ id: 'gev-trail:local-adsb-head-1' }, { id: 'local-adsb:b' }], // under a trail
|
||||
40: [{ id: 'gev-trail:x' }], // a trail alone
|
||||
50: [{ id: 'ae01ce' }, { id: 'local-adsb:a' }], // another layer's on top
|
||||
60: [{ id: 'cctv-1' }, { id: 'local-adsb:a' }], // a registry owner's on top
|
||||
70: [], // empty map
|
||||
});
|
||||
registerPickOwner('trails', (id) => id.startsWith('gev-trail:'));
|
||||
registerPickOwner('cctv', (id) => id.startsWith('cctv'));
|
||||
try {
|
||||
const local = recorder();
|
||||
const flights = recorder();
|
||||
dispatcher.register('local-adsb', {
|
||||
owns: (id) => id.startsWith('local-adsb:'),
|
||||
lookUnder: (id) => id.startsWith('gev-trail:'),
|
||||
...local.handlers,
|
||||
});
|
||||
dispatcher.register('flights', {
|
||||
owns: (id) => id === 'ae01ce',
|
||||
...flights.handlers,
|
||||
});
|
||||
for (const x of [10, 20, 30, 40, 50, 60, 70]) click(x);
|
||||
// A long press on empty map still reaches it (its old LEFT_CLICK rule).
|
||||
click(70, { ms: 900 });
|
||||
assert.deepEqual(local.calls, [
|
||||
['select', 'local-adsb:a', undefined],
|
||||
['select', 'local-adsb:a', undefined],
|
||||
['select', 'local-adsb:b', undefined],
|
||||
// 40: a trail alone is not empty map: nothing.
|
||||
['empty', 0], // 50: another layer's contact releases local's selection
|
||||
['empty', 0], // 60: the same for a registry owner's
|
||||
['empty', 0], // 70
|
||||
['empty', 0], // 70, long press
|
||||
]);
|
||||
// Flights, as before: its own contact at 50 and empty map at 70 (the
|
||||
// long press does not deselect); a local marker (even under a tile), a
|
||||
// trail or another owner's object is not its empty space.
|
||||
assert.deepEqual(flights.calls, [
|
||||
['select', 'ae01ce', undefined],
|
||||
['empty', 0],
|
||||
]);
|
||||
} finally {
|
||||
unregisterPickOwner('trails');
|
||||
unregisterPickOwner('cctv');
|
||||
}
|
||||
});
|
||||
@@ -120,7 +120,7 @@ test('civilian and military click handlers apply duration only at the deselect b
|
||||
// each layer answers with a user-origin clear.
|
||||
const dispatcher = readFileSync(new URL('./selectionDispatcher.js', import.meta.url), 'utf8');
|
||||
assert.match(dispatcher, /if \(!isTrackingSelectionGesture\(gesture\)\) return;[\s\S]+onSelect/);
|
||||
assert.match(dispatcher, /if \(!isTrackingClickGesture\(gesture\)\) return;\s*for \(const owner of \[\.\.\.owners\.values\(\)\]\) owner\.onEmptyClick/);
|
||||
assert.match(dispatcher, /if \(!isTrackingClickGesture\(gesture\)\) return;\s*for \(const owner of \[\.\.\.owners\.values\(\)\]\.filter\(plain\)\)\s*owner\.onEmptyClick/);
|
||||
for (const [layer, source] of [['flights', sources[0]], ['military', sources[1]]]) {
|
||||
assert.match(source, new RegExp(`dispatcher\\.register\\('${layer}', \\{[\\s\\S]+onEmptyClick: _onEmptyClick`));
|
||||
assert.match(source, /function _onEmptyClick\(\) \{[\s\S]+?_clearTracking\(false, \{ origin: 'user' \}\)/);
|
||||
|
||||
Reference in new issue
Block a user