A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(debug): a device reports the step of its clock with what the channel costs it
esengine973859714be5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 042331b28..d87da8969 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,7 @@ published separately; it ships inside the editor.### Fixed+- The Profiler no longer reports a connected build's debug-channel cost as 0 ms when the device's clock is too coarse to measure it — a browser that is not cross-origin isolated steps by 0.1 ms. The device reports its clock's step, the row reads "< 0.100 ms", and `profile_frames` returns it as `channelClockMs`.- An export warns when a signing key the project names (a quick game's or Android's) sits inside the project and is committed to its repository, or is not ignored and would be committed next.- Opening a project no longer holds the editor behind "Preparing play realm…" for about ten seconds: the play realm's warm-up was being cut off and the editor waited out its deadline. A project now opens in under a second, and the first Play is still warm.- An export from the Build dialog and one from `estella export` now read the project the same way. The dialog's builds keep the engine modules a project includes or excludes, which they ignored; the command line's carry the project's app id (a native package was always `com.estella.game`, so two games replaced each other on a phone), its script entry and scenes folder, its desktop channel and Steam app, and a playable's ad network.diff --git a/desktop b/desktopindex 286109b49..a8aef6fd5 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 286109b49e02655d43ecd7e4b44456b315656076+Subproject commit a8aef6fd514205089731b89fc55685832e9be7e9diff --git a/sdk/src/runtime/debugChannel.ts b/sdk/src/runtime/debugChannel.tsindex 71157d519..d51d706e1 100644--- a/sdk/src/runtime/debugChannel.ts+++ b/sdk/src/runtime/debugChannel.ts@@ -35,6 +35,18 @@ const PIXEL_CHUNK = 256 * 1024;/** @p image scaled (nearest) so its longer side is at most @p maxSide; the full* size rides along so a reader can say what it is looking at. */+/** The smallest step this platform's clock takes, sampled over about a millisecond. */+function clockResolutionMs(): number {+ let step = Infinity;+ let prev = platformNow();+ const end = prev + 1;+ for (let now = prev; now < end && step > 0.001; now = platformNow()) {+ if (now > prev) step = Math.min(step, now - prev);+ prev = now;+ }+ return Number.isFinite(step) ? step : 1;+}+export function fitWithin(image: FrameReplayImage, maxSide?: number): FrameReplayImage & { fullWidth: number; fullHeight: number } {const { width: w, height: h } = image;const scale = maxSide && maxSide > 0 ? Math.min(1, maxSide / Math.max(w, h)) : 1;@@ -86,6 +98,10 @@ export function startDebugChannel(config: DebugChannelConfig): void {// What this channel itself costs the game, so a development build's numbers can// be read net of it: the console forwarding and the answers it builds in-frame.let agentMs = 0;+ // A span shorter than the clock's step reads 0: a browser that is not+ // cross-origin isolated steps performance.now() by 0.1 ms, where the channel's+ // own work is tens of microseconds. Reported so a 0 is read as "below this".+ let clockMs = 0;const timed = <T>(work: () => T): T => {const t0 = platformNow();try { return work(); } finally { agentMs += platformNow() - t0; }@@ -145,6 +161,7 @@ export function startDebugChannel(config: DebugChannelConfig): void {if (q.kind === 'stats') {// Timings cost a little every frame, so they start when first asked for.if (!statsOn) {+ clockMs = clockResolutionMs();game.enableStats();game.onFrameEnd((dt) => { frameSum += dt; frames++; worstMs = Math.max(worstMs, dt); });statsOn = true;@@ -152,7 +169,7 @@ export function startDebugChannel(config: DebugChannelConfig): void {// The device's own frame time since the last ask: the editor's clock// runs on another machine and says nothing about this one.const report = timed(() => frameStatsReport(game));- const span = { frames, frameMs: frames > 0 ? frameSum / frames : 0, worstMs, agentMs };+ const span = { frames, frameMs: frames > 0 ? frameSum / frames : 0, worstMs, agentMs, clockMs };frameSum = 0; frames = 0; worstMs = 0; agentMs = 0;reply({ t: 'reply', reqId: q.reqId, data: { ...report, ...span } });return;diff --git a/sdk/tests/debug-channel.test.ts b/sdk/tests/debug-channel.test.tsindex ec2e57cf3..22407d5ce 100644--- a/sdk/tests/debug-channel.test.ts+++ b/sdk/tests/debug-channel.test.ts@@ -102,6 +102,33 @@ describe('a device asked about its content', () => {});});+describe('what the channel costs a device', () => {+ it('comes with the step of the device clock, so a 0 below it reads as unmeasured', async () => {+ vi.resetModules();+ const base = await import('../src/platform/base');+ const channel = await import('../src/runtime/debugChannel');+ const s = fakeSocket();+ // A browser that is not cross-origin isolated: performance.now() steps by 0.1 ms.+ const coarse = () => Math.floor(performance.now() * 10) / 10;+ base.setPlatform({ name: 'web', now: coarse, createSocket: () => s.socket } as unknown as PlatformAdapter);+ channel.startDebugChannel({ url: 'ws://editor:1/?token=t', project: 'Demo' });+ s.open();+ channel.attachDebugChannel({+ hasResource: () => false,+ enableStats: () => {},+ onFrameEnd: () => () => {},+ getPhaseTimings: () => [],+ getFrameCosts: () => null,+ wasmModule: null,+ world: { getAllEntities: () => [] },+ } as unknown as App);+ s.receive({ t: 'query', reqId: 21, kind: 'stats' });+ await flush();+ const reply = s.sent.find((m) => (m as { reqId?: number }).reqId === 21) as { data: { clockMs: number } };+ expect(reply.data.clockMs).toBeCloseTo(0.1, 5);+ });+});+describe('a device in the background', () => {it('refuses a capture at once instead of waiting for a frame it will not draw', async () => {// The channel is one per process; this device needs its own.diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex fcbdb7212..4b6ef0b9e 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1166,4 +1166,8 @@ export const NOTED = {{ note: '**Android release signing.** A Shipping APK (and App Bundle) is signed with the release key the project names under Project Settings → Android → Signing — two PEM paths, the passphrase kept in this machine\'s keychain (the command line reads `ESTELLA_ANDROID_KEY_PASSPHRASE`); Development builds keep the development key. A Shipping build without one says it will be refused by Google Play.' },'fix(export): an Android release key may be named under the home directory':{ note: '**Android release signing.** A Shipping APK (and App Bundle) is signed with the release key the project names under Project Settings → Android → Signing — two PEM paths, the passphrase kept in this machine\'s keychain (the command line reads `ESTELLA_ANDROID_KEY_PASSPHRASE`); Development builds keep the development key. A Shipping build without one says it will be refused by Google Play.' },+ 'fix(debug): a device reports the step of its clock with what the channel costs it':+ { note: 'The Profiler no longer reports a connected build\'s debug-channel cost as 0 ms when the device\'s clock is too coarse to measure it — a browser that is not cross-origin isolated steps by 0.1 ms. The device reports its clock\'s step, the row reads "< 0.100 ms", and `profile_frames` returns it as `channelClockMs`.' },+ 'fix(profiler): a channel cost below the device clock reads as below it, not as 0':+ { note: 'The Profiler no longer reports a connected build\'s debug-channel cost as 0 ms when the device\'s clock is too coarse to measure it — a browser that is not cross-origin isolated steps by 0.1 ms. The device reports its clock\'s step, the row reads "< 0.100 ms", and `profile_frames` returns it as `channelClockMs`.' },};