Draw the map with WebGL2 by default, with the 2D canvas as fallback

- 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.
This commit is contained in:
Antoine 2026-11-04 11:37:27 +01:00
parent 7aa6506e70
commit cf9ab5e774
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
36 changed files with 862 additions and 83 deletions

View file

@ -12,7 +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)){try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;}
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);
}
// 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.
@ -27,12 +28,12 @@ function mapHidden(){for(const id of ['dashCard','bankCard']){const c=$(id);if(c
const r=c.getBoundingClientRect();if(r.top<=1&&r.left<=1&&r.right>=innerWidth-1&&r.bottom>=innerHeight-1)return true;}return false;}
/* Paused, or with animations off, the map only changes when you move it, point at something or the network changes.
Until then the last frame is still right, so it is not drawn again (phones keep cool). It is redrawn at least once
a second anyway, and every frame while the land picture is still catching up with a zoom. */
a second anyway, and every frame while the land picture is still catching up with a zoom (the WebGL map has none). */
const FRAME=[];
function mapStill(t,now){const sl=UI.sel,dr=UI.drag;
const v=[t,cam.x,cam.y,cam.z,CW,CH,DPR,S,R,S&&S.day,S&&S.links.length,S&&S.offers.length,S&&S.inc.length,sl&&sl.type,sl&&sl.id,UI.hover,UI.snap&&UI.snap.id,dr&&dr.mode,dr&&dr.cx,dr&&dr.cy,FLOATS.length,UI.mk?UI.mk.tx:0,UI.mk?UI.mk.mood:0];
let same=v.length===FRAME.length;for(let i=0;i<v.length;i++)if(FRAME[i]!==v[i]){same=false;FRAME[i]=v[i];}
return same&&now-(UI.drawnAt||0)<1000&&!!(WL.cv&&WL.key===(cam.z*DPR).toFixed(4)&&wlCovers(cam.z));}
return same&&now-(UI.drawnAt||0)<1000&&(glOn()||!!(WL.cv&&WL.key===(cam.z*DPR).toFixed(4)&&wlCovers(cam.z)));}
function tickErr(e){console.error('[tubes] tick failed',e);if(UI.tickErr)return;UI.tickErr=true;track('tick_error',true);
toast(tr('loop.something_in_the_noc_glitched_the'),'bad');}
function boot(data){