diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9e48f..14f47c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ All notable changes to this project are documented here. The project follows - Fiber between nearby cities bends gently again instead of looping wide around the neighbourhood, so dense regions like Toronto, Ottawa and Montreal stay readable. - Swapping router models now sells the old ones on eBuy for 30% of their price, and removing a router does too (#82). A POP takes one swap a day, so a double click no longer buys two upgrades, and optics and waves now say which port speed they need instead of naming one model. - Hamburg and Munich join the map, with the Moin-IX and the Brezn-IX. Stuttgart and Frankfurt are back where they belong on the map, with Stuttgart between Frankfurt and Zurich instead of halfway to Prague. -- Big networks no longer lag: working out each day's traffic is more than ten times faster with a hundred POPs and a thousand peering ports, so the game stops freezing every day and after every click. The map needs about a third fewer drawing steps per frame, and open panels only update what changed, which keeps them smooth and lets the traffic bars glide to their new values. The connection and customer lists in the NOC dashboard show 100 rows at a time, with a button for more. +- Big networks no longer lag: working out each day's traffic is more than ten times faster with a hundred POPs and a thousand peering ports, so the game stops freezing every day and after every click. The map needs about a third fewer drawing steps per frame, and open panels only update what changed, which keeps them smooth and lets the traffic bars glide to their new values. The connection and customer lists in the NOC dashboard show 100 rows at a time, with a button for more. While the game is paused or animations are off, the map is only redrawn when something on it changes, which saves a lot of battery on phones. +- The game no longer gets slower after a long pause. The money that floats up from your cities on payday kept piling up off-screen instead of fading, hundreds of them on a big network. ## [1.28.0] — 2026-10-25 diff --git a/site/index.html b/site/index.html index 0c05ae7..c7ddc4d 100644 --- a/site/index.html +++ b/site/index.html @@ -3822,7 +3822,9 @@ while(WAVES.length<220){const x=R1()*W,y=R1()*H;if(!onLand(x,y)&&!onLand(x+12,y) while(HILLS.length<130){const x=R1()*W,y=R1()*H;if(onLand(x,y)&&!CITIES.some(c=>Math.hypot(c.x-x,c.y-y)<40))HILLS.push([x,y,6+R1()*10,R1()]);} const CLOUDS=Array.from({length:7},(_,i)=>({x:R1()*W,y:60+R1()*(H-120),s:.7+R1()*.6,v:3+R1()*4})); const FLOATS=[]; -function floater(x,y,text,col){if(!animOn())return;FLOATS.push({x,y,text,col,t:performance.now()});} +// Stamped with the map's animation clock, which stops while paused: on the real clock, every floater born after a +// pause lingered off-screen for as long as the pause had lasted, and paydays piled up hundreds of them. +function floater(x,y,text,col){if(!animOn())return;FLOATS.push({x,y,text,col,t:animT});} // Static markup: data-i18n text and every aria-label/title go through the dictionary once at boot. function i18nDom(){if(LANG==='en')return;for(const el of document.querySelectorAll('[data-i18n]'))el.textContent=tr(el.textContent); for(const a of ['aria-label','title'])for(const el of document.querySelectorAll('['+a+']'))el.setAttribute(a,tr(el.getAttribute(a)));} @@ -4053,7 +4055,7 @@ function drawBackhoe(x,y,now,sub){ } // Label widths by text (city labels by id, link labels and far-view labels by text): measuring text every frame is slow. const LBLW={},LINKW=new Map(),LBLF=new Map(),CM={off:new Set(),big:new Set(),inc:new Set(),far:false}; -try{document.fonts&&document.fonts.ready.then(()=>{for(const k in LBLW)delete LBLW[k];LINKW.clear();LBLF.clear();});}catch(e){} +try{document.fonts&&document.fonts.ready.then(()=>{for(const k in LBLW)delete LBLW[k];LINKW.clear();LBLF.clear();FRAME.length=0;});}catch(e){} function drawCityFar(C,sx,sy,sc,now,lyOverride){ const p=S.pops[C.id],down=p&&p.down>S.day,sel=UI.sel&&UI.sel.type==='city'&&UI.sel.id===C.id,hov=UI.hover===C.id||(UI.snap&&UI.snap.id===C.id); ctx.save();ctx.translate(sx,sy);ctx.strokeStyle='#1E2640'; @@ -4183,11 +4185,22 @@ function frame(now){ const dt=Math.min(250,now-last);last=now; if(ANALYTICS.host&&S&&!S.lost&&UI.speed&&document.visibilityState==='visible'){UI.playMs=(UI.playMs||0)+dt;const m=UI.playMs/60000;for(const k of PLAY_MARKS)if(m>=k)track('play_'+k+'m',true);} if(S&&UI.started&&!S.lost&&now-(UI.lastSave||0)>5000)save(); + // The panels catch up on the frame after a day, so one frame does not carry both the day's simulation and them. + if(UI.panelsDue){UI.panelsDue=false;if(!pressing){renderPanel();renderLeft();if(!$('dash').hidden)renderDash();renderBank();}renderHint();} if(S&&!S.lost&&$('modal').hidden&&UI.speed){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4&&UI.speed){acc-=DAY_MS;try{dayTick();}catch(e){tickErr(e);}n++;} - if(n){UI.ticking=true;renderHUD();UI.ticking=false;if(!pressing){renderPanel();renderLeft();if(!$('dash').hidden)renderDash();renderBank();}renderHint();}} + if(n){UI.ticking=true;renderHUD();UI.ticking=false;UI.panelsDue=true;}} if(UI.speed&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */ - try{draw(animOn()?animT:0);}catch(e){tickErr(e);} + const t=animOn()?animT:0; + if(!mapStill(t,now)){try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;} } +/* 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. */ +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]; + let same=v.length===FRAME.length;for(let i=0;iSomething in the NOC glitched.
The game kept going. If things look odd, export your save and open an issue on GitHub.'),'bad');} function boot(data){ diff --git a/tests/speed.test.js b/tests/speed.test.js index 92d20cd..1666c83 100644 --- a/tests/speed.test.js +++ b/tests/speed.test.js @@ -130,3 +130,63 @@ test('long lists in the NOC dashboard show 100 rows at a time and grow on reques assert.equal(ev("document.querySelectorAll('#connSec .row').length"), 100); assert.deepEqual(errors, []); }); + +test('the map is only redrawn when something on it can have changed', () => { + const { ev, errors } = load(); + bigNet(ev); + ev("closeModal();UI.anim='on';UI.speed=0;last=100000;worldLayer(cam.z)"); + let T = 100000; + const frame = (code = '', dt = 16) => { if (code) ev(code); const a = ev('ctx.calls.n'); T += dt; ev(`frame(${T})`); return ev('ctx.calls.n') - a; }; + frame(); frame(); + assert.equal(frame(), 0, 'paused and untouched: nothing is drawn'); + assert.ok(frame('cam.x+=5') > 0, 'moving the map redraws it'); + assert.equal(frame(), 0); + assert.ok(frame("UI.hover='ams'") > 0, 'pointing at a city redraws'); + assert.ok(frame("UI.sel={type:'city',id:'fra'}") > 0, 'selecting redraws'); + assert.ok(frame('dayTick()') > 0, 'a new day redraws'); + assert.equal(frame(), 0); + assert.ok(frame('', 1100) > 0, 'and once a second anyway'); + assert.ok(frame('WL.key=null') > 0, 'the land picture catching up after a zoom or resize redraws'); + ev('UI.speed=1'); + assert.ok(frame() > 0 && frame() > 0, 'with the clock running every frame moves'); + ev("ACT.animSet({v:'off'})"); + frame(); frame(); + assert.equal(frame(), 0, 'with animations off the running map stands still between days'); + assert.deepEqual(errors, []); +}); + +test('after a day the open panels catch up on the next frame, even when every frame has a day', () => { + const { ev, errors } = load(); + bigNet(ev); + ev("closeModal();selectCity('fra');window.__rp=0;const rp0=renderPanel;renderPanel=function(){__rp++;return rp0.apply(this,arguments);}"); + ev('UI.speed=1;acc=DAY_MS;last=0;frame(16)'); + const day = ev('S.day'); + assert.equal(ev('__rp'), 0, 'the frame with the day leaves the panels for later'); + ev('frame(32)'); + assert.equal(ev('__rp'), 1, 'the next frame updates them'); + assert.equal(ev('S.day'), day); + // a day on every frame: the panels still follow, one frame behind + for (let i = 0; i < 3; i++) ev(`acc=DAY_MS;frame(${48 + 16 * i})`); + assert.equal(ev('__rp'), 3, 'each frame shows the day before it'); + ev('frame(96)'); + assert.equal(ev('__rp'), 4); + assert.deepEqual(errors, []); +}); + +test('payday money floaters fade after a long pause instead of piling up', () => { + const { ev, errors } = load(); + bigNet(ev); + // a fake clock, so a ten-minute pause takes no time; no auto-pause in the middle + ev("closeModal();ACT.animSet({v:'on'});setPref('pauseFurious',false);setPref('pauseIncident',false);window.__clk=5000;performance.now=()=>__clk;last=__clk;UI.speed=1"); + const run = (ms) => { for (let t = 0; t < ms; t += 16) ev('__clk+=16;frame(__clk)'); }; + run(2000); + assert.equal(ev('FLOATS.length'), 0, 'floaters from building the network have faded'); + ev('UI.speed=0;__clk+=600000;frame(__clk)'); + ev('while(S.day%30!==29)dayTick();UI.speed=1;acc=DAY_MS'); + run(16); + assert.equal(ev('S.day%30'), 0); + assert.ok(ev('FLOATS.length') > 0, 'payday shows the money'); + run(2000); + assert.equal(ev('FLOATS.length'), 0, 'and it fades within two seconds of play'); + assert.deepEqual(errors, []); +});