Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -2114,3 +2114,8 @@ three boards, and the title.
"Double click a labs board to show it alone wth full screen." The three labs set `soloOnDouble`, the field's ONE BOARD, ALONE, FULL SCREEN
(`docs/field.md`): a double click shows the board by itself over the whole page, turned by a drag, nearer by the wheel or two fingers, shut by a
double click, Escape or ×. Its pieces are asked at the screen's size, so a thousand-body board shows every body (A PIXEL'S WORTH does not apply).
Then (1 Dec 2026, "Is the box needed in full screen mode", then "Yes, remove it for gravity and charge"): shown alone, Gravity lab and Charge lab
leave out their box (its edges, floor and glass; `soloItems`, `noBox`), since nothing in them touches it, and draw what has flown out of it
out to three times its size (`LAB_SOLO`, which `gvIn` reads, set in the worker around the board's pieces); the shadows stay, on a faint floor
grid of the view's own (`soloFloor`). Gas lab keeps its box: its balls bounce off it, its wall moves, its bars stand on its floor. The view is
now fitted to how far the pieces reach from the middle (the shadows left out). Part 5's check sees Gas lab in its box and the other two without.
34 changes: 23 additions & 11 deletions games.html
Original file line number Diff line number Diff line change
Expand Up @@ -31736,7 +31736,9 @@
if (end && S.t > end){ const T = gvNew(S.idx, S.lv, S.run + 1, S.kind); Object.assign(S, T); }
}
// drawn inside the cube and a little past it; what has gone farther is not
const gvIn = (x, y, z) => Math.abs(x) < GV_H * 1.1 && Math.abs(y) < GV_H * 1.1 && Math.abs(z) < GV_H * 1.1;
// (…and, shown alone full screen, out to three times the box, its box not drawn: LAB_SOLO, Dec 1, "Yes, remove it for gravity and charge")
let LAB_SOLO = false;
const gvIn = (x, y, z) => { const L = GV_H * (LAB_SOLO ? 3 : 1.1); return Math.abs(x) < L && Math.abs(y) < L && Math.abs(z) < L; };
function gvItems(S){
if (S.kind === 'column') return gcItems(S);
if (S.kind === 'lens') return glzItems(S);
Expand Down Expand Up @@ -32266,6 +32268,8 @@
cellGrid(){ return { n: 1, colors: [BASE] }; },
cellItems(c, r, bp){ return LABW.items('gravity', c, r, bp); },
soloOnDouble: true, // (a double click shows the board alone, full screen: ONE BOARD, ALONE, FULL SCREEN, Dec 1)
// (alone, without its box: what has flown out of it is still drawn, out to three times its size, Dec 1)
soloItems(c, r, bp){ return LABW.items('gravity', c, r, bp, true); }, soloFloor: true,
// (more room for the small dots than the field's 48,000 a kind: a field of boards of a thousand bodies each, A PIXEL'S WORTH, Dec 1)
itemCaps: kind => kind === 'gvDot' ? 240000 : 0,
menu: [{ head: 'Gravity lab', items: [{ label: GVL.item.label, title: GVL.item.title, on(){ GVL.item.on(); GVS.clear(); try { fieldItemsChanged(); } catch {} } }, GVPICK.item] }],
Expand Down Expand Up @@ -32583,6 +32587,8 @@
cellGrid(){ return { n: 1, colors: [BASE] }; },
cellItems(c, r, bp){ return LABW.items('charge', c, r, bp); },
soloOnDouble: true, // (a double click shows the board alone, full screen: ONE BOARD, ALONE, FULL SCREEN, Dec 1)
// (alone, without its box: what has flown out of it is still drawn, out to three times its size, Dec 1)
soloItems(c, r, bp){ return LABW.items('charge', c, r, bp, true); }, soloFloor: true,
menu: [{ head: 'Charge lab', items: [{ label: CHL.item.label, title: CHL.item.title, on(){ CHL.item.on(); CHS.clear(); try { fieldItemsChanged(); } catch {} } }, CHPICK.item] }],
cellTitle(c, r){ return LABW.title('charge', c, r); },
onReset(c, r){ CHS.delete(gkey(c, r)); LABW.reset('charge', gkey(c, r)); CHLIVE = { c, r }; try { fieldItemsChanged(); } catch {} return true; },
Expand Down Expand Up @@ -32637,7 +32643,7 @@
d.boards.sort((a, b) => (b.framed - a.framed) || ((SERVED.get(a.key) || 0) - (SERVED.get(b.key) || 0)));
for (const b of d.boards){ if (!b.framed && performance.now() - t0 > LAB_BUDGET) break; SERVED.set(b.key, performance.now()); let S = L.M.get(b.key);
if (!S || S.kind !== b.kind || S.lv !== b.lv){ S = L.New(b.idx, b.lv, b.kind); } L.M.delete(b.key); L.M.set(b.key, S);
L.adv(S, b.framed); const f = pack(b.framed ? L.items(S) : labThin(L.items(S), b.bp)); bufs.push(f.buffer);
L.adv(S, b.framed); LAB_SOLO = !!b.solo; let IT; try { IT = L.items(S); } finally { LAB_SOLO = false; } const f = pack(b.framed ? IT : labThin(IT, b.bp)); bufs.push(f.buffer);
const o = { key: b.key, f }; if (b.title) o.title = L.title(S);
if (b.framed && d.lab === 'gas'){ o.snd = { kind: S.kind, hits: S.hits, hitV: S.hitV, bigHit: S.bigHit, mixed: S.mixed }; S.bigHit = 0; }
out.push(o); }
Expand Down Expand Up @@ -32681,23 +32687,26 @@
}
// (a board's key is "c_r", a string: the worker is chosen by its column and row, so neighbours go to different workers)
const workerOf = key => { const [c, r] = String(key).split('_').map(Number); return W.ws[(((c * 7 + r * 3) % W.ws.length) + W.ws.length) % W.ws.length] || W.ws[0]; };
function ask(lab, c, r, title, bp){
function ask(lab, c, r, title, bp, solo){
const L = LAB[lab], key = gkey(c, r), idx = boardIdx(c, r), live = L.live();
if (W.lab !== lab){ W.lab = lab; W.items.clear(); W.titles.clear(); W.ear.clear(); for (const X of W.ws){ X.want.clear(); X.pending = false; } }
const X = workerOf(key), was = X.want.get(key), framed = !!(live && live.c === c && live.r === r);
X.want.set(key, { key, idx, lv: L.level(idx), kind: L.pick.kindOf(idx), framed, title: title || (was && was.title) || framed, bp: bp || (was && was.bp) || 0 });
X.want.set(key, { key, idx, lv: L.level(idx), kind: L.pick.kindOf(idx), framed, title: title || (was && was.title) || framed, bp: bp || (was && was.bp) || 0, solo: !!(solo || (was && was.solo)) });
flush(); return key;
}
function items(lab, c, r, bp){
function items(lab, c, r, bp, solo){
const L = LAB[lab];
if (!start()){ const S = L.of(c, r), live = L.live(), framed = !!(live && live.c === c && live.r === r), want = L.adv(S, framed);
if (framed && lab === 'gas' && want) glSound(S, want); return framed ? L.items(S) : labThin(L.items(S), bp); }
const key = ask(lab, c, r, false, bp); return W.items.get(key) || frameItems(EDGE);
if (framed && lab === 'gas' && want) glSound(S, want); LAB_SOLO = !!solo; let IT; try { IT = L.items(S); } finally { LAB_SOLO = false; }
return solo ? noBox(IT) : framed ? IT : labThin(IT, bp); }
const key = ask(lab, c, r, false, bp, solo), got = W.items.get(key) || frameItems(EDGE); return solo ? noBox(got) : got;
}
function title(lab, c, r){
const L = LAB[lab]; if (!start()) return L.title(L.of(c, r));
const key = ask(lab, c, r, true); return W.titles.get(key) || L.name + ' — …';
}
// (shown alone, Gravity lab's and Charge lab's box is not drawn: its edges, floor and glass; the shadows stay, on the view's own floor)
const noBox = L => L.filter(it => it.kind !== 'zgBar' && it.kind !== 'zgGlass');
function reset(lab, key){ W.items.delete(key); W.titles.delete(key); if (W.ws.length) workerOf(key).w.postMessage({ lab, reset: key }); }
return { items, title, reset, W, get mode(){ return W.mode; }, src: labWorkerSrc };
})();
Expand Down Expand Up @@ -69353,6 +69362,8 @@
root.append(R2.domElement, title, close); document.body.appendChild(root);
const scene2 = new THREE.Scene(); scene2.background = new THREE.Color(0x0e1420);
scene2.add(new THREE.HemisphereLight(0xf4f2ff, 0x30343e, 0.95)); const sun = new THREE.DirectionalLight(0xffffff, 0.55); sun.position.set(0.4, 1, 0.3); scene2.add(sun);
// (an app whose box is left out alone, `soloItems`, may ask for a faint floor instead, `soloFloor`: something to stand the view on as it turns)
if (app.soloFloor){ const g = new THREE.GridHelper(3, 18, 0x3a4660, 0x1a2130); g.position.y = 0.03; g.material.transparent = true; g.material.opacity = 0.55; scene2.add(g); }
const cam = new THREE.PerspectiveCamera(38, 1, 0.01, 100), meshes = new Map(), view = { yaw: 0.6, pitch: 0.55, dist: 0, cy: 0, fitted: false };
const S = SOLO.open = { app, c, r, root, R2, scene2, cam, meshes, view, raf: 0, titleAt: 0 };
const recOf = kind => {
Expand All @@ -69372,21 +69383,22 @@
S.raf = requestAnimationFrame(frame);
const w = root.clientWidth || window.innerWidth, h = root.clientHeight || window.innerHeight;
if (R2.domElement.width !== Math.round(w * R2.getPixelRatio()) || R2.domElement.height !== Math.round(h * R2.getPixelRatio())){ R2.setSize(w, h, false); cam.aspect = w / h; cam.updateProjectionMatrix(); }
let L = null; try { L = app.cellItems(c, r, Math.max(w, h)); } catch (e){ _reportError('one board alone', e); }
let L = null; try { L = app.soloItems ? app.soloItems(c, r, Math.max(w, h)) : app.cellItems(c, r, Math.max(w, h)); } catch (e){ _reportError('one board alone', e); }
for (const rec of meshes.values()) rec.n = 0;
let lo = Infinity, hi = -Infinity;
let lo = Infinity, hi = -Infinity, reach = 0;
for (const it of L || []){
const rec = recOf(it.kind || 'default'); if (!rec) continue;
if (rec.n >= rec.cap){ rec.cap *= 2; rec.mesh = growInstanced(rec.mesh, rec.cap); } // (it takes the old one's place in the scene)
const u = it.u == null ? 0.5 : it.u, v = it.v == null ? 0.5 : it.v, s = it.scale || 0.25, y = 0.02 + (it.lift || 0);
P.set(0.5 - u, y, 0.5 - v); Sc.set(s * (it.sx || 1), s * (it.sy || 1), s * (it.sz || 1));
if (it.rot) Q.set(it.rot[2], it.rot[3], -it.rot[0], -it.rot[1]); else if (it.yaw) Q.setFromAxisAngle(UP, Math.PI - it.yaw); else Q.identity();
M.compose(P, Q, Sc); rec.mesh.setMatrixAt(rec.n, M); rec.mesh.setColorAt(rec.n, _appColor(it.color == null ? 0xf0e6d2 : it.color)); rec.n++;
if (y < lo) lo = y; if (y > hi) hi = y;
if (it.kind !== 'zgShadow'){ if (y < lo) lo = y; if (y > hi) hi = y; } if (it.kind !== 'zgShadow') reach = Math.max(reach, Math.hypot(P.x, P.z) + s * Math.max(it.sx || 1, it.sz || 1) / 2);
}
for (const rec of meshes.values()){ rec.mesh.count = rec.n; rec.mesh.instanceMatrix.needsUpdate = true; if (rec.mesh.instanceColor) rec.mesh.instanceColor.needsUpdate = true; }
// (the view fitted once, to the board and what stands on it: its middle height, and far enough back that a board's width and its height both show)
if (!view.fitted && lo < hi){ view.cy = (lo + hi) / 2; const span = Math.max(1, hi - lo); view.dist = 0.72 * span / Math.tan(cam.fov * Math.PI / 360) / Math.min(1, cam.aspect); view.fitted = true; }
// (fitted to how far the pieces reach from the middle, across and up: with a box, the box; without one, what is in it)
if (!view.fitted && lo <= hi && isFinite(lo)){ view.cy = (lo + hi) / 2; const rad = Math.max(0.12, reach, (hi - lo) / 2); view.dist = 0.95 * rad / Math.tan(cam.fov * Math.PI / 360) / Math.min(1, cam.aspect); view.fitted = true; }
if (!view.fitted){ view.cy = 0.3; view.dist = 2.4; }
const d = view.dist, cp = Math.cos(view.pitch);
cam.position.set(d * cp * Math.sin(view.yaw), view.cy + d * Math.sin(view.pitch), d * cp * Math.cos(view.yaw)); cam.lookAt(0, view.cy, 0);
Expand Down
6 changes: 3 additions & 3 deletions tests/part5.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,13 +2065,13 @@ const game = { title: 'Words', size: l => 5 + Math.ceil(l / 2),
const p = await page.evaluate(() => window.__aim(1, 0, 0));
await page.mouse.dblclick(p.x, p.y); await drawn(page, 1500);
const on = await page.evaluate(() => { const s = window.fieldSolo.state, el = document.getElementById('soloView'), r = el && el.getBoundingClientRect();
return s && { pieces: s.kinds.reduce((a, [, n]) => a + n, 0), title: s.title.slice(0, 40), full: !!r && r.width >= innerWidth - 1 && r.height >= innerHeight - 1 }; });
return s && { pieces: s.kinds.reduce((a, [, n]) => a + n, 0), box: s.kinds.some(([k, n]) => k === 'zgBar' && n > 0), title: s.title.slice(0, 40), full: !!r && r.width >= innerWidth - 1 && r.height >= innerHeight - 1 }; });
await page.mouse.move(400, 300); await page.mouse.down(); await page.mouse.move(520, 340, { steps: 5 }); await page.mouse.up(); await drawn(page, 400);
await page.mouse.dblclick(600, 420); await drawn(page, 800);
const off = await page.evaluate(() => !window.fieldSolo.state && !document.getElementById('soloView'));
const ok = p.ok && on && on.pieces > 10 && on.full && /lab — /.test(on.title) && off;
const ok = p.ok && on && on.pieces > 10 && on.full && /lab — /.test(on.title) && off && on.box === (id === 'gaslab'); // (Gas lab keeps its box alone, the others not: Dec 1)
if (!ok) failures.push('[lab alone] ' + id + ' ' + JSON.stringify({ p, on, off }));
console.log(`${ok ? 'ok ' : 'FAIL'} ${id}, a double click shows the board alone, full screen: ${on ? on.pieces + ' pieces, "' + on.title + '…"' : 'not opened'}; shut by a double click ${off}`);
console.log(`${ok ? 'ok ' : 'FAIL'} ${id}, a double click shows the board alone, full screen: ${on ? on.pieces + ' pieces' + (on.box ? ', in its box' : ', no box') + ', "' + on.title + '…"' : 'not opened'}; shut by a double click ${off}`);
}

} catch (e){
Expand Down