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
feat(debug): a connected build says what device it runs on
esengine28f3ab5bf195
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 33d82b358..aa7d70425 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ published separately; it ships inside the editor.### Added+- Connected development builds are named by the device they run on — `web (Chrome · Android)`, a phone's model on a mini-game — and numbered when two read alike, in the Profiler, Outliner, Frame Debugger and `device_targets`.- Profiling a connected development build, the Profiler's Frame section shows what its debug channel costs the device per frame (and `profile_frames` reports it as `channelMs`).- 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.diff --git a/desktop b/desktopindex 3f0756842..a2a1535d2 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 3f07568427e76c166c6707e8276e1f5a8694c65b+Subproject commit a2a1535d286e9bcc4e3e33b81b7352465dd61846diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 31f2246bc..ef9bb12fe 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -5739,6 +5739,7 @@ createRewardedAd: ((adUnitId: string) => PlatformRewardedAd | null) | undefinedcreateSocket: ((options: PlatformSocketOptions) => PlatformSocket) | undefinedcreateTextEditor: (() => PlatformTextEditor | null) | undefinedcreateVideoBackend: ((ctx: VideoBackendContext) => PlatformVideoBackend) | undefined+deviceName: (() => string) | undefineddevicePixelRatio: () => numberfamily: "minigame" | undefinedfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 6bc3ea798..2f8493a5c 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -5922,6 +5922,7 @@ createRewardedAd: ((adUnitId: string) => PlatformRewardedAd | null) | undefinedcreateSocket: ((options: PlatformSocketOptions) => PlatformSocket) | undefinedcreateTextEditor: (() => PlatformTextEditor | null) | undefinedcreateVideoBackend: ((ctx: VideoBackendContext) => PlatformVideoBackend) | undefined+deviceName: (() => string) | undefineddevicePixelRatio: () => numberfamily: "minigame" | undefinedfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 7e02bafe1..d66edadf3 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -5734,6 +5734,7 @@ createRewardedAd: ((adUnitId: string) => PlatformRewardedAd | null) | undefinedcreateSocket: ((options: PlatformSocketOptions) => PlatformSocket) | undefinedcreateTextEditor: (() => PlatformTextEditor | null) | undefinedcreateVideoBackend: ((ctx: VideoBackendContext) => PlatformVideoBackend) | undefined+deviceName: (() => string) | undefineddevicePixelRatio: () => numberfamily: "minigame" | undefinedfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex d0d562b74..35500ead1 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -5200,6 +5200,7 @@ createRewardedAd: (adUnitId: string) => PlatformRewardedAd | nullcreateScreenCanvas: () => MiniGameCanvascreateSocket: (options: PlatformSocketOptions) => PlatformSocketcreateVideoBackend: (ctx: VideoBackendContext) => PlatformVideoBackend+deviceName: () => stringdevicePixelRatio: () => numberfamily: "minigame"fetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>@@ -5319,6 +5320,7 @@ keys: string[]## MiniGameSystemInfo — interface @experimental```language: string | undefined+model: string | undefinedpixelRatio: number | undefinedplatform: string | undefinedwindowHeight: number | undefined@@ -6002,6 +6004,7 @@ createRewardedAd: ((adUnitId: string) => PlatformRewardedAd | null) | undefinedcreateSocket: ((options: PlatformSocketOptions) => PlatformSocket) | undefinedcreateTextEditor: (() => PlatformTextEditor | null) | undefinedcreateVideoBackend: ((ctx: VideoBackendContext) => PlatformVideoBackend) | undefined+deviceName: (() => string) | undefineddevicePixelRatio: () => numberfamily: "minigame" | undefinedfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 6b02cd75f..b2db165d6 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -5741,6 +5741,7 @@ createRewardedAd: ((adUnitId: string) => PlatformRewardedAd | null) | undefinedcreateSocket: ((options: PlatformSocketOptions) => PlatformSocket) | undefinedcreateTextEditor: (() => PlatformTextEditor | null) | undefinedcreateVideoBackend: ((ctx: VideoBackendContext) => PlatformVideoBackend) | undefined+deviceName: (() => string) | undefineddevicePixelRatio: () => numberfamily: "minigame" | undefinedfetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>diff --git a/sdk/src/platform/minigame/adapter.ts b/sdk/src/platform/minigame/adapter.tsindex e72f811ce..5751f4736 100644--- a/sdk/src/platform/minigame/adapter.ts+++ b/sdk/src/platform/minigame/adapter.ts@@ -570,6 +570,15 @@ export class MiniGamePlatformAdapter implements PlatformAdapter {}}+ deviceName(): string {+ try {+ // WeChat appends the hardware id, as in 'iPhone 13<iPhone14,5>'.+ return (this.g_.getSystemInfoSync?.()?.model ?? '').replace(/<.*>$/, '').trim();+ } catch {+ return '';+ }+ }+language(): string {try {// Hosts report 'zh_CN'-style tags; platformLanguage() normalizes underscores.diff --git a/sdk/src/platform/minigame/api.ts b/sdk/src/platform/minigame/api.tsindex 43e481593..feef0b666 100644--- a/sdk/src/platform/minigame/api.ts+++ b/sdk/src/platform/minigame/api.ts@@ -79,6 +79,7 @@ export interface MiniGameSystemInfo {* cosmetic: in-game purchase is permitted on some of these and forbidden* on others, so a capability has to read it. */platform?: string;+ model?: string;}export interface MiniGameTouch {diff --git a/sdk/src/platform/types.ts b/sdk/src/platform/types.tsindex cbba82687..e8add7462 100644--- a/sdk/src/platform/types.ts+++ b/sdk/src/platform/types.ts@@ -577,6 +577,9 @@ export interface PlatformAdapter {* 'zh_CN'-style tags — `platformLanguage()` normalizes underscores.* Optional; web falls through to navigator.language. */language?(): string;+ /** What a person would call this device when picking it from a list: a+ * phone's model, or a browser and its system. Optional. */+ deviceName?(): string;/** One rewarded ad unit. Mini-game hosts implement it over their* RewardedVideoAd; platforms without an ad system (web, native until adiff --git a/sdk/src/platform/web.ts b/sdk/src/platform/web.tsindex 2075e650e..69c68d28a 100644--- a/sdk/src/platform/web.ts+++ b/sdk/src/platform/web.ts@@ -318,6 +318,10 @@ class WebPlatformAdapter implements PlatformAdapter {return typeof window !== 'undefined' ? (window.devicePixelRatio || 1) : 1;}+ deviceName(): string {+ return typeof navigator !== 'undefined' ? browserDeviceName(navigator.userAgent) : '';+ }+/*** Both ways an error reaches the browser with nobody holding it.*@@ -380,3 +384,20 @@ class WebPlatformAdapter implements PlatformAdapter {// =============================================================================export const webAdapter = new WebPlatformAdapter();++/** A browser and the system it runs on, from its user agent. Chrome on Android+ * no longer names the phone's model there, so this is as close as a page gets. */+export function browserDeviceName(ua: string): string {+ const system = /Android/.test(ua) ? 'Android'+ : /iPhone/.test(ua) ? 'iPhone'+ : /iPad/.test(ua) ? 'iPad'+ : /Mac OS X/.test(ua) ? 'Mac'+ : /Windows/.test(ua) ? 'Windows'+ : /Linux/.test(ua) ? 'Linux' : '';+ const browser = /Electron\//.test(ua) ? 'Electron'+ : /Edg\//.test(ua) ? 'Edge'+ : /Firefox\//.test(ua) ? 'Firefox'+ : /Chrome\//.test(ua) ? 'Chrome'+ : /Safari\//.test(ua) ? 'Safari' : '';+ return [browser, system].filter(Boolean).join(' · ');+}diff --git a/sdk/src/runtime/debugChannel.ts b/sdk/src/runtime/debugChannel.tsindex 9d63898c7..6757458cf 100644--- a/sdk/src/runtime/debugChannel.ts+++ b/sdk/src/runtime/debugChannel.ts@@ -148,7 +148,7 @@ export function startDebugChannel(config: DebugChannelConfig): void {const hello = (): void => {const assets = app?.hasResource(Assets) ? app.getResource(Assets) : null;send({- t: 'hello', v: DEBUG_CHANNEL_PROTOCOL, platform: platform.name, title: '',+ t: 'hello', v: DEBUG_CHANNEL_PROTOCOL, platform: platform.name, title: platform.deviceName?.() ?? '',project: config.project ?? null, revision: assets?.getManifest()?.revision() ?? null,});};diff --git a/sdk/tests/debug-channel.test.ts b/sdk/tests/debug-channel.test.tsindex 37faff56b..4dc6c1c1a 100644--- a/sdk/tests/debug-channel.test.ts+++ b/sdk/tests/debug-channel.test.ts@@ -33,7 +33,9 @@ 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', now: () => performance.now(), createSocket: () => s.socket } as unknown as PlatformAdapter);+ setPlatform({+ name: 'web', now: () => performance.now(), createSocket: () => s.socket, deviceName: () => 'Chrome · Android',+ } as unknown as PlatformAdapter);startDebugChannel({ url: 'ws://editor:1/?token=t', project: 'Demo' });console.log('booting the engine');@@ -41,7 +43,7 @@ describe('the debug channel', () => {const logged = s.sent.filter((m) => (m as { t: string }).t === 'logs').flatMap((m) => (m as { entries: Array<{ line: string }> }).entries.map((e) => e.line));expect(logged).toContain('booting the engine');- expect(s.sent[0]).toMatchObject({ t: 'hello', project: 'Demo', revision: null });+ expect(s.sent[0]).toMatchObject({ t: 'hello', title: 'Chrome · Android', project: 'Demo', revision: null });s.receive({ t: 'query', reqId: 7, kind: 'control', paused: true });await flush();diff --git a/sdk/tests/device-name.test.ts b/sdk/tests/device-name.test.tsnew file mode 100644index 000000000..8283c915f--- /dev/null+++ b/sdk/tests/device-name.test.ts@@ -0,0 +1,38 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A connected build says what device it is on, so two of them in the+ * editor's lists are not the same line twice.+ */+import { describe, it, expect } from 'vitest';+import { browserDeviceName } from '../src/platform/web';+import { MiniGamePlatformAdapter } from '../src/platform/minigame/adapter';+import type { MiniGameGlobal, MiniGameProfile } from '../src/platform/minigame/api';++describe('a browser names itself by browser and system', () => {+ it.each([+ ['Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36', 'Chrome · Android'],+ ['Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1', 'Safari · iPhone'],+ ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36', 'Chrome · Mac'],+ ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0', 'Edge · Windows'],+ ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Estella/0.72.0 Chrome/128.0.0.0 Electron/32.0.0 Safari/537.36', 'Electron · Mac'],+ ])('%s', (ua, name) => {+ expect(browserDeviceName(ua)).toBe(name);+ });+});++describe('a mini-game names its device by the model the host reports', () => {+ const named = (model?: string) => new MiniGamePlatformAdapter({+ id: 'wechat', hostLabel: 'x',+ global: { getSystemInfoSync: () => ({ model }) } as unknown as MiniGameGlobal,+ } as MiniGameProfile).deviceName();++ it('without the hardware id WeChat appends', () => {+ expect(named('iPhone 13<iPhone14,5>')).toBe('iPhone 13');+ expect(named('V2203A')).toBe('V2203A');+ });++ it('as nothing when the host reports none', () => {+ expect(named()).toBe('');+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 4d7b4cdf2..d0223c136 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1104,4 +1104,8 @@ export const NOTED = {{ note: 'Profiling a connected development build, the Profiler\'s Frame section shows what its debug channel costs the device per frame (and `profile_frames` reports it as `channelMs`).' },'feat(profiler): a device\'s frame shows what its debug channel costs':{ note: 'Profiling a connected development build, the Profiler\'s Frame section shows what its debug channel costs the device per frame (and `profile_frames` reports it as `channelMs`).' },+ 'feat(debug): a connected build says what device it runs on':+ { note: 'Connected development builds are named by the device they run on — `web (Chrome · Android)`, a phone\'s model on a mini-game — and numbered when two read alike, in the Profiler, Outliner, Frame Debugger and `device_targets`.' },+ 'feat(debug): connected builds are named by the device they run on':+ { note: 'Connected development builds are named by the device they run on — `web (Chrome · Android)`, a phone\'s model on a mini-game — and numbered when two read alike, in the Profiler, Outliner, Frame Debugger and `device_targets`.' },};