mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
input.on('click'|'doubleClick'|'move', fn, { pick, drill }) delivers
{ …event, picked, drilled }: PickResult { id, owner, instance, primitive
(Cesium) } names the mover set (and instance) or line hit. One pick (and
one drill, as deep as the deepest listener) per event, shared by its
listeners; moves with picks are coalesced to one delivery per frame with
the latest position (src/globe/pickDelivery.js). Option checks in the
contract (normalizeInputOptions).
- Cesium: scene.pick / drillPick, and the picker names the owner: movers
map billboards, points and models to their set and instance, lines
their primitives to the line.
- Navara: a click with pick takes Navara's GPU pick of the same gesture
(featureClick; its pick helper answers on the same pointerup, usually
before the engine's click, so a fresh answer waits for it; otherwise
the click waits up to 250 ms, then the CPU pick). Navara 0.2.1 answers
clicks in quick succession with the first click's pick: a GPU answer
whose instance is not drawn near the click is stale and the CPU pick
answers. Hover, drill and the synchronous picker.pick/drillPick are CPU
picks (src/globe/cpuPicks.js) of pickable mover sets and pickable lines
(within half the width + 3 px), behind the globe excluded, nearest
first; lines are picked on the CPU after an empty GPU answer.
picker.clickStats() (Navara only) counts the answers and latencies.
- The fake engine picks its own movers and lines on the CPU unless
scripted.
- The contract suite clicks with real pointer events (puppeteer) on both
engines: a sprite is picked with its owner and instance, the map picks
nothing, two sprites in one place drill both, a line is picked, a
hover picks the sprite under it. Navara, 20 clicks: payload p50 2.8 ms,
p95 4.1 ms after the click (puppeteer dispatch included), 20/20 GPU
answers. The Cesium harness keeps the first-run card closed.
87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createPickDelivery } from './pickDelivery.js';
|
|
|
|
const entry = (seen, name, options = {}) => ({
|
|
pick: false,
|
|
drill: 0,
|
|
...options,
|
|
listener: (event) => seen.push([name, event]),
|
|
});
|
|
|
|
test('plain listeners get the event; pick listeners the pick and their drill', () => {
|
|
const seen = [];
|
|
const picks = [];
|
|
const delivery = createPickDelivery({
|
|
pick: (at) => (picks.push(at), { id: 'x' }),
|
|
drill: (at, limit) =>
|
|
[{ id: 'x' }, { id: 'y' }, { id: 'z' }].slice(0, limit),
|
|
schedule: () => assert.fail('clicks are not deferred'),
|
|
});
|
|
const event = { position: { x: 1, y: 2 } };
|
|
delivery.deliver('click', event, [
|
|
entry(seen, 'plain'),
|
|
entry(seen, 'pick', { pick: true }),
|
|
entry(seen, 'drill', { pick: true, drill: 2 }),
|
|
]);
|
|
assert.deepEqual(picks, [{ x: 1, y: 2 }], 'one pick for every listener');
|
|
assert.deepEqual(seen[0], ['plain', event]);
|
|
assert.deepEqual(seen[1][1], { ...event, picked: { id: 'x' } });
|
|
assert.deepEqual(seen[2][1].drilled, [{ id: 'x' }, { id: 'y' }]);
|
|
});
|
|
|
|
test('moves with picks are delivered once per frame, with the latest position', () => {
|
|
const seen = [];
|
|
let frame = null;
|
|
const delivery = createPickDelivery({
|
|
pick: (at) => ({ id: `at-${at.x}` }),
|
|
drill: () => [],
|
|
schedule: (run) => {
|
|
frame = run;
|
|
},
|
|
});
|
|
const listeners = [
|
|
entry(seen, 'plain'),
|
|
entry(seen, 'hover', { pick: true }),
|
|
];
|
|
for (const x of [1, 2, 3])
|
|
delivery.deliver(
|
|
'move',
|
|
{ startPosition: { x: x - 1, y: 0 }, endPosition: { x, y: 0 } },
|
|
listeners,
|
|
);
|
|
assert.equal(seen.filter(([name]) => name === 'plain').length, 3);
|
|
assert.equal(seen.filter(([name]) => name === 'hover').length, 0);
|
|
frame();
|
|
const hovers = seen.filter(([name]) => name === 'hover');
|
|
assert.equal(hovers.length, 1);
|
|
assert.equal(hovers[0][1].picked.id, 'at-3');
|
|
});
|
|
|
|
test('asynchronous picks resolve before delivery; removed listeners get nothing', async () => {
|
|
const seen = [];
|
|
const delivery = createPickDelivery({
|
|
pick: async () => ({ id: 'later' }),
|
|
drill: async () => [{ id: 'later' }],
|
|
schedule: (run) => run(),
|
|
});
|
|
const kept = entry(seen, 'kept', { pick: true, drill: 1 });
|
|
const removed = entry(seen, 'removed', { pick: true });
|
|
const live = new Set([kept, removed]);
|
|
const done = delivery.deliver(
|
|
'click',
|
|
{ position: { x: 0, y: 0 } },
|
|
[...live],
|
|
{
|
|
isLive: (candidate) => live.has(candidate),
|
|
},
|
|
);
|
|
live.delete(removed);
|
|
await done;
|
|
assert.deepEqual(
|
|
seen.map(([name]) => name),
|
|
['kept'],
|
|
);
|
|
assert.deepEqual(seen[0][1].drilled, [{ id: 'later' }]);
|
|
});
|