Skip to content

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.

feat(debug): a device answers with its world, and a question asked while it boots waits

esengine2778b9b06864
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4cc76a90c..ea571dbed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ published separately; it ships inside the editor.
### Added
+- In the Outliner, a connected development build's world can be shown instead of this editor's (read-only, with live values in Details).
- A development build connected to the editor shows its log in the Output Log (from before the editor connected, too), can be profiled in the Profiler on its own frame clock, and can be paused, stepped and frame-capped from there; the log says which project and content version connected.
- The Frame Debugger can capture and replay a frame of a development build running outside the editor — a browser or a mini-game host, on this machine or another on the network: export with the Development configuration and "Frame debugger connection", then pick the device in the panel. Native apps cannot connect yet.
diff --git a/desktop b/desktop
index a5dcf56e6..0a456f4ae 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit a5dcf56e6648327732d0ae9649cc93d43c667c6d
+Subproject commit 0a456f4ae1e50e397559be04ee966cbacb709343
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 600dc28bb..b1156648d 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 115,
"beta": 103,
- "experimental": 2119,
+ "experimental": 2126,
"deprecated": 3
},
- "total": 2337,
+ "total": 2344,
"subsystems": [
{
"id": "ecs",
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 5726b54cb..67936d68f 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 91 beta · 1505 experimental · 3 deprecated
+Symbols: 115 public · 91 beta · 1512 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2736,6 +2736,7 @@ url: string
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl)
```
@@ -7602,6 +7603,24 @@ value: number | undefined
world: World
```
+## SnapshotComponent — interface @experimental
+```
+data: Record<string, unknown>
+type: string
+```
+
+## SnapshotEntity — interface @experimental
+```
+children: number[]
+components: SnapshotComponent[]
+hidden: boolean | undefined
+hideable: boolean | undefined
+id: number
+name: string
+parent: number | null
+src: number | undefined
+```
+
## SocketReadyState — type @experimental
```
PlatformSocketReadyState
@@ -9673,6 +9692,18 @@ unloadCount: number
unloadingCells: string[]
```
+## WorldSnapshot — interface @experimental
+```
+selected: SnapshotEntity | null
+tree: { version: "1.0"; name: "live"; entities: SnapshotEntity[]; } | null
+```
+
+## WorldSnapshotOptions — interface @experimental
+```
+assetPath: ((path: string) => string | null) | undefined
+entryScene: string | undefined
+```
+
## WorldStreamHost — interface @experimental
```
discardPrepared: (name: string) => number
@@ -11129,6 +11160,11 @@ InputPlugin
InputRouter
```
+## inspectableTypes — function @experimental
+```
+(world: World, entity: number): string[]
+```
+
## installEditorGrid — function @experimental
```
(app: App): void
@@ -12509,6 +12545,11 @@ TrailPlugin
(host: App | SceneManagerState, targetScene: string, config: TransitionConfig): Promise<void>
```
+## translateAssetHandles — function @experimental
+```
+(components: readonly SnapshotComponent[], pathForHandle: (kind: string, handle: number) => string | null): SnapshotComponent[]
+```
+
## travelRatio — function @experimental
```
(source: AnimatorAvatar | null, target: AnimatorAvatar | null): number
@@ -12734,6 +12775,11 @@ Plugin
SystemDef
```
+## worldSnapshot — function @experimental
+```
+(app: App, selectedId: number | null, withTree: boolean, opts?: WorldSnapshotOptions): WorldSnapshot
+```
+
## wrapSceneSystem — function @experimental
```
(app: App, sceneName: string, system: SystemDef): SystemDef
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index e8da18b6e..b31cce202 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 96 beta · 1524 experimental · 3 deprecated
+Symbols: 115 public · 96 beta · 1531 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2744,6 +2744,7 @@ url: string
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl)
```
@@ -7795,6 +7796,24 @@ value: number | undefined
world: World
```
+## SnapshotComponent — interface @experimental
+```
+data: Record<string, unknown>
+type: string
+```
+
+## SnapshotEntity — interface @experimental
+```
+children: number[]
+components: SnapshotComponent[]
+hidden: boolean | undefined
+hideable: boolean | undefined
+id: number
+name: string
+parent: number | null
+src: number | undefined
+```
+
## SocketReadyState — type @experimental
```
PlatformSocketReadyState
@@ -9866,6 +9885,18 @@ unloadCount: number
unloadingCells: string[]
```
+## WorldSnapshot — interface @experimental
+```
+selected: SnapshotEntity | null
+tree: { version: "1.0"; name: "live"; entities: SnapshotEntity[]; } | null
+```
+
+## WorldSnapshotOptions — interface @experimental
+```
+assetPath: ((path: string) => string | null) | undefined
+entryScene: string | undefined
+```
+
## WorldStreamHost — interface @experimental
```
discardPrepared: (name: string) => number
@@ -11367,6 +11398,11 @@ InputPlugin
InputRouter
```
+## inspectableTypes — function @experimental
+```
+(world: World, entity: number): string[]
+```
+
## installEditorGrid — function @experimental
```
(app: App): void
@@ -12752,6 +12788,11 @@ TrailPlugin
(host: App | SceneManagerState, targetScene: string, config: TransitionConfig): Promise<void>
```
+## translateAssetHandles — function @experimental
+```
+(components: readonly SnapshotComponent[], pathForHandle: (kind: string, handle: number) => string | null): SnapshotComponent[]
+```
+
## travelRatio — function @experimental
```
(source: AnimatorAvatar | null, target: AnimatorAvatar | null): number
@@ -12977,6 +13018,11 @@ Plugin
SystemDef
```
+## worldSnapshot — function @experimental
+```
+(app: App, selectedId: number | null, withTree: boolean, opts?: WorldSnapshotOptions): WorldSnapshot
+```
+
## wrapSceneSystem — function @experimental
```
(app: App, sceneName: string, system: SystemDef): SystemDef
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index ee31abb43..525c17c06 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 93 beta · 1504 experimental · 3 deprecated
+Symbols: 115 public · 93 beta · 1511 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2731,6 +2731,7 @@ url: string
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl)
```
@@ -7597,6 +7598,24 @@ value: number | undefined
world: World
```
+## SnapshotComponent — interface @experimental
+```
+data: Record<string, unknown>
+type: string
+```
+
+## SnapshotEntity — interface @experimental
+```
+children: number[]
+components: SnapshotComponent[]
+hidden: boolean | undefined
+hideable: boolean | undefined
+id: number
+name: string
+parent: number | null
+src: number | undefined
+```
+
## SocketReadyState — type @experimental
```
PlatformSocketReadyState
@@ -9668,6 +9687,18 @@ unloadCount: number
unloadingCells: string[]
```
+## WorldSnapshot — interface @experimental
+```
+selected: SnapshotEntity | null
+tree: { version: "1.0"; name: "live"; entities: SnapshotEntity[]; } | null
+```
+
+## WorldSnapshotOptions — interface @experimental
+```
+assetPath: ((path: string) => string | null) | undefined
+entryScene: string | undefined
+```
+
## WorldStreamHost — interface @experimental
```
discardPrepared: (name: string) => number
@@ -11124,6 +11155,11 @@ InputPlugin
InputRouter
```
+## inspectableTypes — function @experimental
+```
+(world: World, entity: number): string[]
+```
+
## installEditorGrid — function @experimental
```
(app: App): void
@@ -12514,6 +12550,11 @@ TrailPlugin
(host: App | SceneManagerState, targetScene: string, config: TransitionConfig): Promise<void>
```
+## translateAssetHandles — function @experimental
+```
+(components: readonly SnapshotComponent[], pathForHandle: (kind: string, handle: number) => string | null): SnapshotComponent[]
+```
+
## travelRatio — function @experimental
```
(source: AnimatorAvatar | null, target: AnimatorAvatar | null): number
@@ -12739,6 +12780,11 @@ Plugin
SystemDef
```
+## worldSnapshot — function @experimental
+```
+(app: App, selectedId: number | null, withTree: boolean, opts?: WorldSnapshotOptions): WorldSnapshot
+```
+
## wrapSceneSystem — function @experimental
```
(app: App, sceneName: string, system: SystemDef): SystemDef
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index bf7144e57..1cc0527d2 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 91 beta · 1526 experimental · 3 deprecated
+Symbols: 115 public · 91 beta · 1533 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2731,6 +2731,7 @@ url: string
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl)
```
@@ -7865,6 +7866,24 @@ value: number | undefined
world: World
```
+## SnapshotComponent — interface @experimental
+```
+data: Record<string, unknown>
+type: string
+```
+
+## SnapshotEntity — interface @experimental
+```
+children: number[]
+components: SnapshotComponent[]
+hidden: boolean | undefined
+hideable: boolean | undefined
+id: number
+name: string
+parent: number | null
+src: number | undefined
+```
+
## SocketReadyState — type @experimental
```
PlatformSocketReadyState
@@ -9942,6 +9961,18 @@ unloadCount: number
unloadingCells: string[]
```
+## WorldSnapshot — interface @experimental
+```
+selected: SnapshotEntity | null
+tree: { version: "1.0"; name: "live"; entities: SnapshotEntity[]; } | null
+```
+
+## WorldSnapshotOptions — interface @experimental
+```
+assetPath: ((path: string) => string | null) | undefined
+entryScene: string | undefined
+```
+
## WorldStreamHost — interface @experimental
```
discardPrepared: (name: string) => number
@@ -11408,6 +11439,11 @@ InputPlugin
InputRouter
```
+## inspectableTypes — function @experimental
+```
+(world: World, entity: number): string[]
+```
+
## installEditorGrid — function @experimental
```
(app: App): void
@@ -12793,6 +12829,11 @@ TrailPlugin
(host: App | SceneManagerState, targetScene: string, config: TransitionConfig): Promise<void>
```
+## translateAssetHandles — function @experimental
+```
+(components: readonly SnapshotComponent[], pathForHandle: (kind: string, handle: number) => string | null): SnapshotComponent[]
+```
+
## travelRatio — function @experimental
```
(source: AnimatorAvatar | null, target: AnimatorAvatar | null): number
@@ -13018,6 +13059,11 @@ Plugin
SystemDef
```
+## worldSnapshot — function @experimental
+```
+(app: App, selectedId: number | null, withTree: boolean, opts?: WorldSnapshotOptions): WorldSnapshot
+```
+
## wrapSceneSystem — function @experimental
```
(app: App, sceneName: string, system: SystemDef): SystemDef
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 65435b662..f42e78257 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 91 beta · 1517 experimental · 3 deprecated
+Symbols: 115 public · 91 beta · 1524 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2731,6 +2731,7 @@ url: string
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl)
```
@@ -7604,6 +7605,24 @@ value: number | undefined
world: World
```
+## SnapshotComponent — interface @experimental
+```
+data: Record<string, unknown>
+type: string
+```
+
+## SnapshotEntity — interface @experimental
+```
+children: number[]
+components: SnapshotComponent[]
+hidden: boolean | undefined
+hideable: boolean | undefined
+id: number
+name: string
+parent: number | null
+src: number | undefined
+```
+
## SocketReadyState — type @experimental
```
PlatformSocketReadyState
@@ -9699,6 +9718,18 @@ unloadCount: number
unloadingCells: string[]
```
+## WorldSnapshot — interface @experimental
+```
+selected: SnapshotEntity | null
+tree: { version: "1.0"; name: "live"; entities: SnapshotEntity[]; } | null
+```
+
+## WorldSnapshotOptions — interface @experimental
+```
+assetPath: ((path: string) => string | null) | undefined
+entryScene: string | undefined
+```
+
## WorldStreamHost — interface @experimental
```
discardPrepared: (name: string) => number
@@ -11165,6 +11196,11 @@ InputPlugin
InputRouter
```
+## inspectableTypes — function @experimental
+```
+(world: World, entity: number): string[]
+```
+
## installEditorGrid — function @experimental
```
(app: App): void
@@ -12545,6 +12581,11 @@ TrailPlugin
(host: App | SceneManagerState, targetScene: string, config: TransitionConfig): Promise<void>
```
+## translateAssetHandles — function @experimental
+```
+(components: readonly SnapshotComponent[], pathForHandle: (kind: string, handle: number) => string | null): SnapshotComponent[]
+```
+
## travelRatio — function @experimental
```
(source: AnimatorAvatar | null, target: AnimatorAvatar | null): number
@@ -12775,6 +12816,11 @@ Plugin
SystemDef
```
+## worldSnapshot — function @experimental
+```
+(app: App, selectedId: number | null, withTree: boolean, opts?: WorldSnapshotOptions): WorldSnapshot
+```
+
## wrapSceneSystem — function @experimental
```
(app: App, sceneName: string, system: SystemDef): SystemDef
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index aab06c581..65061e7eb 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -446,6 +446,15 @@ export {
type PackagedAssetSourceOptions,
type PackagedGameConfig,
} from './runtime/packagedRuntime';
+export {
+ worldSnapshot,
+ inspectableTypes,
+ translateAssetHandles,
+ type WorldSnapshot,
+ type WorldSnapshotOptions,
+ type SnapshotEntity,
+ type SnapshotComponent,
+} from './runtime/worldSnapshot';
export {
startDebugChannel,
DEBUG_CHANNEL_PROTOCOL,
diff --git a/sdk/src/runtime/debugChannel.ts b/sdk/src/runtime/debugChannel.ts
index 29a4e8bf4..3ad52b358 100644
--- a/sdk/src/runtime/debugChannel.ts
+++ b/sdk/src/runtime/debugChannel.ts
@@ -18,6 +18,7 @@ import { captureFrameReport, replayFrameDraw } from '../render/frameDebugReport'
import { log } from '../util/logger';
import { Assets } from '../asset/AssetPlugin';
import { frameStatsReport } from './frameStats';
+import { worldSnapshot } from './worldSnapshot';
import { forwardConsole, type ConsoleLevel } from './consoleForward';
export const DEBUG_CHANNEL_PROTOCOL = 1;
@@ -44,6 +45,7 @@ export type DebugChannelQuery =
| { t: 'query'; reqId: number; kind: 'frameCapture' }
| { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number }
| { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
| ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl);
/**
@@ -58,6 +60,7 @@ export type DebugChannelMessage =
| { t: 'log'; level: ConsoleLevel; line: string };
const RECONNECT_MS = 3000;
+const START_WAIT_MS = 20_000;
/** Lines kept while no editor listens; the oldest go first, and how many is said. */
const LOG_BACKLOG = 200;
@@ -88,6 +91,9 @@ export function startDebugChannel(config: DebugChannelConfig): void {
}
let app: App | null = null;
let nextFrame: NextFrame | null = null;
+ // An editor may ask while the engine is still booting; the answer waits for the game.
+ let started: () => void = () => {};
+ const gameStarted = new Promise<void>((resolve) => { started = resolve; });
let socket: PlatformSocket | null = null;
let retry: ReturnType<typeof setTimeout> | null = null;
let statsOn = false;
@@ -123,10 +129,15 @@ export function startDebugChannel(config: DebugChannelConfig): void {
const answer = async (q: DebugChannelQuery): Promise<void> => {
const reply = (m: DebugChannelMessage): void => send(m);
try {
- if (!app || !nextFrame) throw new Error('the game has not started yet');
- const game = app;
+ if (!app) {
+ const late = new Promise<never>((_, reject) => setTimeout(
+ () => reject(new Error(`the game did not start within ${START_WAIT_MS / 1000}s`)), START_WAIT_MS));
+ await Promise.race([gameStarted, late]);
+ }
+ const game = app!;
+ const frame = nextFrame!;
if (q.kind === 'frameCapture') {
- reply({ t: 'reply', reqId: q.reqId, data: await captureFrameReport(game, nextFrame) });
+ reply({ t: 'reply', reqId: q.reqId, data: await captureFrameReport(game, frame) });
return;
}
if (q.kind === 'stats') {
@@ -143,6 +154,10 @@ export function startDebugChannel(config: DebugChannelConfig): void {
reply({ t: 'reply', reqId: q.reqId, data: { ...frameStatsReport(game), ...span } });
return;
}
+ if (q.kind === 'snapshot') {
+ reply({ t: 'reply', reqId: q.reqId, data: worldSnapshot(game, q.selectedId, q.withTree) });
+ return;
+ }
if (q.kind === 'control') {
if (q.fps !== undefined) game.setTargetFrameRate(q.fps);
if (q.paused !== undefined) game.setPaused(q.paused);
@@ -150,7 +165,7 @@ export function startDebugChannel(config: DebugChannelConfig): void {
reply({ t: 'reply', reqId: q.reqId, data: { paused: game.isPaused(), fps: Math.round(game.getTargetFrameRate()) } });
return;
}
- const image = await replayFrameDraw(game, q.drawIndex, nextFrame);
+ const image = await replayFrameDraw(game, q.drawIndex, frame);
if (!image) {
reply({ t: 'reply', reqId: q.reqId, data: null });
return;
@@ -193,6 +208,7 @@ export function startDebugChannel(config: DebugChannelConfig): void {
app = game;
nextFrame = appFrame(game);
hello();
+ started();
},
};
}
diff --git a/sdk/src/runtime/worldSnapshot.ts b/sdk/src/runtime/worldSnapshot.ts
new file mode 100644
index 000000000..7e8045b2d
--- /dev/null
+++ b/sdk/src/runtime/worldSnapshot.ts
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file worldSnapshot.ts
+ * @brief A running world as an inspector shows it: the shallow tree, and one
+ * entity with its values — from the editor's Play realm and from a
+ * device alike.
+ */
+import type { App } from '../app/app';
+import type { World } from '../ecs/world';
+import { getComponent } from '../ecs/component';
+import { getComponentAssetFieldDescriptors } from '../scene/scene';
+import { Assets } from '../asset/AssetPlugin';
+import { hasVisibility, isEntityVisible } from '../ecs/entityUtils';
+import { sceneOriginOf } from '../scene/sceneOrigins';
+
+/** Kept as the tree's own shape (name, parent, children) rather than as rows. */
+const STRUCTURAL = new Set(['Name', 'Parent', 'Children', 'WorldTransform']);
+
+export interface SnapshotComponent {
+ type: string;
+ data: Record<string, unknown>;
+}
+
+export interface SnapshotEntity {
+ id: number;
+ name: string;
+ parent: number | null;
+ children: number[];
+ /** Types only in the tree; values only for the entity asked for. */
+ components: SnapshotComponent[];
+ /** Whether it has something to hide, and whether it is hidden. */
+ hideable?: boolean;
+ hidden?: boolean;
+ /** The id of the document entity it was loaded from, for the entry scene's. */
+ src?: number;
+}
+
+export interface WorldSnapshot {
+ tree: { version: '1.0'; name: 'live'; entities: SnapshotEntity[] } | null;
+ selected: SnapshotEntity | null;
+}
+
+export interface WorldSnapshotOptions {
+ /** The scene whose entities carry their document id (`src`). */
+ entryScene?: string;
+ /** Turns an asset's load path into the one its reader knows it by. */
+ assetPath?: (path: string) => string | null;
+}
+
+/** The component types an inspector shows for @p entity: not the tree's own
+ * structure, and never per-frame transient state. */
+export function inspectableTypes(world: World, entity: number): string[] {
+ return world.getComponentTypes(entity as never).filter((t) => {
+ if (STRUCTURAL.has(t)) return false;
+ const def = getComponent(t);
+ return !!def && !def.transient;
+ });
+}
+
+/**
+ * Rewrite handle-valued asset fields to the load paths behind them. A World stores
+ * handles; an inspector speaks refs, and a handle shown raw reads as an empty slot.
+ * Handles nobody can name pass through untouched.
+ */
+export function translateAssetHandles(
+ components: readonly SnapshotComponent[],
+ pathForHandle: (kind: string, handle: number) => string | null,
+): SnapshotComponent[] {
+ return components.map(({ type, data }) => {
+ let out: Record<string, unknown> | null = null;
+ for (const d of getComponentAssetFieldDescriptors(type)) {
+ const v = data[d.field];
+ if (typeof v !== 'number' || v === 0) continue;
+ const path = pathForHandle(d.type, v);
+ if (path !== null) (out ??= { ...data })[d.field] = path;
+ }
+ return out ? { type, data: out } : { type, data };
+ });
+}
+
+/**
+ * @p app's world: the tree when @p withTree (O(entities), so a caller polling one
+ * entity's values skips it), and @p selectedId's values when given.
+ */
+export function worldSnapshot(
+ app: App, selectedId: number | null, withTree: boolean, opts: WorldSnapshotOptions = {},
+): WorldSnapshot {
+ const world = app.world;
+ const nameDef = getComponent('Name');
+ const parentDef = getComponent('Parent');
+ const ownerDef = getComponent('SceneOwner');
+ const all = world.getAllEntities();
+
+ const parentOf = new Map<number, number>();
+ if (parentDef) {
+ for (const e of all) {
+ const p = world.tryGet(e, parentDef) as { entity?: number } | null;
+ if (p && p.entity !== undefined) parentOf.set(e as never as number, p.entity);
+ }
+ }
+ const childrenOf = new Map<number, number[]>();
+ for (const [child, parent] of parentOf) (childrenOf.get(parent) ?? childrenOf.set(parent, []).get(parent)!).push(child);
+
+ const nameOf = (e: number): string =>
+ (nameDef ? (world.tryGet(e as never, nameDef) as { value?: string } | null)?.value : undefined) ?? `Entity_${e}`;
+ const visibilityOf = (e: number): Pick<SnapshotEntity, 'hideable' | 'hidden'> =>
+ hasVisibility(world, e as never) ? { hideable: true, hidden: !isEntityVisible(world, e as never) } : {};
+ // Only the entry scene's ids name documents an editor has open.
+ const srcOf = (e: number): number | undefined => {
+ if (opts.entryScene === undefined) return undefined;
+ const owner = ownerDef ? (world.tryGet(e as never, ownerDef) as { scene?: string } | null) : null;
+ if ((owner?.scene ?? '') !== opts.entryScene) return undefined;
+ return sceneOriginOf(app, e as never);
+ };
+ const shape = (id: number, components: SnapshotComponent[]): SnapshotEntity => {
+ const src = srcOf(id);
+ return {
+ id, name: nameOf(id), parent: parentOf.get(id) ?? null, children: childrenOf.get(id) ?? [],
+ components, ...visibilityOf(id), ...(src === undefined ? {} : { src }),
+ };
+ };
+
+ const tree = withTree
+ ? {
+ version: '1.0' as const, name: 'live' as const,
+ entities: all.map((e) => {
+ const id = e as never as number;
+ return shape(id, inspectableTypes(world, id).map((type) => ({ type, data: {} })));
+ }),
+ }
+ : null;
+
+ let selected: SnapshotEntity | null = null;
+ if (selectedId != null) {
+ const raw = inspectableTypes(world, selectedId)
+ .map((type) => {
+ const def = getComponent(type);
+ const data = def ? world.tryGet(selectedId as never, def) : null;
+ return data ? { type, data: data as Record<string, unknown> } : null;
+ })
+ .filter((c): c is SnapshotComponent => !!c);
+ const assets = app.hasResource(Assets) ? app.getResource(Assets) : null;
+ const components = translateAssetHandles(raw, (kind, handle) => {
+ const p = assets?.pathForHandle(kind, handle) ?? null;
+ return p === null ? null : (opts.assetPath ? opts.assetPath(p) : p);
+ });
+ selected = shape(selectedId, components);
+ }
+ return { tree, selected };
+}
diff --git a/sdk/tests/debug-channel.test.ts b/sdk/tests/debug-channel.test.ts
new file mode 100644
index 000000000..210d7f6d2
--- /dev/null
+++ b/sdk/tests/debug-channel.test.ts
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file A development build's channel opens before its engine does: what it
+ * printed meanwhile reaches the editor, and a question asked meanwhile is
+ * answered once the game starts rather than refused.
+ */
+import { describe, it, expect } from 'vitest';
+import { setPlatform } from '../src/platform/base';
+import type { PlatformAdapter, PlatformSocket, PlatformSocketEvents } from '../src/platform/types';
+import { startDebugChannel, attachDebugChannel } from '../src/runtime/debugChannel';
+import type { App } from '../src/app/app';
+
+function fakeSocket() {
+ const handlers: { [K in keyof PlatformSocketEvents]?: Array<(...a: PlatformSocketEvents[K]) => void> } = {};
+ const sent: unknown[] = [];
+ const socket: PlatformSocket = {
+ delivery: 'reliable-ordered',
+ readyState: 'connecting',
+ on(event, fn) { (handlers[event] ??= [] as never).push(fn as never); return () => {}; },
+ connect() {},
+ send(data) { sent.push(typeof data === 'string' ? JSON.parse(data) : data); },
+ close() {},
+ };
+ const emit = <K extends keyof PlatformSocketEvents>(event: K, ...args: PlatformSocketEvents[K]): void => {
+ for (const fn of handlers[event] ?? []) (fn as (...a: PlatformSocketEvents[K]) => void)(...args);
+ };
+ return { socket, sent, open: () => { socket.readyState = 'open'; emit('open'); }, receive: (m: unknown) => emit('message', JSON.stringify(m)) };
+}
+
+const flush = () => new Promise((r) => setTimeout(r, 0));
+
+describe('the debug channel', () => {
+ it('forwards what was printed before the editor listened, then answers a question asked before the game started', async () => {
+ const s = fakeSocket();
+ setPlatform({ name: 'web', createSocket: () => s.socket } as unknown as PlatformAdapter);
+ startDebugChannel({ url: 'ws://editor:1/?token=t', project: 'Demo' });
+ console.log('booting the engine');
+
+ s.open();
+ const logged = s.sent.filter((m) => (m as { t: string }).t === 'log').map((m) => (m as { line: string }).line);
+ expect(logged).toContain('booting the engine');
+ expect(s.sent[0]).toMatchObject({ t: 'hello', project: 'Demo', revision: null });
+
+ s.receive({ t: 'query', reqId: 7, kind: 'control', paused: true });
+ await flush();
+ expect(s.sent.some((m) => (m as { reqId?: number }).reqId === 7)).toBe(false);
+
+ let paused = false;
+ const app = {
+ hasResource: () => false,
+ onFrameEnd: () => () => {},
+ setTargetFrameRate: () => {},
+ setPaused: (p: boolean) => { paused = p; },
+ isPaused: () => paused,
+ getTargetFrameRate: () => 0,
+ } as unknown as App;
+ attachDebugChannel(app);
+ await flush();
+ expect(s.sent.find((m) => (m as { reqId?: number }).reqId === 7)).toEqual({ t: 'reply', reqId: 7, data: { paused: true, fps: 0 } });
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index fb12b5512..3ee311731 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1070,4 +1070,8 @@ export const NOTED = {
{ note: 'A development build connected to the editor shows its log in the Output Log (from before the editor connected, too), can be profiled in the Profiler on its own frame clock, and can be paused, stepped and frame-capped from there; the log says which project and content version connected.' },
'fix(app): a frame-rate cap keeps a cadence, so 30 on a 60 Hz display is 30':
{ note: 'A frame-rate cap now holds: `setTargetFrameRate(30)` on a 60 Hz display runs at 30, not 24.' },
+ 'feat(debug): a device answers with its world, and a question asked while it boots waits':
+ { note: 'In the Outliner, a connected development build\'s world can be shown instead of this editor\'s (read-only, with live values in Details).' },
+ 'feat(outliner): a connected build\'s world, shown read-only beside this editor\'s':
+ { note: 'In the Outliner, a connected development build\'s world can be shown instead of this editor\'s (read-only, with live values in Details).' },
};
diff --git a/tools/verify-remote-capture.mjs b/tools/verify-remote-capture.mjs
index 74319804d..e3742fc86 100644
--- a/tools/verify-remote-capture.mjs
+++ b/tools/verify-remote-capture.mjs
@@ -125,12 +125,25 @@ try {
check(lines.some((l) => /EstellaContext initialized/.test(l.line)),
`what the device printed before it connected reached the editor (${lines.length} line(s))`);
+ // The first ask turns timings on; they exist once the device has run a frame since,
+ // which a software-rendered runner can take a second or more to do.
await server.query(target.id, 'stats');
- await new Promise((r) => setTimeout(r, 500));
- const stats = await server.query(target.id, 'stats');
+ let stats = null;
+ for (const until = Date.now() + 10_000; Date.now() < until;) {
+ await new Promise((r) => setTimeout(r, 250));
+ stats = await server.query(target.id, 'stats');
+ if (Object.keys(stats?.phases ?? {}).length > 0) break;
+ }
check(stats?.entities > 0 && Object.keys(stats?.phases ?? {}).length > 0 && stats?.wasmBytes > 0,
`the device reported its frame: ${stats?.entities} entities, ${Object.keys(stats?.phases ?? {}).length} phase(s), ${stats?.wasmBytes} wasm bytes`);
+ const tree = (await server.query(target.id, 'snapshot', { selectedId: null, withTree: true }))?.tree;
+ const ship = tree?.entities.find((e) => e.name === 'Ship');
+ const one = ship ? (await server.query(target.id, 'snapshot', { selectedId: ship.id, withTree: false }))?.selected : null;
+ const transform = one?.components.find((c) => c.type === 'Transform');
+ check(!!ship && typeof transform?.data?.position?.x === 'number',
+ `the device's world came back: ${tree?.entities.length ?? 0} entities, Ship's Transform ${JSON.stringify(transform?.data?.position)}`);
+
const paused = await server.query(target.id, 'control', { paused: true, fps: 30 });
const stepped = await server.query(target.id, 'control', { step: 2 });
const resumed = await server.query(target.id, 'control', { paused: false, fps: 0 });