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

+134
View File
@@ -0,0 +1,134 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { bindRenderer } from '../render/rendererOf.js';
import {
captureViewportImage,
capturePointerCrop,
} from './realtimeViewport.js';
/**
* A page with a bound renderer whose canvas must never be read directly:
* its pixels come only through `readPixels`, as the frame it just drew.
*/
function page({ cssWidth = 800, cssHeight = 600, dpr = 2, dprY = dpr } = {}) {
const canvas = {
width: cssWidth * dpr,
height: cssHeight * dprY,
clientWidth: cssWidth,
clientHeight: cssHeight,
};
let fire = null;
const reads = [];
let drawn = false;
const renderer = {
canvas,
frame: {
on(phase, cb) {
if (phase !== 'postRender') return () => {};
fire = cb;
return () => (fire = null);
},
requestRender() {
queueMicrotask(() => {
drawn = true;
fire?.();
drawn = false;
});
},
},
readPixels(options) {
reads.push({ ...options, duringFrame: drawn });
const width = Math.round(
(options.crop?.width ?? cssWidth) * options.scale,
);
const height = Math.round(
(options.crop?.height ?? cssHeight) * options.scale,
);
return {
width,
height,
data: new Uint8ClampedArray(width * height * 4).fill(200),
};
},
};
const viewer = {};
bindRenderer(viewer, renderer);
const put = [];
const encoded = [];
const document = {
hidden: false,
createElement() {
const out = {
width: 0,
height: 0,
getContext: () => ctx,
toDataURL: (type) => {
encoded.push([out.width, out.height]);
return `data:${type};base64,AAAA`;
},
};
const ctx = {
canvas: out,
putImageData: (image, x, y) =>
put.push([image.width, image.height, x, y]),
drawImage(source) {
assert.notEqual(
source,
canvas,
'the renderer’s canvas is never drawn',
);
},
getImageData: (x, y, w, h) => ({
data: new Uint8ClampedArray(w * h * 4).fill(200),
}),
beginPath() {},
arc() {},
stroke() {},
};
return out;
},
querySelector: () => canvas,
};
return { viewer, reads, put, encoded, document };
}
function withPage(p, fn) {
const saved = [globalThis.window, globalThis.document];
globalThis.window = { __godsEyeView: { viewer: p.viewer } };
globalThis.document = p.document;
return Promise.resolve(fn()).finally(() => {
[globalThis.window, globalThis.document] = saved;
});
}
test('the viewport image is the renderer’s readPixels of the fresh frame, as it is drawn', async () => {
const p = page();
const image = await withPage(p, () => captureViewportImage());
assert.match(image, /^data:image\/jpeg;base64,/);
assert.equal(p.reads.length, 1);
const [read] = p.reads;
assert.equal(read.duringFrame, true, 'read in the frame it waited for');
assert.equal(read.crop, undefined, 'the whole canvas');
// 1600 × 1200 drawing-buffer pixels, cut to the 1200 × 900 budget.
assert.deepEqual(p.put, [[1200, 900, 0, 0]]);
});
test('the pointer crop is the renderer’s readPixels around the pointer, as the frame is drawn', async () => {
const p = page();
const crop = await withPage(p, () => capturePointerCrop({ x: 400, y: 300 }));
assert.ok(crop?.dataUrl);
assert.deepEqual(crop.rect, { x: 0.18, y: 44 / 600, w: 0.64, h: 512 / 600 });
const [read] = p.reads;
assert.equal(read.duringFrame, true);
assert.deepEqual(read.crop, { x: 144, y: 44, width: 512, height: 512 });
assert.deepEqual(p.put, [[512, 512, 0, 0]]);
});
test('the pointer crop is its full square even where the canvas is stretched unevenly', async () => {
// Drawing-buffer pixels three to a CSS pixel across and 0.3 down: the
// crop read back is a row taller than it is wide.
const p = page({ dpr: 3, dprY: 0.3 });
const crop = await withPage(p, () => capturePointerCrop({ x: 400, y: 300 }));
assert.ok(crop?.dataUrl);
assert.deepEqual(p.encoded, [[512, 512]], 'a 512 px square');
});