From 1fa3d3be3e807a641c6cd736fd4eed448f815f47 Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Fri, 13 Nov 2026 23:54:34 -0600 Subject: [PATCH] site: the background carries on across pages instead of starting over Each page began its current from rest and compiled its shaders after first paint, so moving between home and stats showed the bare page colour and then about two seconds of the fibers coming back up, on a different picture. A page now leaves its current in sessionStorage when it is left, and the next page resumes from it if it is under 30 seconds old: same position, regime and energy. Arriving that way, the shaders are compiled and the first frame drawn before first paint. A first visit still defers the compile so the content is never held up. Strata loads the script under the same key as the other pages. Co-Authored-By: Claude Fable 5.2 --- deploy/site/ambient.js | 34 ++++++++++++++++++++++++---------- deploy/site/index.html | 2 +- deploy/site/stats.html | 2 +- deploy/site/statuspage.html | 2 +- strata/index.html | 2 +- tests/current.test.cjs | 14 ++++++++++++++ 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/deploy/site/ambient.js b/deploy/site/ambient.js index 42c557c..1d157ba 100644 --- a/deploy/site/ambient.js +++ b/deploy/site/ambient.js @@ -68,7 +68,15 @@ state.quality *= .8; state.late = 0; return true; } - if (typeof module !== 'undefined') module.exports = { createCurrent, position, regime, receive, energy, moving, packets, seedFor, surfaceScale, pace }; + // the current as a record another page can pick up: times become ages, since each page has its own clock + function keep(current, now) { + return { ...current, sequence: String(current.sequence), at: now - current.at }; + } + // carry on from a record kept `elapsed` ms ago, as if this page had been drawing all along + function resume(current, kept, now, elapsed) { + Object.assign(current, kept, { sequence: BigInt(kept.sequence), at: now - kept.at - elapsed }); + } + if (typeof module !== 'undefined') module.exports = { createCurrent, position, regime, receive, energy, moving, packets, seedFor, surfaceScale, pace, keep, resume }; if (typeof document === 'undefined') return; if (document.body.dataset.page === 'strata' && !document.getElementById('atmosphere')) { @@ -198,13 +206,15 @@ void main(){ targets[name] = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, targets[name]); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textures[name], 0); } - // compile off the main thread where the browser allows it, and only after the page has painted, - // so the shaders never delay the content. until they are ready the canvas shows the page colour, - // which is also their ground. without WebGL2 it stays that way and the river still runs. - function prepare() { + // on a first visit, compile off the main thread where the browser allows it, and only after the page + // has painted, so the shaders never delay the content. until they are ready the canvas shows the page + // colour, which is also their ground. without WebGL2 it stays that way and the river still runs. + // arriving from another page of the site, `now` is set: the picture is drawn before the first paint, + // so it is already there when the old page goes away. + function prepare(now) { gl = canvas.getContext('webgl2', { antialias: false, alpha: false, powerPreference: 'low-power' }); if (!gl) return; - const parallel = gl.getExtension('KHR_parallel_shader_compile'); + const parallel = now ? null : gl.getExtension('KHR_parallel_shader_compile'); for (const [name, fragment] of [['seeds', SEEDS], ['field', FIELD], ['streak', STREAK], ['fiber', FIBER]]) { const program = gl.createProgram(); for (const [type, source] of [[gl.VERTEX_SHADER, TRIANGLE], [gl.FRAGMENT_SHADER, fragment]]) { @@ -294,12 +304,16 @@ void main(){ new ResizeObserver(resize).observe(canvas); document.addEventListener('visibilitychange', () => { if (!document.hidden) wake(); }); reduced.addEventListener('change', wake); - // a page visited moments ago left its last sequence behind, so the first poll here already gives a rate + // a page of the site left moments ago hands its current over, so the picture carries on where it was + let carried = false; try { - const kept = JSON.parse(sessionStorage.getItem('seqCont') || 'null'); - if (kept && Date.now() - kept.t < 30000 && BigInt(kept.seq) > 0n) receive(current, BigInt(kept.seq), performance.now() - (Date.now() - kept.t)); + const kept = JSON.parse(sessionStorage.getItem('current') || 'null'), elapsed = kept ? Date.now() - kept.t : 0; + if (kept && elapsed >= 0 && elapsed < 30000) { resume(current, kept.current, performance.now(), elapsed); carried = true; } } catch {} - requestAnimationFrame(() => setTimeout(prepare, 0)); + addEventListener('pagehide', () => { + try { sessionStorage.setItem('current', JSON.stringify({ t: Date.now(), current: keep(current, performance.now()) })); } catch {} + }); + if (carried) prepare(true); else requestAnimationFrame(() => setTimeout(prepare, 0)); if (document.body.dataset.page === 'strata') { async function observe() { if (document.hidden) return; diff --git a/deploy/site/index.html b/deploy/site/index.html index e6e0f88..9f2d98c 100644 --- a/deploy/site/index.html +++ b/deploy/site/index.html @@ -67,7 +67,7 @@ footer .icon{width:11px;height:11px;vertical-align:-1px;margin-right:.6ch} - + + +
~   s t r e a m   ~strata · local preview

Explore what people are making and sharing.

A shared history of public activity from across the network.
Start with a face you recognize. Tap a sphere to look inside.

Gathering the map…

Each circle groups record types under a shared namespace. Select one to explore.

Search sources

Find something familiar

Search by name or website, or browse the list.

How this works & technical details

+Strata — inside the archive
~   s t r e a m   ~strata · local preview

Explore what people are making and sharing.

A shared history of public activity from across the network.
Start with a face you recognize. Tap a sphere to look inside.

Gathering the map…

Each circle groups record types under a shared namespace. Select one to explore.

Search sources

Find something familiar

Search by name or website, or browse the list.

How this works & technical details

diff --git a/tests/current.test.cjs b/tests/current.test.cjs index d4119d2..3854856 100644 --- a/tests/current.test.cjs +++ b/tests/current.test.cjs @@ -110,3 +110,17 @@ test('late frames step the drawing resolution down, and frames on pace do not', assert.equal(steps, 4); assert.ok(slow.quality <= .5 && slow.quality > .4); }); + +test('a current handed to the next page carries on where it was', () => { + const { createCurrent, receive, position, regime, energy, keep, resume } = require('../deploy/site/ambient.js'); + const old = createCurrent(); + receive(old, 1000n, 0); receive(old, 3000n, 5000); receive(old, 5400n, 10000); + const kept = JSON.parse(JSON.stringify(keep(old, 12000))); + const next = createCurrent(); + resume(next, kept, 40, 300); // the new page's clock reads 40 ms, 300 ms after the old page was left + assert.equal(next.sequence, 5400n); + assert.ok(Math.abs(position(next, 40) - position(old, 12300)) < 1e-9); + assert.ok(Math.abs(regime(next, 40) - regime(old, 12300)) < 1e-9); + assert.ok(Math.abs(energy(next, 40) - energy(old, 12300)) < 1e-9); + assert.equal(energy(next, 40), 1); +}); -- knotmirror 0.0.1