diff --git a/CHANGELOG.md b/CHANGELOG.md index a076f4e..64021a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to this project are documented here. The project follows - The NOC charts have tooltips, on the dashboard and on the wallboard in the NOC window: hover (or touch) a chart to see every series on that day, with a total. Click an entry in the legend to hide or show that series, and the scale follows what is left. The "how it arrives" bars on the Traffic tab show the same kind of tooltip, and its legend picks which ways in (caches, PNIs, IX peering, transit) the table counts. - Bilbao joins the map, where the transatlantic cables really come ashore: Marea Carey, Grace Hopscotch and Sol Survivor now land there instead of Madrid. It has no exchange of its own, so traffic heads inland to Madrid, and Drizzle Electric, Tangerine Telecom and the big carriers sell transit there. A link you already run on the old Madrid landings keeps working as a plain subsea link, and the Mid-Atlantic Accent scenario now goes Azores, Bilbao, Madrid, and Marea Carey now leaves the American coast at Virginia Beach instead of crossing the northeast to New Jersey. Columbus III-and-a-half now comes ashore near Cádiz, where it really landed, on its way to Madrid. - Puzzles are easier to read, above all on phones: the three stars are now three goals in plain words, and the one you are working on says what is wrong and what to do, with a Show me button. The map marks it too: a red ring around a city that still needs traffic, and a pulsing ✂ on a link whose cut would hurt. On phones the sheet starts small so the map gets the screen; swipe it up for the rest. Cities far from the puzzle are left off the map, and stepping stones you are not using are small dots without a name until you tap one, build there or zoom in. -- The map is now drawn by the graphics card wherever the browser can, so panning, zooming and fast play stay smooth on big networks and big screens. The map looks the same; Settings › Map drawing › Always 2D keeps the old drawing, and browsers without WebGL2 keep it on their own. +- The map is now drawn by the graphics card wherever the browser can, so panning, zooming and fast play stay smooth on big networks and big screens. The map looks the same; Settings › Map drawing › Always 2D keeps the old drawing, and browsers without WebGL2 keep it on their own, as does a game whose graphics card fails while you play. - Cities, labels, building cones, ships, offer bubbles and money pop-ups are painted once and then reused, so the usual map also draws far fewer shapes each frame. ## [2.9.1] — 2026-11-04 diff --git a/src/game/96-map/56-webgl.js b/src/game/96-map/56-webgl.js index 1469c6c..5306506 100644 --- a/src/game/96-map/56-webgl.js +++ b/src/game/96-map/56-webgl.js @@ -6,13 +6,15 @@ packets (58) and the pictures of cities, labels and markers (59); and #mapfx, a transparent 2D canvas over it for the few things still painted shape by shape (the drag preview, the chaos monkey), cleared only after it was used. Puzzles, and any browser without WebGL2 or whose context fails or is lost, keep the 2D map. */ -const GLX={want:true,dead:false,gl:null,c:null,f:null,fx:null,key:[],nSeg:0,nPk:0,sel:false,shown:false,gpu:''}; +const GLX={want:true,dead:false,gl:null,c:null,f:null,fx:null,key:[],nSeg:0,nPk:0,nHalo:0,shown:false,gpu:''}; try{GLX.want=localStorage.getItem('sot-map')!=='2d';}catch(e){} const glOn=()=>GLX.want&&!GLX.dead&&!!S&&!pzOn()&&glInit(); // Switches the WebGL map on or off: the setting keeps the choice in this browser (keep), the GPU benchmark does not. function mapGl(on,keep=true){GLX.want=!!on;if(keep)try{on?localStorage.removeItem('sot-map'):localStorage.setItem('sot-map','2d');}catch(e){} if(!on)glShow(false);GLX.key=[];UI.drawnAt=0;return on&&!GLX.dead;} 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;glShow(false);} const GL_HEAD='#version 300 es\nprecision highp float;precision highp int;\n'; // Clip space from CSS px (the shaders work in CSS px, as the 2D map does, and use uDpr only for anti-aliasing). @@ -42,7 +44,7 @@ function glInit(){if(GLX.gl)return true;if(GLX.dead)return false; const fx=f.getContext('2d'),CP=CanvasRenderingContext2D.prototype; for(const m of ['fill','stroke','fillRect','strokeRect','fillText','strokeText','drawImage','putImageData']){const fn=CP[m];fx[m]=function(){GLX.fxUsed=true;return fn.apply(this,arguments);};} const V=s=>glVao(gl,s); - Object.assign(GLX,progs,{gl,c,f,fx,fxUsed:true,tex,land:{},lv:V([4,4,4]),pv:V([4,4]),cb:V([4,4,4]),wv:V([4,4,4]),cl:V([4]),empty:gl.createVertexArray()});return true;} + Object.assign(GLX,progs,{gl,c,f,fx,fxUsed:true,tex,land:{},lv:V([4,4,4]),hv:V([4,4,4]),pv:V([4,4]),cb:V([4,4,4]),wv:V([4,4,4]),cl:V([4]),empty:gl.createVertexArray()});return true;} catch(e){glKill(e);return false;}} // Colours as [r,g,b,a] from '#rrggbb', '#rgb' or 'rgba(r,g,b,a)', kept by string. const GLCOL=new Map(); diff --git a/src/game/96-map/58-webgl-links.js b/src/game/96-map/58-webgl-links.js index d034873..958f47b 100644 --- a/src/game/96-map/58-webgl-links.js +++ b/src/game/96-map/58-webgl-links.js @@ -1,6 +1,7 @@ /* The tubes on the card: every tube is one instanced draw per layer (halo, casing, colour, fiber dots, packets), and the packets travel their paths in the vertex shader, so a frame costs a few uniforms however many tubes there are. - The buffers are rebuilt only when the network, the routing, the day or the selection change. Depth stands in for + The buffers are rebuilt only when the network, the routing or the day change; a selection only rebuilds the halo, + a buffer of the selected tube's own segments. Depth stands in for the 2D painting order: a later tube's casing still covers an earlier tube's colour and packets. */ // The line program's passes: a tube's layers in drawFrame()'s order, and plain lines (coasts, waves, cables). const LP={halo:0,casing:1,colour:2,dots:3,plain:4}; @@ -58,29 +59,37 @@ void main(){float d=length(vLoc),out_=clamp((vR+vLw*.5-d)*uDpr+.5,0.,1.);if(out_ float inn=clamp((vR-vLw*.5-d)*uDpr+.5,0.,1.);vec3 c=mix(vec3(30./255.,38./255.,64./255.),vec3(1.),inn);o=vec4(c*out_,out_);}`; /* The tubes as instance data: their segments (see LINE_STRIDE; later tubes are nearer), their packets (first point, points, length, packets | which, base width, depth, -), and every tube's points in the texture. */ -function glBuild(LG,GM,looks,selId){const gl=GLX.gl,N=LG.length;let ns=0,np=0,nk=0; +const glDepth=(gi,N)=>1-(gi+1)/(N+2); +function glBuild(LG,GM,looks){const gl=GLX.gl,N=LG.length;let ns=0,np=0,nk=0; for(let gi=0;gix.id===selId);if(hot)sel=true;const fl=(hot?LINE_SEL:0)|(L.df&&!L.bld&&!L.dark?LINE_FIBER:0),p0=pi; + let si=0,ki=0,pi=0; + for(let gi=0;gix.id===selId))continue;const L=looks[gi],{pts,cum,len}=GM[gi],dep=glDepth(gi,N),col=glColor(L.col); + for(let j=0;j+1v!==GLX.key[i])){glBuild(ML.LG,ML.GM,ML.looks,selId);GLX.key=key;} + const selId=UI.sel&&UI.sel.type==='link'?UI.sel.id:'',net=GLX.key[0]!==ML; + if(net)glBuild(ML.LG,ML.GM,ML.looks); + if(net||GLX.key[1]!==selId){glHalo(ML.LG,ML.GM,ML.looks,selId);GLX.key=[ML,selId];} gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);gl.enable(gl.DEPTH_TEST);gl.depthFunc(gl.LEQUAL);gl.depthMask(true); - const L=GLX.line,K=GLX.pk,wm=sc*(far?0.5:1),lines=(pass)=>{gl.useProgram(L.p);gl.bindVertexArray(GLX.lv.v);gl.uniform1f(L.u.uBusy,busy?1:0);gl.uniform1i(L.u.uPass,pass); - for(const k of ks){glSet(gl,L,k,wm);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,GLX.nSeg);}}; + const L=GLX.line,K=GLX.pk,wm=sc*(far?0.5:1),lines=(pass,v=GLX.lv.v,n=GLX.nSeg)=>{gl.useProgram(L.p);gl.bindVertexArray(v);gl.uniform1f(L.u.uBusy,busy?1:0);gl.uniform1i(L.u.uPass,pass); + for(const k of ks){glSet(gl,L,k,wm);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,n);}}; if(GLX.nSeg)for(const pass of [LP.casing,LP.colour,LP.dots])lines(pass); if(GLX.nPk){gl.useProgram(K.p);gl.bindVertexArray(GLX.pv.v);gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,GLX.tex);gl.uniform1i(K.u.uPts,0); gl.uniform1f(K.u.uT,now/1000);gl.uniform1f(K.u.uFar,far?1:0);for(const k of ks){glSet(gl,K,k,wm);gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,GLX.nPk);}} // The selection's halo goes over earlier tubes but under its own line and later ones, as in 2D. - if(GLX.sel&&GLX.nSeg){gl.depthFunc(gl.LESS);gl.depthMask(false);lines(LP.halo);gl.depthMask(true);} + if(GLX.nHalo){gl.depthFunc(gl.LESS);gl.depthMask(false);lines(LP.halo,GLX.hv.v,GLX.nHalo);gl.depthMask(true);} gl.bindVertexArray(null);} diff --git a/src/game/96-map/59-gl-sprites.js b/src/game/96-map/59-gl-sprites.js index ff44065..87eeee6 100644 --- a/src/game/96-map/59-gl-sprites.js +++ b/src/game/96-map/59-gl-sprites.js @@ -36,21 +36,22 @@ function spriteEntry(key,w,h,ax,ay,paint){key=DPR+'|'+key;let e=SPRS.get(key);if e={cv,w,h,ax,ay,up:false,u0:0,v0:0,u1:1,v1:1};SPRS.set(key,e);return e;} // Puts a picture 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)return false; - const pw=e.cv.width,ph=e.cv.height,A=GLS.size;if(pw>A||ph>A)return false; + try{return glsPut(gl,e);}catch(x){throw glErr(x);}} +function glsPut(gl,e){const pw=e.cv.width,ph=e.cv.height,A=GLS.size;if(pw>A||ph>A)return false; if(GLS.shx+pw>A){GLS.shx=0;GLS.shy+=GLS.shh;GLS.shh=0;} if(GLS.shy+ph>A){spritesReset();return false;} const x=GLS.shx,y=GLS.shy;GLS.shx+=pw;GLS.shh=Math.max(GLS.shh,ph); gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,GLS.tex);gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,true); gl.texSubImage2D(gl.TEXTURE_2D,0,x,y,gl.RGBA,gl.UNSIGNED_BYTE,e.cv);gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false); Object.assign(e,{up:true,u0:x/A,v0:y/A,u1:(x+pw)/A,v1:(y+ph)/A});return true;} -// The next record in GLS.data, which grows as needed. +// The next record in GLS.data, which grows as needed: take it before reading GLS.data, which it may replace. function glsNext(){if((GLS.n+1)*SPR_STRIDE>GLS.data.length){const nd=new Float32Array(GLS.data.length*2);nd.set(GLS.data);GLS.data=nd;}return GLS.n++*SPR_STRIDE;} // Draws a picture at (x,y) of w×h CSS px, on the card for a frame drawn there, else with the 2D canvas. -function blit(e,x,y,w,h){if(GLS.frame&&glsEnsure(e)){const d=GLS.data,o=glsNext(); +function blit(e,x,y,w,h){if(GLS.frame&&glsEnsure(e)){const o=glsNext(),d=GLS.data; d[o]=x;d[o+1]=y;d[o+2]=w;d[o+3]=h;d[o+4]=e.u0;d[o+5]=e.v0;d[o+6]=e.u1;d[o+7]=e.v1;d[o+8]=d[o+9]=d[o+10]=0;d[o+11]=ctx.globalAlpha;d[o+12]=0;} else ctx.drawImage(e.cv,x,y,w,h);} // A round dot of radius r at (x,y), in colour col (CSS colour string) at opacity a, on the card or the 2D canvas. -function dot(x,y,r,col,a){if(GLS.frame){const c=glColor(col),d=GLS.data,o=glsNext(); +function dot(x,y,r,col,a){if(GLS.frame){const c=glColor(col),o=glsNext(),d=GLS.data; d[o]=x;d[o+1]=y;d[o+2]=r;d[o+3]=d[o+4]=d[o+5]=d[o+6]=d[o+7]=0;d[o+8]=c[0];d[o+9]=c[1];d[o+10]=c[2];d[o+11]=(a===undefined?ctx.globalAlpha:a)*c[3];d[o+12]=1;} else{const sa=ctx.globalAlpha;if(a!==undefined)ctx.globalAlpha=a;ctx.fillStyle=col;ctx.beginPath();ctx.arc(x,y,r,0,7);ctx.fill();ctx.globalAlpha=sa;}} // A small picture w×h px at scale k with its anchor at (ax,ay), painted once by paint(g) with the origin on the anchor @@ -65,12 +66,13 @@ function textStamp(t,font,px,tw,fill,stroke,lw,x,y){const W=Math.ceil(tw+lw+4),H if(lw){g.lineWidth=lw;g.lineJoin='round';g.strokeStyle=stroke;g.strokeText(t,0,0);}g.fillStyle=fill;g.fillText(t,0,0);}); blit(e,Math.round((x-e.w/2)*DPR)/DPR,Math.round((y-e.h/2)*DPR)/DPR,e.w,e.h);} // Sends the queued pictures to the card in one draw. -function glsDrawNow(){const gl=GLX.gl;if(!gl||!GLS.prog||!GLS.n){GLS.n=0;return;} - gl.useProgram(GLS.prog.p);gl.bindVertexArray(GLS.vao);gl.bindBuffer(gl.ARRAY_BUFFER,GLS.buf); - gl.bufferData(gl.ARRAY_BUFFER,GLS.data.subarray(0,GLS.n*SPR_STRIDE),gl.STREAM_DRAW); +function glsDrawNow(){const gl=GLX.gl,n=GLS.n;GLS.n=0;if(!gl||!GLS.prog||!n)return; + try{glsDraw(gl,n);}catch(x){throw glErr(x);}} +function glsDraw(gl,n){gl.useProgram(GLS.prog.p);gl.bindVertexArray(GLS.vao);gl.bindBuffer(gl.ARRAY_BUFFER,GLS.buf); + gl.bufferData(gl.ARRAY_BUFFER,GLS.data.subarray(0,n*SPR_STRIDE),gl.STREAM_DRAW); gl.uniform2f(GLS.prog.u.uDev,GLX.c.width,GLX.c.height);gl.uniform1f(GLS.prog.u.uDpr,DPR);gl.uniform1i(GLS.prog.u.uTex,0); gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,GLS.tex); gl.enable(gl.BLEND);gl.blendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA);gl.disable(gl.DEPTH_TEST); - gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,GLS.n);gl.bindVertexArray(null);GLS.n=0;} -// The end of a frame on the card: the pictures go up over the tubes. -function glsFrameEnd(){if(GLS.frame){glsDrawNow();GLS.frame=false;}} + gl.drawArraysInstanced(gl.TRIANGLE_STRIP,0,4,n);gl.bindVertexArray(null);} +// The end of a frame on the card: the pictures go up over the tubes. The frame is over even if that draw fails. +function glsFrameEnd(){if(!GLS.frame)return;GLS.frame=false;glsDrawNow();} diff --git a/src/game/96-map/60-draw.js b/src/game/96-map/60-draw.js index 321fff0..f42754e 100644 --- a/src/game/96-map/60-draw.js +++ b/src/game/96-map/60-draw.js @@ -1,4 +1,9 @@ -function draw(now){DFC=new Map();try{drawFrame(now);}finally{DFC=null;glsFrameEnd();ctx=CTX0;}} +/* A frame. An error from the card itself (glErr()) gives WebGL up for this session and draws the same frame again in + 2D, once; any other error goes on to the loop's tickErr(). Either way the 2D context and the sprite queue are reset. */ +function draw(now){for(let pass=0;;pass++){let err=null;DFC=new Map(); + try{drawFrame(now);}catch(e){err=e;} + try{glsFrameEnd();}catch(e){if(!err)err=e;}finally{DFC=null;GLS.frame=false;GLS.n=0;ctx=CTX0;} + if(!err)return;if(!err.glErr||pass)throw err;glKill(err);}} // Rectangles on a 64 px grid: a new one is compared only with the few that share its cells (a plain list made the // label placement quadratic in the number of cities). class RGrid{constructor(){this.m=new Map();} @@ -7,10 +12,11 @@ class RGrid{constructor(){this.m=new Map();} hits(r){let h=false;this.cells(r,k=>{if(h)return;const a=this.m.get(k);if(a)for(const q of a)if(r.x