2D map: draw the pictures with the map's own pen, as main did

Cities, markers and labels are now pictures painted once on a canvas of their own. Drawn straight on the map,
main's dashed rings (the selected city, the cities feeding a selected tube, a flood), the cones' tips, a sleeping
POP's "zzz" and a working cable ship's spark took the state the tubes and labels left on the map's canvas: round
line ends and corners, text centred on its middle. A new canvas starts with square ends and text on its baseline, so
the rings came out with square dashes and the "zzz" sat higher. Every picture now starts with that pen (sprPen()),
on the card's shared canvas too.

tests/map-2d.test.js holds the 2D map to main, for players who keep it:
- for the same state, a frame drawn from the kept pictures is, call for call, the frame painted with no cache at
  all: over every state a POP can be in, a city without a POP, random views of the big network with days passing,
  and seeded random games after every move and day (the route-fuzz driver, two pages in lockstep);
- every tube's width, colour, dash and packets follow main's formulas;
- the 2D map never asks for WebGL, never draws a picture without a canvas, keeps one canvas per picture, draws as
  a 2D map after the card is switched off or lost, and paints again at a new pixel density;
- money pop-ups fade as before; every picture starts with the right pen.
Planted bugs (incomplete keys, a stale key memo, the tubes' looks kept without the routing, one shared 2D canvas,
no pen) each fail it. A pixel comparison with main in Chromium (desktop and phone, the fixture, a late-game save and
states from random games) found the pen and nothing else beyond sub-pixel edges.
This commit is contained in:
Antoine 2026-11-04 19:08:36 +01:00
parent 87b153db6f
commit fb76a1e6fd
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
2 changed files with 314 additions and 2 deletions

View file

@ -48,12 +48,16 @@ function spriteEntry(key,w,h,ax,ay,paint){const M=sprMap(),gpu=M===SPRS;let e=M.
e={cv:null,pw,ph,w,h,ax,ay,up:false,u0:0,v0:0,u1:1,v1:1};
if(gpu&&pw<=GLS.size&&ph<=GLS.size){const P=glsPad(pw,ph),g=P.g;
g.save();g.setTransform(1,0,0,1,0,0);g.clearRect(0,0,pw,ph);ctx=g;
try{g.setTransform(DPR,0,0,DPR,0,0);paint(g);}finally{ctx=saved;g.restore();}
try{g.setTransform(DPR,0,0,DPR,0,0);sprPen(g);paint(g);}finally{ctx=saved;g.restore();}
// A full atlas starts again (glsPut), and the picture goes into the empty one at once: the pad is reused next.
try{if(!glsPut(GLX.gl,e,P.cv))glsPut(GLX.gl,e,P.cv);}catch(x){throw glErr(x);}
}else{const cv=document.createElement('canvas');cv.width=pw;cv.height=ph;const g=cv.getContext('2d');ctx=g;
try{g.setTransform(DPR,0,0,DPR,0,0);paint(g);}finally{ctx=saved;}e.cv=cv;}
try{g.setTransform(DPR,0,0,DPR,0,0);sprPen(g);paint(g);}finally{ctx=saved;}e.cv=cv;}
M.set(key,e);return e;}
/* A picture starts with the pen the map's own canvas has when it draws cities and markers: the tubes leave it with
round line ends and corners, the labels with text centred on its middle. Drawn straight on the map, the dashed rings,
the cones' tips and a sleeping POP's "zzz" took those, and a new canvas has others (square ends, text on its baseline). */
function sprPen(g){g.lineCap='round';g.lineJoin='round';g.textAlign='center';g.textBaseline='middle';}
// Puts a picture with its own canvas into the atlas (once), shelf by shelf. A full atlas starts again; this picture then waits a frame.
function glsEnsure(e){if(e.up)return true;const gl=GLX.gl;if(!gl||!GLS.prog||!e.cv)return false;
try{return glsPut(gl,e,e.cv);}catch(x){throw glErr(x);}}