- Sea, land, waves, clouds, cables, tubes and packets are drawn by the graphics card; the land is geometry built once, so panning and zooming repaint nothing. - Cities, labels and markers are painted once into a sprite atlas and drawn in one call (with drawImage in 2D, which speeds up the 2D map too). - Settings > Map drawing: Auto or Always 2D, per device. Browsers without WebGL2, a lost context and puzzles keep the 2D map. - npm run bench:gpu compares 2D and WebGL in a real browser on a real GPU; ?fps shows a frame meter.
29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { load } = require('./harness');
|
|
|
|
// Zoomed in, cable names sit on their cables. Where short cables crowd (the Philippine islands), a name that would
|
|
// land on another is left out, unless the cable touches the selected city.
|
|
const labels = (ev, sel) => JSON.parse(ev(`(()=>{ACT.start({});S.nextFail=1e9;S.nextEvent=1e9;UI.sel=${sel ? `{type:'city',id:'${sel}'}` : 'null'};
|
|
cam.x=(CITY.mnl.x+CITY.dvo.x)/2;cam.y=(CITY.mnl.y+CITY.dvo.y)/2;cam.z=4.5;const out=[];
|
|
const ts=textStamp;textStamp=(t,f,px,w,c,sk,lw,x,y)=>out.push({t,x,y,w});try{drawCables([0]);}finally{textStamp=ts;}return JSON.stringify(out);})()`));
|
|
|
|
test('cable names never sit on top of each other', () => {
|
|
const { ev, errors } = load();
|
|
const L = labels(ev);
|
|
assert.ok(L.length > 5, 'names are drawn');
|
|
assert.ok(L.some(l => l.t === 'Pan de Sal Cable Network'), 'the domestic cables are named');
|
|
const hit = (a, b) => Math.abs(a.x - b.x) < (a.w + b.w) / 2 + 6 && Math.abs(a.y - b.y) < 14;
|
|
const clash = [];
|
|
for (let i = 0; i < L.length; i++) for (let j = i + 1; j < L.length; j++) if (hit(L[i], L[j])) clash.push(`${L[i].t} / ${L[j].t}`);
|
|
assert.deepEqual(clash, []);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test("a selected city's cables are always named", () => {
|
|
const { ev, errors } = load();
|
|
const plain = labels(ev).map(l => l.t), sel = labels(ev, 'ceb').map(l => l.t);
|
|
for (const n of ['Pan de Sal Cable Network', 'Philippines Long Distance Relationship', 'Diverge VisMin Express']) assert.ok(sel.includes(n), n);
|
|
assert.ok(sel.length >= plain.length);
|
|
assert.deepEqual(errors, []);
|
|
});
|