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}
-
+
+
+