Rest the map while the dashboard covers a phone screen
On a phone the NOC dashboard, scrolled past its top edge, fills the whole screen, but the map underneath was still drawn every frame: about 4 ms per frame on a big network on a fast PC, several times that on a phone. While a panel covers the map completely it is no longer drawn, and it comes back as soon as any of it shows. At the top of the dashboard the strip of map above the card keeps moving, and on desktop, where the map shows around the dashboard, nothing changes. No payday floaters are made while the map is hidden, so they cannot pile up out of sight.
This commit is contained in:
parent
e026836169
commit
47c7c19402
3 changed files with 34 additions and 3 deletions
|
|
@ -9,7 +9,7 @@ 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. 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.
|
||||
- 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. On a phone, the map also rests while the NOC dashboard fills the screen, so scrolling it stays smooth.
|
||||
- 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
|
||||
|
|
|
|||
|
|
@ -3824,7 +3824,7 @@ const CLOUDS=Array.from({length:7},(_,i)=>({x:R1()*W,y:60+R1()*(H-120),s:.7+R1()
|
|||
const FLOATS=[];
|
||||
// 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});}
|
||||
function floater(x,y,text,col){if(!animOn()||UI.mapHid)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)));}
|
||||
|
|
@ -4191,8 +4191,12 @@ function frame(now){
|
|||
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 */
|
||||
const t=animOn()?animT:0;
|
||||
if(!mapStill(t,now)){try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;}
|
||||
if(!(UI.mapHid=mapHidden())&&!mapStill(t,now)){try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;}
|
||||
}
|
||||
/* On a phone the NOC dashboard (or the bank), scrolled past its top edge, covers the whole map. Drawing the map
|
||||
under it is work nobody sees, so it waits until the map shows again (and no payday money piles up meanwhile). */
|
||||
function mapHidden(){for(const id of ['dashCard','bankCard']){const c=$(id);if(c.parentNode.hidden)continue;
|
||||
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. */
|
||||
|
|
|
|||
|
|
@ -190,3 +190,30 @@ test('payday money floaters fade after a long pause instead of piling up', () =>
|
|||
assert.equal(ev('FLOATS.length'), 0, 'and it fades within two seconds of play');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the map is not drawn while the dashboard covers the whole screen', () => {
|
||||
const { ev, errors } = load();
|
||||
bigNet(ev);
|
||||
ev("closeModal();ACT.animSet({v:'on'});setPref('pauseFurious',false);setPref('pauseIncident',false);window.__clk=5000;performance.now=()=>__clk;last=__clk;UI.speed=1");
|
||||
const frame = () => { const a = ev('ctx.calls.n'); ev('__clk+=16;frame(__clk)'); return ev('ctx.calls.n') - a; };
|
||||
// jsdom has no layout, so the card says where it is: on a phone, scrolled down, it fills the screen
|
||||
const at = (top) => ev(`$('dashCard').getBoundingClientRect=()=>({top:${top},left:0,right:innerWidth,bottom:innerHeight+900})`);
|
||||
for (let t = 0; t < 2000; t += 16) frame();
|
||||
assert.equal(ev('FLOATS.length'), 0, 'floaters from building the network have faded');
|
||||
assert.ok(frame() > 0, 'the running map is drawn every frame');
|
||||
ev('ACT.connOpen()'); at(-40);
|
||||
assert.equal(frame(), 0, 'nothing is drawn under the dashboard');
|
||||
ev('while(S.day%30!==29)dayTick();acc=DAY_MS');
|
||||
for (let i = 0; i < 100; i++) assert.equal(frame(), 0);
|
||||
assert.equal(ev('S.day%30'), 0, 'the game kept running');
|
||||
assert.equal(ev('FLOATS.length'), 0, 'and payday money does not pile up out of sight');
|
||||
at(6);
|
||||
assert.ok(frame() > 0, 'back at the top, the strip of map above the card is drawn again');
|
||||
at(-40); frame();
|
||||
ev("$('dashCard').getBoundingClientRect=()=>({top:60,left:120,right:900,bottom:700})");
|
||||
assert.ok(frame() > 0, 'a dashboard with the map around it (desktop) does not stop it');
|
||||
at(-40); frame();
|
||||
ev('ACT.dashClose()');
|
||||
assert.ok(frame() > 0, 'closing the dashboard draws the map again');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue