The renderer seam: clicks go to the newest tool, recession and display groups through the contract, drawing at parity with Cesium

- Clicks: when two tools want the globe's clicks, the newest takes them and the older is told and turns itself off; a click is decided when it arrives, and ambient selection fires only when no tool holds the pointer. The "map is busy" paths and their strings are removed.
- Recession: the limb fade is shared (src/render/recession.js) and reaches icon and model sets through SetSpec.recede; tuning applies on the next frame.
- Display panel groups are published through src/ui/displayGroups.js; the Weather group and src/viewWeather.js are removed.
- Draw port: a set whose icons only move is moved in place, and models that did not change are not restyled each frame, so moving fleets cost what they did when drawn directly; an untinted, fully opaque model is drawn without a colour.
- Conformance: input.lease.lost checks the new lease inside onLost and reports a throwing onLost; draw.sets.recede covers model sets.
- QA scripts read the renderer host instead of internals the seam replaced.
This commit is contained in:
Sameh Khamis committed 2026-11-15 17:03:09 -08:00
1 parent a0d299523d
commit 0ab31d4fb8
130 files changed
+5438 -1674

No files matched your search

+47 -33
View File
@@ -14,17 +14,21 @@
* and every subscriber reads the same {@link ClickEvent}; what a layer does
* with a click that is not its own stays the layer's decision.
*
* Who gets the pointer:
* Who gets the pointer: while a tool holds it (src/data/inputOwnership.js)
* the port holds a lease for it (`bridgePointer`), so the port is not free,
* but that lease takes no press: each event is decided here when it arrives.
* - Ambient subscribers ({@link InputDispatcher.onClick}, and `onPointer`
* without a lease) run only while no tool holds the pointer
* (src/data/inputOwnership.js). The check is made once per event, before
* any subscriber runs, so a tool that releases its lease while handling a
* click does not let that same click through to ambient selection. Ambient
* `move` and `up` are the exceptions: hover sees every move, so it can drop
* its cursor or card when a tool takes the pointer, and a release always
* reaches whoever began the press, so a drag started while the pointer was
* free still ends (and gives its camera hold back).
* without a lease) run only while no tool holds the pointer. The check is
* made once per event, before any subscriber runs, so a tool that releases
* its lease while handling a click does not let that same click through
* to ambient selection. Ambient `move` and `up` are the exceptions: hover
* sees every move, so it can drop its cursor or card when a tool takes the
* pointer, and a release always reaches whoever began the press, so a drag
* started while the pointer was free still ends (and gives its camera hold
* back).
* - Tool subscribers pass their lease and run only while it is current.
* - A claim made on the port by anyone else takes the presses it grabs; the
* rest reach the subscribers here as above.
*
* Camera input is suspended through the input port's counted holds
* (`suspendCameraControls`), so a camera flight that ends cannot re-enable
@@ -39,7 +43,11 @@
* lives until {@link InputDispatcher.destroy}; the application scene owns
* it.
*/
import { isLeaseCurrent, isPointerFree } from '../data/inputOwnership.js';
import {
bridgePointer,
isLeaseCurrent,
pointerOwner,
} from '../data/inputOwnership.js';
import {
findPickOwner,
pickContact,
@@ -267,6 +275,10 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
const cameraHolds = new Set();
let destroyed = false;
// The port holds a lease while a tool here holds the pointer.
const bridge = bridgePointer(port);
/** Tool subscribers whose lease is current, and ambient ones if `free`. */
const run = (list, free, arg) => {
for (const entry of [...list]) {
if (entry.lease ? !isLeaseCurrent(leaseOf(entry)) : !free) continue;
@@ -278,16 +290,18 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
}
};
// Each type is one port listener; the pointer's owner is read once per
// event, before any subscriber runs.
const offPort = [
port.on('down', (ev) => {
// Whether ambient subscribers hear a press, read once as it arrives. A
// claim on the port that is not this bridge's has already taken the
// presses it grabs; what reaches here is free unless a tool here holds it.
const free = () => pointerOwner() === null;
// Each type is one port listener.
const deliver = {
down: (ev) => {
if (!unmodifiedLeft(ev)) return;
run(pointerSubscribers.down, isPointerFree(), {
position: xy(ev.position),
});
}),
port.on('move', (ev) => {
run(pointerSubscribers.down, free(), { position: xy(ev.position) });
},
move: (ev) => {
if (!unmodified(ev)) return;
const endPosition = xy(ev.endPosition ?? ev.position);
let pickPosition;
@@ -305,30 +319,29 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
return pickPosition;
},
});
}),
port.on('up', (ev) => {
},
up: (ev) => {
if (!unmodifiedLeft(ev)) return;
run(pointerSubscribers.up, true, { position: xy(ev.position) });
}),
port.on('click', (ev) => {
},
click: (ev) => {
if (!unmodifiedLeft(ev)) return;
const free = isPointerFree();
const ambient = free();
const event = createClickEvent(
viewer,
queryOf,
xy(ev.position),
ev.gesture ?? { travelPx: 0, durationMs: 0 },
);
run(pointerSubscribers.click, free, event);
if (free) run(clickSubscribers, true, event);
}),
port.on('dblclick', (ev) => {
run(pointerSubscribers.click, ambient, event);
if (ambient) run(clickSubscribers, true, event);
},
dblclick: (ev) => {
if (!unmodifiedLeft(ev)) return;
run(pointerSubscribers.dblclick, isPointerFree(), {
position: xy(ev.position),
});
}),
];
run(pointerSubscribers.dblclick, free(), { position: xy(ev.position) });
},
};
const offPort = POINTER_TYPES.map((type) => port.on(type, deliver[type]));
const subscribe = (list, entry) => {
if (destroyed) return () => {};
@@ -393,6 +406,7 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
clickSubscribers.length = 0;
for (const type of POINTER_TYPES) pointerSubscribers[type].length = 0;
for (const off of offPort) off();
bridge.off();
for (const hold of [...stockHolds]) hold();
for (const hold of [...cameraHolds]) hold();
// A port built for this viewer goes with its dispatcher; a
+93 -1
View File
@@ -2,7 +2,7 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { inputFor, pickAt } from './dispatcher.js';
import { bindRenderer } from '../render/rendererOf.js';
import { bindRenderer, findInput } from '../render/rendererOf.js';
import {
FAKE_EVENT_TYPES,
FakeScreenSpaceEventHandler as FakeHandler,
@@ -193,6 +193,98 @@ test('a stale lease gets nothing once its successor holds the pointer', (t) => {
assert.equal(staleRan, 0);
});
test("a tool's claim holds the renderer's input port without taking its presses", (t) => {
const h = harness();
t.after(() => h.input.destroy());
const port = findInput(h.viewer);
const heard = [];
port.on('click', () => heard.push('port'));
const lease = claimPointer('test-tool');
t.after(() => releasePointer(lease));
h.input.onPointer('click', () => heard.push('tool'), { lease });
assert.equal(port.isPointerFree(), false);
h.click();
// Who hears a click is decided here, when it arrives; the port gives
// every press on, so the renderer's own select runs unless held off.
assert.deepEqual(heard, ['tool', 'port']);
releasePointer(lease);
assert.equal(port.isPointerFree(), true);
h.click();
assert.deepEqual(heard, ['tool', 'port', 'port']);
});
test('a click goes where the pointer is when it arrives: a tool that claims during the press gets it, ambient selection does not', (t) => {
const h = harness();
t.after(() => h.input.destroy());
const heard = [];
h.input.onClick(() => heard.push('ambient'));
let lease = null;
h.input.onPointer('click', () => heard.push('tool'), {
lease: () => lease,
});
h.input.onPointer('dblclick', () => heard.push('tool:dblclick'), {
lease: () => lease,
});
h.input.onPointer('dblclick', () => heard.push('ambient:dblclick'));
h.handler.fire(TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
lease = claimPointer('test-tool');
t.after(() => releasePointer(lease));
h.handler.fire(TYPES.LEFT_UP, { position: { x: 10, y: 10 } });
h.handler.fire(TYPES.LEFT_CLICK, { position: { x: 10, y: 10 } });
h.handler.fire(TYPES.LEFT_DOUBLE_CLICK, { position: { x: 10, y: 10 } });
assert.deepEqual(heard, ['tool', 'tool:dblclick']);
});
test('a click goes where the pointer is when it arrives: after a tool lets go during the press, ambient selection gets it', (t) => {
const h = harness();
t.after(() => h.input.destroy());
const heard = [];
h.input.onClick(() => heard.push('ambient'));
const lease = claimPointer('test-tool');
t.after(() => releasePointer(lease));
h.input.onPointer('click', () => heard.push('tool'), { lease });
h.input.onPointer('dblclick', () => heard.push('ambient:dblclick'));
h.handler.fire(TYPES.LEFT_DOWN, { position: { x: 10, y: 10 } });
releasePointer(lease);
h.handler.fire(TYPES.LEFT_UP, { position: { x: 10, y: 10 } });
h.handler.fire(TYPES.LEFT_CLICK, { position: { x: 10, y: 10 } });
h.handler.fire(TYPES.LEFT_DOUBLE_CLICK, { position: { x: 10, y: 10 } });
assert.deepEqual(heard, ['ambient', 'ambient:dblclick']);
});
test("a claim on the renderer's port takes over from the tool, which is told", (t) => {
const h = harness();
t.after(() => h.input.destroy());
const port = findInput(h.viewer);
const told = [];
const heard = [];
const lease = claimPointer('test-tool', { onLost: () => told.push('tool') });
h.input.onPointer('click', () => heard.push('tool'), { lease });
h.input.onClick(() => heard.push('ambient'));
const other = port.claimPointer('other');
t.after(() => other.release());
port.on('click', () => heard.push('other'), { lease: other });
assert.deepEqual(told, ['tool']);
h.click();
assert.deepEqual(
heard,
['other'],
'neither the old tool nor ambient selection',
);
releasePointer(lease);
assert.equal(other.current, true, "the old tool's release frees nothing");
});
test('destroy gives the port its lease back', () => {
const h = harness();
const port = findInput(h.viewer);
const lease = claimPointer('test-tool');
assert.equal(port.isPointerFree(), false);
h.input.destroy();
assert.equal(port.isPointerFree(), true);
releasePointer(lease);
});
test('camera input returns only when the last hold releases', (t) => {
const h = harness();
t.after(() => h.input.destroy());