The game plays exactly as before; only what holds the page changes. * mapStill() tells three cases apart: still (drawn once a second), ambient (only the animation clock moved: drawn at most every 29 ms, so 30 fps on 60 and 120 Hz screens) and moving (camera, pointer, selection, network: every frame). The animations follow the clock, so they keep their speed. * save() skips the storage write when the text is the one the slot already holds (SLOT.txt) and no write is on its way; leaving the page still writes. A big autosave that moved on is packed, turned into text, stamped and compressed in the route worker (rwSave(), rwGzip()); the page only writes what comes back. A lost worker hands its pending saves back to the page (rwSaveBack(), rwGzBack()). * Less crosses back from the worker: R.efg stays there while R is its own last answer (RW.wR, efg 0), R.egDesc comes as 0 or as the entries that changed (rwDescOut()/rwDescIn()), what crossed each link travels as typed arrays decoded on demand (rwLOut()/rwLIn()), and the full ports (hotMap) come along with R. Every message is read in order (rwMsg()), so both sides always hold the same last answer. * Idle frames build the diverse-paths map and the latency floors a millisecond at a time (diversityWarm(), latWarm()), before the first offer asks. * Diagnostic info shows how fast days really come: speed asked, speed held, how long a day takes (15-day-pace.js). * perf-bench: "The NOC intern's shift: opsDay()" and, in Chromium, "One game day in play: page time only", a day played with the real route worker counting only the time it holds the page. Tests: frame-pacing, day-pace, save-size, persist, route-worker (efg as typed arrays, hotMap from the worker), day-steps (a second page plays the worker: answers without R.egDesc, with only its changes, posts without R.efg, renewal haggles answered through the worker), intern-dark-fiber-worker, webgl-zoom-sprites, speed.
35 lines
2.1 KiB
JavaScript
35 lines
2.1 KiB
JavaScript
// How fast days really come with the route worker (src/game/88-days/15-day-pace.js), for Settings › Diagnostic info:
|
||
// the speed asked, the speed held from the starts of the last days, how long a day takes and the slowest. Measured
|
||
// only: the clock starts days as it always did.
|
||
const test = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const { load } = require('./harness');
|
||
|
||
test('Diagnostic info says the speed asked, the speed held and how long a day takes', () => {
|
||
const { ev, errors } = load();
|
||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();closeModal();UI.speed=8;");
|
||
assert.equal(ev('diagPace()'), 'days: x8 asked · measuring');
|
||
// A day every 400 ms (x8 asks one every 312.5), each taking 300 ms, one of them 700.
|
||
ev('for(let i=0;i<14;i++){const t=1000+i*400;paceStart(t);paceEnd(t+(i===10?700:300));}');
|
||
assert.equal(ev('diagPace()'), 'days: x8 asked · x6.3 held (one every 400 ms) · a day takes 333 ms, slowest 700');
|
||
// Another speed: the measure starts again.
|
||
ev('UI.speed=4;');
|
||
assert.equal(ev('diagPace()'), 'days: x4 asked · measuring');
|
||
ev('paceStart(9000);paceStart(9625);paceStart(10250);');
|
||
assert.match(ev('diagPace()'), /^days: x4 asked · x4\.0 held \(one every 625 ms\)/);
|
||
ev('UI.speed=0;');
|
||
assert.equal(ev('diagPace()'), 'days: paused');
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
|
||
test('the clock with the worker feeds the measure and starts days as it always did', () => {
|
||
const { ev, errors } = load();
|
||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();closeModal();autoPause=()=>false;UI.speed=8;");
|
||
// A stand-in worker day that ends at once: one day per 312.5 ms of clock, as before.
|
||
ev(`window.__n=0;rwOn=()=>true;RW.w={postMessage(){},terminate(){}};rwDay=()=>{__n++;S.day++;rwDayDone();};
|
||
for(let i=0;i<600;i++)runClock(1000/60);`);
|
||
assert.equal(ev('__n'), Math.floor(600 * 1000 / 60 / 312.5), 'one day per 312.5 ms of clock');
|
||
assert.equal(ev('PACE.st.length'), 13, 'the last days are measured');
|
||
assert.match(ev('diagPace()'), /^days: x8 asked · x\d+\.\d held/);
|
||
assert.deepEqual(errors, []);
|
||
});
|