A day that reroutes no longer stops the page at x8: every routing it needs goes to the route worker
The day split of #312 on its own, from 3.0.0, without its routing core, save or map changes. On a big network at x8 the game stopped whenever a day rerouted: after a failure, an event, the NOC intern's shift or the sales desk's signing, dayPost() routed on the page. * The day is a generator (dayRun(), dayPreRun(), dayPost()): each yield is a compute() it needs. dayTick() answers them on the spot (tests, fallback); in play rwGo() posts each one to the route worker. A failure (failureRun()), a DDoS and Auto-RTBH (ddosNewsRun()), the chaos monkey's snip (mkSnipRun()), an event's cut (eventRun()), the intern's shift (opsRun()) and the sales desk (slAutoRun(), its trials answered by the worker with offerTrial()) are steps of the day. fireFailure(), opsDay() and slAutoDay() still play them in one go. * yield DAY_REST lets a long day draw a frame between two steps (half a frame, 3 to 8 ms, RW.budget). One day in flight at a time, resting or routing: the clock waits for the day, and a half day is never saved. * UI.tick is set around every step (dayStep()), so quiet notifications hold in play, not only in dayTick(). * The daily mood check works out the land islands once per pass over the customers (TERR), instead of walking every land link for each customer afraid of sharks. This fix is thesysadmindev's, from #310; here the islands are worked out again if something routed meanwhile (RW.gen), since the mood loop can now rest between customers. Same game either way: tests/day-steps.test.js plays a second page as the worker and compares each day with dayTick(), the intern on every order, failures, events, DDoS and the monkey forced. Thanks to thesysadmindev for the profiling in #310 that pointed at the reroutes, and for the sharks fix.
This commit is contained in:
parent
9d64aa0144
commit
3c45d7dca1
26 changed files with 497 additions and 127 deletions
|
|
@ -4,6 +4,9 @@ function frame(now){
|
|||
// Schedule the next frame first: one bad lookup in a day tick must not freeze the whole game.
|
||||
if(!window.__TUBES_TEST__)requestAnimationFrame(frame);
|
||||
const dt=Math.min(250,now-last);last=now;
|
||||
// A day's steps take half a frame at most before letting one through (rwGo()): 8 ms at 60 Hz, 3 ms on a 240 Hz screen,
|
||||
// where 8 ms would be two frames lost. The frame time is followed slowly, a long frame counting as two at most.
|
||||
if(dt>0){RW.fms=RW.fms?RW.fms*0.95+Math.min(dt,RW.fms*2)*0.05:dt;RW.budget=Math.min(8,Math.max(3,RW.fms/2));}
|
||||
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.
|
||||
|
|
@ -14,12 +17,16 @@ function frame(now){
|
|||
const t=animOn()?animT:0;
|
||||
if(!(UI.mapHid=mapHidden())&&!mapStill(t,now)){const d0=DIAG.on?performance.now():0;try{draw(t);}catch(e){tickErr(e);}UI.drawnAt=now;if(DIAG.on)DIAG.dms=performance.now()-d0;}
|
||||
if(DIAG.on)diagFrame(now);
|
||||
RW.lf=performance.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.
|
||||
function runClock(dt){acc+=dt*UI.speed;let n=0;
|
||||
// With the route worker one day is in flight at a time; time does not pile up behind it.
|
||||
if(rwOn()){if(!RW.w)rwStart();if(RW.job)acc=Math.min(acc,DAY_MS);else if(acc>=DAY_MS){acc=Math.min(acc-DAY_MS,DAY_MS);try{rwDay();}catch(e){tickErr(e);}}}
|
||||
// One day in flight at a time (its routing in the worker, or resting between steps): time does not pile up behind it.
|
||||
// The clock waits for the day, never the other way round: a machine that cannot keep up plays slower, it does not
|
||||
// freeze to catch up.
|
||||
if(RW.job){acc=Math.min(acc,DAY_MS);return;}
|
||||
if(rwOn()){if(!RW.w)rwStart();if(acc>=DAY_MS){acc=Math.min(acc-DAY_MS,DAY_MS);try{rwDay();}catch(e){tickErr(e);}}}
|
||||
else{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;UI.panelsDue=true;}}}
|
||||
/* On a phone the NOC dashboard (or the bank), scrolled past its top edge, covers the whole map. Drawing the map
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue