Settings: one Diagnostic info readout for the screen, the map's drawing and its speed

Settings › Viewport info is now Diagnostic info, and the frame meter of the WebGL work joins it: one readout in a
corner instead of two, for bug reports. It shows:
- what the screen tells the game, as before (sizes, visual viewport, safe areas, standalone, the tab bar);
- what draws the map: WebGL2 and the graphics card's name, or 2D and why (Always 2D, a puzzle, no WebGL2, a
  processor pretending to be a card, a lost context, a card out of memory: glKill() keeps the reason);
- how fast: frames per second, the 95th percentile and slowest frame, draw()'s mean time, the speed and zoom, and on
  the card its segments and packets.
?vp and ?fps open it, ?novp and ?nofps close it, five taps on the date toggle it, and a device that had the frame
meter on keeps it. Its text stays technical and in English: it is pasted into reports. On a 360 px phone it wraps
inside the screen and never takes a tap. The setting's name and description are translated.

tests/diagnostic-info.test.js: the setting, the readout's parts, each reason for 2D, the frame figures, the address
flags and the old setting, the taps, and the phone layout.
This commit is contained in:
Antoine 2026-11-04 19:21:23 +01:00
parent 52c8aaffd6
commit cdc7c6d1eb
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
15 changed files with 160 additions and 38 deletions

View file

@ -35,7 +35,7 @@ Object.assign(ACT,{
settings:()=>{UI.setOpen=true;openModal(settingsHtml());},
settingsClose:()=>{UI.setOpen=false;if(!S||!UI.started)showTitle();else closeModal();},
prefSet:({v})=>{const [k,b]=String(v).split(':');if(!own(PREF_DEF,k))return;setPref(k,b==='1');sfx('click');refreshSettings();},
vpSet:({v})=>{vpOn(v==='on');refreshSettings();},
vpSet:({v})=>{diagOn(v==='on');refreshSettings();},
resetAsk:()=>openModal(`<h2 style="font-size:26px">${tr('game_and_settings.start_a_new_network')}</h2><p class="tagline">${tr('game_and_settings.name_and_everything_it_owns_will',{name:esc(S?S.name:tr('common.your_network'))})}</p><div class="btns">${btn(tr('game_and_settings.delete_and_start_over'),'newgame',{},'red big')}${btn(tr('common.keep_playing'),'closeModal',{},'ghost big')}</div>`),
whatsNewShow:()=>whatsNew(true,true),
updateNow:()=>{save(true);location.reload();},

View file

@ -14,15 +14,5 @@ function fixStandaloneHeight(){const R0=document.documentElement;
R0.classList.toggle('iosfix',on);if(on)R0.style.setProperty('--app-h',sh+'px');else R0.style.removeProperty('--app-h');return on?sh:0;}
function resize(){const ah=fixStandaloneHeight();DPR=Math.min(2,window.devicePixelRatio||1);CW=innerWidth;CH=ah||innerHeight;cv.width=CW*DPR;cv.height=CH*DPR;}
addEventListener('resize',()=>{resize();WL.key=null;renderLeft();fitHud();});resize();
// Viewport readout for debugging phone layouts: open the game once with ?vp in the address (or the start URL).
function vpDebug(){let el=document.getElementById('vpdbg');if(!el){el=document.createElement('pre');el.id='vpdbg';el.style.cssText='position:fixed;left:8px;bottom:calc(var(--tabbar,0px) + 8px);z-index:99;margin:0;padding:6px 8px;background:rgba(30,38,64,.85);color:#7CFFB2;font:11px/1.35 ui-monospace,monospace;border-radius:8px;pointer-events:none';document.body.appendChild(el);
const pr=document.createElement('div');pr.id='vpprobe';pr.style.cssText='position:fixed;visibility:hidden;padding:env(safe-area-inset-top,0px) 0 env(safe-area-inset-bottom,0px)';document.body.appendChild(pr);}
const pr=document.getElementById('vpprobe'),cs=getComputedStyle(pr),vv=window.visualViewport,de=document.documentElement,tb=document.getElementById('tabbar').getBoundingClientRect();
el.textContent=`inner ${innerWidth}×${innerHeight} · screen ${screen.width}×${screen.height}\nvv ${vv?Math.round(vv.width)+'×'+Math.round(vv.height)+' top '+Math.round(vv.offsetTop):'-'} · client ${de.clientHeight}\nsafe top ${cs.paddingTop} bottom ${cs.paddingBottom}\nstandalone ${navigator.standalone===true||!!(window.matchMedia&&matchMedia('(display-mode: standalone)').matches)} · iosfix ${de.classList.contains('iosfix')} · CH ${CH}\nbody ${Math.round(document.body.getBoundingClientRect().height)} · tabbar ${Math.round(tb.top)}–${Math.round(tb.bottom)}`;}
let VP_T=null;const vpOn=on=>{clearInterval(VP_T);VP_T=null;const el=document.getElementById('vpdbg');if(el)el.remove();if(on){VP_T=setInterval(vpDebug,500);vpDebug();}try{on?localStorage.setItem('sot-vp','1'):localStorage.removeItem('sot-vp');}catch(e){}};
if(/[?&]vp\b/.test(location.search))vpOn(true);else if(/[?&]novp\b/.test(location.search))vpOn(false);
try{if(localStorage.getItem('sot-vp')==='1')vpOn(true);}catch(e){}
// Inside an installed app there is no address bar: five quick taps on the date toggle the readout.
{let taps=[];document.getElementById('hDate').closest('.chip,div').addEventListener('click',()=>{const t=performance.now();taps=taps.filter(x=>t-x<1500).concat(t);if(taps.length>=5){taps=[];vpOn(!VP_T);}});}
// iOS settles the standalone viewport a moment after launch and after rotating.
for(const t of [300,1000])setTimeout(()=>{resize();WL.key=null;},t);addEventListener('pageshow',()=>{resize();WL.key=null;});

View file

@ -33,7 +33,7 @@ function settingsHtml(){const seg=(lab,act,cur,opts,note)=>`<div class="setline"
${seg(tr('settings.map_drawing'),'mapSet',GLX.want?'auto':'2d',[['auto',tr('common.auto')],['2d',tr('settings.always_2d')]],tr('settings.auto_draws_the_map_with_your')+(GLX.want&&!glInit()?' '+tr('settings.this_browser_cannot_so_the_map'):''))}
${seg(tr('common.sound'),'soundSet',UI.muted?'off':'on',[['on',tr('common.on')],['off',tr('common.off')]])}
<div class="setline"><label for="langSel">${tr('common.language')}</label>${langPick('langSel')}</div>
${seg(tr('common.viewport_info'),'vpSet',VP_T?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_reporting_layout_bugs_shows_what'))}
${seg(tr('settings.diagnostic_info'),'vpSet',DIAG.on?'on':'off',[['on',tr('common.on')],['off',tr('common.off')]],tr('settings.for_bug_reports_shows_your_screen'))}
${installRow()}<div class="btns" style="margin-top:12px">${btn(tr('common.done_8dd3'),'settingsClose',{},'pink')}</div>`;}
const refreshSettings=()=>{if(UI.setOpen)openModal(settingsHtml());};
function animOn(){const m=UI.anim||'auto';if(m==='on')return true;if(m==='off')return false;try{return !matchMedia('(prefers-reduced-motion: reduce)').matches;}catch(e){return true;}}

View file

@ -19,7 +19,7 @@ function mapGl(on,keep=true){GLX.want=!!on;if(keep)try{on?localStorage.removeIte
function glShow(on){on=!!on;if(GLX.shown===on)return;GLX.shown=on;const e=document.getElementById('mapgl'),fx=document.getElementById('mapfx');if(e)e.hidden=!on;if(fx)fx.hidden=!on;}
// Marks an error as the card's own, so draw() falls back to 2D instead of trying WebGL again every frame.
function glErr(e){const x=e instanceof Error?e:new Error(String(e));x.glErr=true;return x;}
function glKill(why){console.warn('[tubes] the map stays 2D:',why&&why.message||why);GLX.dead=true;GLX.gl=null;spritesDrop();glShow(false);}
function glKill(why){console.warn('[tubes] the map stays 2D:',why&&why.message||why);GLX.why=String(why&&why.message||why);GLX.dead=true;GLX.gl=null;spritesDrop();glShow(false);}
/* A card short of memory may refuse a texture or a buffer without throwing: it only leaves OUT_OF_MEMORY for
getError(), and the texture then draws black (every picture a black box) or the buffer draws nothing. So the big
uploads (the atlas, the land, the tubes, the cables) read it, and give the card up like any of its errors. Never

View file

@ -0,0 +1,36 @@
/* Settings › Diagnostic info: one readout in a corner, for bug reports. What the screen tells the game (for phone
layouts), how the map is drawn (the graphics card or 2D, and why), and how fast: frames per second, the slowest
frames, the time draw() takes. It is also opened with ?vp or ?fps in the address (?novp, ?nofps close it), and,
inside an installed app where there is no address bar, with five quick taps on the date. Its words are technical on
purpose and stay in English: they are pasted into bug reports. */
const DIAG={on:false,el:null,t:null,fr:[],dr:[],last:0,dms:-1};
// One frame of the loop (99-loop.js): its interval, and the time draw() took if the map was drawn.
function diagFrame(now){const D=DIAG;if(D.last)D.fr.push(now-D.last);D.last=now;if(D.dms>=0){D.dr.push(D.dms);D.dms=-1;}
if(D.fr.length>600)D.fr.splice(0,300);if(D.dr.length>600)D.dr.splice(0,300);}
// What draws the map, and why it is the 2D canvas when it is.
function diagMap(){if(!S)return 'map: none (title screen)';if(pzOn())return 'map: 2D (puzzle)';if(!GLX.want)return 'map: 2D (Always 2D)';
if(GLX.dead)return 'map: 2D ('+(GLX.why||'no WebGL2')+')';return GLX.gl&&GLX.shown?'map: WebGL2 · '+(GLX.gpu||'unknown GPU'):'map: WebGL2 (starting)';}
// Frames since the last readout: per second, the 95th percentile and the slowest, and draw()'s mean.
function diagPerf(){const f=DIAG.fr.splice(0),d=DIAG.dr.splice(0),s=f.slice().sort((a,b)=>a-b),sum=f.reduce((a,x)=>a+x,0),
q=x=>s.length?s[Math.min(s.length-1,Math.floor(s.length*x))].toFixed(0):'-',gl=GLX.shown&&!GLX.dead;
return `${sum?(f.length*1000/sum).toFixed(0):'-'} fps · p95 ${q(.95)} ms · max ${q(1)} ms\ndraw ${d.length?(d.reduce((a,x)=>a+x,0)/d.length).toFixed(1):'-'} ms · x${UI.speed||0} · zoom ${cam.z.toFixed(2)}`+
(gl?` · ${GLX.nSeg} segments · ${GLX.nPk} packets`:'');}
function diagShow(){const D=DIAG;let el=D.el;
if(!el){el=D.el=document.createElement('pre');el.id='diag';el.style.cssText='position:fixed;left:8px;bottom:calc(var(--tabbar,0px) + 8px);z-index:99;margin:0;padding:6px 8px;max-width:calc(100vw - 32px);background:rgba(30,38,64,.85);color:#7CFFB2;font:11px/1.35 ui-monospace,monospace;border-radius:8px;pointer-events:none;white-space:pre-wrap;overflow-wrap:anywhere';
// A hidden probe reads the safe areas (the notch, the home bar) as CSS gives them.
const pr=document.createElement('div');pr.id='diagprobe';pr.style.cssText='position:fixed;visibility:hidden;padding:env(safe-area-inset-top,0px) 0 env(safe-area-inset-bottom,0px)';el.appendChild(pr);
D.txt=document.createTextNode('');el.appendChild(D.txt);document.body.appendChild(el);}
const cs=getComputedStyle(document.getElementById('diagprobe')),vv=window.visualViewport,de=document.documentElement,tb=document.getElementById('tabbar').getBoundingClientRect(),
sa=navigator.standalone===true||!!(window.matchMedia&&matchMedia('(display-mode: standalone)').matches);
D.txt.data=`Series of Tubes ${APP_VERSION} · ${LANG}\n`+
`inner ${innerWidth}×${innerHeight} · screen ${screen.width}×${screen.height} · dpr ${window.devicePixelRatio||1}\n`+
`vv ${vv?Math.round(vv.width)+'×'+Math.round(vv.height)+' top '+Math.round(vv.offsetTop):'-'} · client ${de.clientHeight}\nsafe top ${cs.paddingTop} bottom ${cs.paddingBottom}\n`+
`standalone ${sa} · iosfix ${de.classList.contains('iosfix')} · CH ${CH}\nbody ${Math.round(document.body.getBoundingClientRect().height)} · tabbar ${Math.round(tb.top)}–${Math.round(tb.bottom)}\n`+
diagMap()+'\n'+diagPerf();}
// Shows or hides the readout, and remembers it on this device.
function diagOn(on){const D=DIAG;clearInterval(D.t);D.t=null;if(D.el){D.el.remove();D.el=null;}D.on=!!on;D.fr.length=D.dr.length=0;D.last=0;D.dms=-1;
if(on){D.t=setInterval(diagShow,500);diagShow();}
try{on?localStorage.setItem('sot-vp','1'):localStorage.removeItem('sot-vp');localStorage.removeItem('sot-fps');}catch(e){}}
{const q=location.search;let on=false;try{on=localStorage.getItem('sot-vp')==='1'||localStorage.getItem('sot-fps')==='1';}catch(e){}
if(/[?&](vp|fps)\b/.test(q))on=true;else if(/[?&]no(vp|fps)\b/.test(q))on=false;diagOn(on);}
{let taps=[];document.getElementById('hDate').closest('.chip,div').addEventListener('click',()=>{const t=performance.now();taps=taps.filter(x=>t-x<1500).concat(t);if(taps.length>=5){taps=[];diagOn(!DIAG.on);}});}

View file

@ -1,11 +0,0 @@
/* A frame meter for measuring the map on a real device: open the game once with ?fps (?nofps hides it again).
Frames per second, the slowest frames, the time draw() takes, and which renderer and graphics card draw the map. */
const FPSM={on:false,el:null,fr:[],dr:[],last:0,shown:0,dms:-1};
try{const q=location.search;if(/[?&]fps\b/.test(q))localStorage.setItem('sot-fps','1');else if(/[?&]nofps\b/.test(q))localStorage.removeItem('sot-fps');
FPSM.on=localStorage.getItem('sot-fps')==='1';}catch(e){}
function fpsNote(now){const M=FPSM;if(M.last)M.fr.push(now-M.last);M.last=now;if(M.dms>=0){M.dr.push(M.dms);M.dms=-1;}
if(now-M.shown<500)return;M.shown=now;
if(!M.el){M.el=document.createElement('pre');M.el.id='fpsm';M.el.style.cssText='position:fixed;right:8px;bottom:calc(var(--tabbar,0px) + 8px);z-index:99;margin:0;padding:6px 8px;background:rgba(30,38,64,.85);color:#7CFFB2;font:11px/1.35 ui-monospace,monospace;border-radius:8px;pointer-events:none;white-space:pre';document.body.appendChild(M.el);}
const f=M.fr.splice(0),d=M.dr.splice(0),s=f.slice().sort((a,b)=>a-b),sum=f.reduce((a,x)=>a+x,0),q=x=>s.length?s[Math.min(s.length-1,Math.floor(s.length*x))].toFixed(0):'-';
const gl=GLX.shown&&!GLX.dead;
M.el.textContent=`${sum?(f.length*1000/sum).toFixed(0):0} fps · p95 ${q(.95)} ms · max ${q(1)} ms\ndraw ${d.length?(d.reduce((a,x)=>a+x,0)/d.length).toFixed(1):'-'} ms · ${gl?'WebGL':'2D'} · x${UI.speed||0}`+(gl?`\n${GLX.nSeg} segments · ${GLX.nPk} packets\n${GLX.gpu.slice(0,60)}`:'');}

View file

@ -12,8 +12,8 @@ function frame(now){
if(S&&!S.lost&&$('modal').hidden&&UI.speed&&!pzOn())runClock(dt);
if((UI.speed||pzOn())&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */
const t=animOn()?animT:0;
if(!(UI.mapHid=mapHidden())&&!mapStill(t,now)){const d0=FPSM.on?performance.now():0;try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;if(FPSM.on)FPSM.dms=performance.now()-d0;}
if(FPSM.on)fpsNote(now);
if(!(UI.mapHid=mapHidden())&&!mapStill(t,now)){const d0=DIAG.on?performance.now():0;try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;if(DIAG.on)DIAG.dms=performance.now()-d0;}
if(DIAG.on)diagFrame(now);
}
// dt of real time at UI.speed: the days it adds up to. The frame calls it; so may a clock that also runs where frames
// do not (src/agent/, a hidden tab), under the frame's own conditions otherwise.