mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(globe): picks on input payloads
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.
This commit is contained in:
1 parent
86aa0bc9ba
commit
b0cb8ce881
26 files changed
+1267
-68
No files matched your search
@@ -72,11 +72,14 @@ const along = (origin, direction, distance) =>
|
||||
* @param {{ waitFrames: (count: number) => Promise<void>, maxWaitFrames?: number,
|
||||
* mapSources?: { imagery: object[], photoreal: object },
|
||||
* readRegion?: (x: number, y: number, width: number, height: number) => Uint8ClampedArray,
|
||||
* makeCanvas?: (width: number, height: number) => object }} options
|
||||
* makeCanvas?: (width: number, height: number) => object,
|
||||
* pointer?: { click: (x: number, y: number) => Promise<void>, move: (x: number, y: number) => Promise<void> } }} options
|
||||
* `mapSources` (two imagery sources and a photoreal one the engine can
|
||||
* show) adds the maps checks; they leave photoreal tiles hidden.
|
||||
* `readRegion` (RGBA bytes of the last drawn frame in a CSS-pixel box) and
|
||||
* `makeCanvas` (a 2D canvas) add the pixel checks of drawn objects.
|
||||
* `pointer` (a real left click and pointer move at a canvas position)
|
||||
* adds the pick checks.
|
||||
* @returns {{ name: string, run: () => Promise<void> }[]}
|
||||
*/
|
||||
export function createContractSuite(
|
||||
@@ -87,6 +90,7 @@ export function createContractSuite(
|
||||
mapSources = null,
|
||||
readRegion = null,
|
||||
makeCanvas = null,
|
||||
pointer = null,
|
||||
},
|
||||
) {
|
||||
if (typeof waitFrames !== 'function')
|
||||
@@ -701,6 +705,104 @@ export function createContractSuite(
|
||||
);
|
||||
},
|
||||
],
|
||||
[
|
||||
'input: picks on click and move payloads, drill, lines',
|
||||
async () => {
|
||||
await nadirView(1e6);
|
||||
const at = (lon, lat, height = 20_000) =>
|
||||
cartesian3.fromDegrees(lon, lat, height);
|
||||
const atlasCanvas = makeCanvas
|
||||
? makeCanvas(16, 16)
|
||||
: { width: 16, height: 16 };
|
||||
if (makeCanvas) {
|
||||
const context = atlasCanvas.getContext('2d');
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, 0, 16, 16);
|
||||
}
|
||||
const set = engine.movers.createSet({
|
||||
id: 'contract-picks',
|
||||
kind: 'sprite',
|
||||
capacity: 3,
|
||||
order: 100,
|
||||
depthTest: 'always',
|
||||
pickable: true,
|
||||
sprite: {
|
||||
atlas: { canvas: atlasCanvas, cells: { box: [0, 0, 1, 1] } },
|
||||
sizePx: 24,
|
||||
},
|
||||
});
|
||||
const line = engine.lines.createLine({
|
||||
id: 'contract-pick-line',
|
||||
widthPx: 8,
|
||||
color: [1, 1, 0, 1],
|
||||
pickId: 'line-1',
|
||||
});
|
||||
const clicks = [];
|
||||
const moves = [];
|
||||
const removers = [
|
||||
engine.input.on('click', (event) => clicks.push(event), {
|
||||
pick: true,
|
||||
drill: 8,
|
||||
}),
|
||||
engine.input.on('move', (event) => moves.push(event), {
|
||||
pick: true,
|
||||
}),
|
||||
];
|
||||
try {
|
||||
const a = at(20, 10);
|
||||
const b = at(21, 10.5);
|
||||
set.set(0, { position: a, pickId: 'a', color: [1, 0, 1, 1] });
|
||||
set.set(1, { position: b, pickId: 'b', color: [1, 0, 1, 1] });
|
||||
set.set(2, { position: b, pickId: 'c', color: [1, 0, 1, 1] });
|
||||
set.setCount(3);
|
||||
set.commit();
|
||||
line.setPositions([at(19, 9), at(21, 9)]);
|
||||
await settle(4);
|
||||
if (!pointer) return;
|
||||
const screen = (position) => engine.projector.worldToWindow(position);
|
||||
const clickAt = async (position) => {
|
||||
const before = clicks.length;
|
||||
const { x, y } = screen(position);
|
||||
await pointer.click(x, y);
|
||||
await until(() => clicks.length > before, 'a click payload');
|
||||
return clicks[clicks.length - 1];
|
||||
};
|
||||
const onA = await clickAt(a);
|
||||
ensure(
|
||||
onA.picked?.id === 'a' && onA.picked?.owner === 'contract-picks',
|
||||
`a click on sprite a picked ${JSON.stringify(onA.picked?.id)} of ${onA.picked?.owner}`,
|
||||
);
|
||||
ensure(onA.picked.instance === 0, `instance ${onA.picked.instance}`);
|
||||
const empty = await clickAt(at(18, 12));
|
||||
ensure(
|
||||
empty.picked === undefined || empty.picked.id === undefined,
|
||||
`a click on the map picked ${JSON.stringify(empty.picked?.id)}`,
|
||||
);
|
||||
const onB = await clickAt(b);
|
||||
const drilled = (onB.drilled ?? []).map(({ id }) => id);
|
||||
ensure(
|
||||
drilled.includes('b') && drilled.includes('c'),
|
||||
`two sprites in one place drilled ${JSON.stringify(drilled)}`,
|
||||
);
|
||||
const onLine = await clickAt(at(20, 9));
|
||||
ensure(
|
||||
onLine.picked?.id === 'line-1',
|
||||
`a click on the line picked ${JSON.stringify(onLine.picked?.id)}`,
|
||||
);
|
||||
const target = screen(a);
|
||||
const movesBefore = moves.length;
|
||||
await pointer.move(target.x + 1, target.y);
|
||||
await until(
|
||||
() => moves.length > movesBefore && moves.at(-1).picked?.id === 'a',
|
||||
'a hover payload over sprite a',
|
||||
);
|
||||
} finally {
|
||||
for (const remove of removers) remove();
|
||||
set.destroy();
|
||||
line.destroy();
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
'render: continuous mode toggles',
|
||||
async () => {
|
||||
|
||||
Reference in new issue
Block a user