Take pointer input through one dispatcher per scene

Every layer and tool bound its own ScreenSpaceEventHandler and picked the
same click again: with the usual layers on, one click ran about 26
scene.pick and 2 drillPick passes (120-215 ms in NYC with 18 layers). Pointer
input now comes in through src/input/dispatcher.js, one handler per scene.
A click is picked lazily and at most once per kind of query, and every
subscriber reads the same ClickEvent (pick, hit, id, ownerId, gesture,
drill, ground). The same click now costs 3 picks and 2 drills, 17-70 ms.

- Ambient onClick subscribers run only while no tool holds the pointer,
  checked once per event; tools subscribe with their lease. Moves and
  releases always reach ambient subscribers, so hover and drags end cleanly.
- Camera input and the viewer's stock select/track clicks are ref-counted
  holds (suspendCamera, suppressStockClicks). The dispatcher owns the
  controller's enableInputs, so a Cesium flight that ends no longer turns
  input back on under a drag or the cockpit.
- The draw tool, imagery box, CCTV gizmo, cockpit, directions and every
  selecting layer use it; bindTrackingClickGesture is gone (the gesture is
  on the event). A source scan forbids new handlers, enableInputs writes and
  stock-click removal outside the dispatcher.
- The sensor-style pick correction transit had now applies to every layer.
- Radio's 8-pick near-miss ring is one 17x17 windowed drill.
- A missed pick passed to pickContact is no longer picked again, and a
  touch tap's contact search shares the click's drill.
- A gizmo drag whose release Cesium never reported ends on the next press
  instead of leaving the camera held.

The dispatcher is exported as ./input with the pointer-lease functions, and
documented in docs/APPLICATION.md.
This commit is contained in:
Sameh Khamis committed 2026-11-04 08:48:51 -08:00
1 parent 83ec9473b6
commit 02d492a079
97 files changed
+2506 -1307

No files matched your search

+14 -27
View File
@@ -2,26 +2,18 @@ import { readLayerSource } from '../testSupport/readLayerSource.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import {
bindTrackingClickGesture,
isTrackingClickGesture,
isTrackingSelectionGesture,
} from './trackingClickGesture.js';
import { FAKE_EVENT_TYPES as TYPES, fakeInput } from '../input/testDoubles.mjs';
import { TRACKED_MODEL_MAX_PX as CIVIL_TRACKED_MODEL_MAX_PX } from './flights.js';
import { TRACKED_MODEL_MAX_PX as MILITARY_TRACKED_MODEL_MAX_PX } from './militaryFlights.js';
const TYPES = {
LEFT_DOWN: 'left-down',
MOUSE_MOVE: 'mouse-move',
LEFT_UP: 'left-up',
LEFT_CLICK: 'left-click',
};
function makeHandler() {
const actions = new Map();
return {
setInputAction(callback, type) { actions.set(type, callback); },
fire(type, event) { actions.get(type)?.(event); },
};
/** A dispatcher on a fake handler, with `onClick(click, gesture)` as the layers read it. */
function gestureInput(now, onClick) {
const { input, handler } = fakeInput({ scene: {} }, { now });
input.onClick((event) => onClick(event.screenPosition, event.gesture));
return { input, handler };
}
test('tracking click discrimination pins the travel/duration boundary matrix', () => {
@@ -43,12 +35,8 @@ test('tracking click discrimination pins the travel/duration boundary matrix', (
test('synthetic drag-then-click sequence does not reach the untrack callback', () => {
let timeMs = 0;
let untrackCalls = 0;
const handler = makeHandler();
bindTrackingClickGesture(handler, (_click, gesture) => {
const { input, handler } = gestureInput(() => timeMs, (_click, gesture) => {
if (isTrackingClickGesture(gesture)) untrackCalls += 1;
}, {
now: () => timeMs,
eventTypes: TYPES,
});
handler.fire(TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
@@ -64,29 +52,27 @@ test('synthetic drag-then-click sequence does not reach the untrack callback', (
handler.fire(TYPES.LEFT_CLICK, { position: { x: 10, y: 10 } });
assert.equal(untrackCalls, 1, 'suppression is consumed and cannot poison the next click');
input.destroy();
});
test('slow clean sprite clicks select, while long presses and orbit nudges cannot untrack', () => {
let timeMs = 0;
let selections = 0;
let untracks = 0;
const handler = makeHandler();
bindTrackingClickGesture(handler, (click, gesture) => {
// A click at x 0 lands on a sprite; anywhere else is empty space.
const { input, handler } = gestureInput(() => timeMs, (click, gesture) => {
if (!isTrackingSelectionGesture(gesture)) return;
if (click.sprite) {
if (click.x === 0 && click.y === 0) {
selections += 1;
return;
}
if (isTrackingClickGesture(gesture)) untracks += 1;
}, {
now: () => timeMs,
eventTypes: TYPES,
});
handler.fire(TYPES.LEFT_DOWN, { position: { x: 0, y: 0 } });
timeMs = 401;
handler.fire(TYPES.LEFT_UP, { position: { x: 0, y: 0 } });
handler.fire(TYPES.LEFT_CLICK, { position: { x: 0, y: 0 }, sprite: true });
handler.fire(TYPES.LEFT_CLICK, { position: { x: 0, y: 0 } });
assert.equal(selections, 1, 'duration alone must not suppress entity selection');
assert.equal(untracks, 0);
@@ -106,6 +92,7 @@ test('slow clean sprite clicks select, while long presses and orbit nudges canno
handler.fire(TYPES.LEFT_UP, { position: { x: 3, y: 4 } });
handler.fire(TYPES.LEFT_CLICK, { position: { x: 3, y: 4 } });
assert.equal(untracks, 1, 'a short clean empty-space tap still untracks');
input.destroy();
});
test('civilian and military click handlers apply duration only at the deselect branch', () => {
@@ -114,7 +101,7 @@ test('civilian and military click handlers apply duration only at the deselect b
readLayerSource(new URL('./militaryFlights.js', import.meta.url)),
];
for (const source of sources) {
assert.match(source, /isTrackingSelectionGesture\(gesture\)[\s\S]+scene\.pick/);
assert.match(source, /isTrackingSelectionGesture\(gesture\)[\s\S]+event\.hit/);
assert.match(source, /isTrackingClickGesture\(gesture\)[\s\S]+(?:parts\.\w+\.)?_clearTracking\([^)]*\{ origin: 'user' \}\)/);
}
assert.doesNotMatch(