Give the Cesium renderer the contract's input port

src/render/cesium/input.js feeds the shared router from one
ScreenSpaceEventHandler: every button's press, release and click, double
clicks, moves and pinches, under any one modifier. The DOM event being
dispatched gives the full modifiers and pointer type; an action Cesium
raises on a timer takes its own modifier. Wheel comes from the canvas in
lines and is never cancelled. Clicks are picked once, lazily, through the
query port. Cesium ends every held button on any release; those presses
end there, but only the button released clicks.

The viewer's stock select and follow move off its handler and run first,
as they did, but only for a press no lease took and while not suppressed.
Camera holds go through the scene's shared holds, ctrlWheelZoom through
ctrlWheelZoom.js. The router gains a before-hook and dispose, which stops
delivery mid-event.

The conformance renderer exposes the port and the harness feeds it;
input.lease, input.lease.grab, input.lease.press, input.clickPick and
input.behaviours join the Cesium checks.
This commit is contained in:
Sameh Khamis committed 2026-11-05 18:50:18 -08:00
1 parent 6921e075d0
commit 1c29a54dc9
8 files changed
+870 -12

No files matched your search

+20 -3
View File
@@ -214,12 +214,20 @@ export function createInputRouter({
/**
* Delivers one event to the listeners it belongs to.
* @param {import('../contract/input').PointerEv} ev
* @returns {{lease: object|null, ambient: boolean}} Who it went to, so a
* renderer can leave a grabbed press out of its stock behaviours. A
* @param {(to: {lease: object|null, ambient: boolean}) => void} [before]
* Runs first with who the event goes to: a renderer's stock behaviours,
* which run ahead of the subscribers. Its error is reported.
* @returns {{lease: object|null, ambient: boolean}} Who it went to. A
* `move` or `up` always reads as going to both, grabbed press or not.
*/
function dispatch(ev) {
function dispatch(ev, before) {
const to = recipients(ev);
if (before)
try {
before(to);
} catch (error) {
report(error);
}
for (const entry of listeners.slice()) {
if (!entry.live || entry.type !== ev.type) continue;
if (entry.lease) {
@@ -240,5 +248,14 @@ export function createInputRouter({
dispatch,
/** Live listeners, for leak checks. */
listenerCount: () => listeners.length,
/**
* Ends delivery: no listener runs again, even for the event under way
* (a listener that destroys the renderer stops the rest).
*/
dispose() {
for (const entry of listeners) entry.live = false;
listeners.length = 0;
currentLease?.release();
},
};
}
+17
View File
@@ -114,3 +114,20 @@ test('camera holds go to the renderer, reason as a string', () => {
port.suspendCameraControls(7);
assert.deepEqual(reasons, ['7']);
});
test('dispose ends delivery, even of the event under way', () => {
const { port, dispatch, dispose, listenerCount } = router();
const heard = [];
// A lease that leaves presses alone, so the down is everyone else's.
const lease = port.claimPointer('tool', { grab: () => false });
port.on('down', () => {
heard.push('a');
dispose();
});
port.on('down', () => heard.push('b'));
dispatch(ev('down'));
assert.deepEqual(heard, ['a']);
assert.equal(listenerCount(), 0);
assert.equal(lease.current, false, 'the lease ended');
assert.equal(port.isPointerFree(), true);
});