Show entities and time per area while playing in the Game View (#275)
A game that stutters gave no hint where the frame goes. The Game tab now has a Performance switch. It shows a small overlay in the top left corner of the Game View while a game runs: fps, the number of entities and the mean milliseconds per frame for each area, averaged over half a second like the fps counter. - src/editor/frameMeter.ts holds the pure rule. FrameMeter sums the areas per frame, closes a window every 0.5 s and formats the lines. - World.timeSystem times every system the world ticks. PlaySession maps the systems to Behaviors, Physics and Animation and sets the hook again after Load scene. - Animation has its own line. Counting the AnimationSystem under Behaviors would have skewed that number. - Drawing is the build of the game picture plus app.render(). It is main thread time only. The GPU work after it is not in the number, and app.render() draws the whole canvas including the panels. - Editor is the rest of the editor tick after the systems and the game picture: mirroring into the model, panels and console. - The overlay lets clicks through to the game. It shows dashes until the first window closes. The switch is off by default and is not saved. The released game (#266) runs without a meter. Tests: - Unit frame-meter: 9 passed. - Gate on melektaus-atx: 197 files, 2853 tests, CHECK EXIT 0. - e2e 59 on melektaus-atx: ALL PASSED, 18 checks (13 before, +5 in 59e with a real mouse on the switch). Run twice. - Three mutations were caught: the editor share not subtracting the systems (2 unit tests), systems running in pause not reported (1 unit test), the overlay getting no times (59e). - The e2e total of 1601 is computed (1596 + 5), not measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d471150efb
commit
77f4c2c1a3
13 files changed
+436
-5
No files matched your search
@@ -140,4 +140,57 @@ export async function whilePlaying(t) {
|
||||
(await json('__gm.state.project.whilePlaying')) === 'balanced' && (await undoSteps()) === steps,
|
||||
JSON.stringify({ steps: await undoSteps(), before: steps }),
|
||||
);
|
||||
|
||||
// 59e. The performance overlay (#275): switched on in the game tab's header, it shows over a
|
||||
// running game only, top left – fps, the entities the world has, and a time per area.
|
||||
const performance = () => json('__gm.gamePerformance()');
|
||||
await showTab('game');
|
||||
await click((await performance()).button.x, (await performance()).button.y);
|
||||
const waiting = await performance();
|
||||
check(
|
||||
'switched on in the header, the overlay waits for a game to run',
|
||||
waiting.button.lit && !waiting.shown,
|
||||
JSON.stringify(waiting),
|
||||
);
|
||||
await play();
|
||||
await sleep(1200);
|
||||
const running = await json(
|
||||
'({ overlay: __gm.gamePerformance(), measured: __gm.playInfo().performance, entities: __gm.world().entities.length })',
|
||||
);
|
||||
const { overlay, measured } = running;
|
||||
const times = Object.values(measured?.times ?? {});
|
||||
check(
|
||||
'while playing it shows in the top left corner of the game view',
|
||||
overlay.shown &&
|
||||
overlay.box.x - overlay.view.x >= 0 &&
|
||||
overlay.box.x - overlay.view.x < 20 &&
|
||||
overlay.box.y - overlay.view.y >= 0 &&
|
||||
overlay.box.y - overlay.view.y < 20 &&
|
||||
overlay.box.w > 100,
|
||||
JSON.stringify(overlay),
|
||||
);
|
||||
check(
|
||||
'it counts the entities the running world has',
|
||||
measured?.entities === running.entities && overlay.lines[0]?.includes(`· ${running.entities} entities`),
|
||||
JSON.stringify({ measured, entities: running.entities, line: overlay.lines[0] }),
|
||||
);
|
||||
check(
|
||||
'and shows the fps and a time for each of the five areas, drawing included',
|
||||
/^\d+ fps/.test(overlay.lines[0] ?? '') &&
|
||||
overlay.lines.length === 6 &&
|
||||
overlay.lines.slice(1).every((line) => / \d+\.\d\d ms$/.test(line)) &&
|
||||
times.length === 5 &&
|
||||
times.every((ms) => Number.isFinite(ms) && ms >= 0) &&
|
||||
measured.times.drawing > 0,
|
||||
JSON.stringify(overlay.lines),
|
||||
);
|
||||
await shot('59c-performance');
|
||||
await click(overlay.button.x, overlay.button.y);
|
||||
const switchedOff = await performance();
|
||||
await stop();
|
||||
check(
|
||||
'a second click switches it off again',
|
||||
!switchedOff.button.lit && !switchedOff.shown,
|
||||
JSON.stringify(switchedOff),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user