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(subsystems): show the running game's modules while playing

esengine8f78f4804c2c
diff --git a/desktop/src/engine/PlayRealm.ts b/desktop/src/engine/PlayRealm.ts
index 753b86a5e..d4c829209 100644
--- a/desktop/src/engine/PlayRealm.ts
+++ b/desktop/src/engine/PlayRealm.ts
@@ -12,7 +12,7 @@
* touched, so there is nothing to restore.
*/
import { createStore } from 'zustand/vanilla';
-import type { SceneData, PhysicsPluginConfig } from 'esengine';
+import type { SceneData, PhysicsPluginConfig, SubsystemStatus } from 'esengine';
export interface PlayPayload {
sceneData: SceneData;
@@ -131,6 +131,18 @@ class PlayRealmImpl {
});
}
+ /** The running game's subsystem (module) health, for the editor's Modules indicator.
+ * Null if not ready. */
+ subsystems(): Promise<SubsystemStatus[] | null> {
+ if (!this.iframe?.contentWindow || !this.store.getState().ready) return Promise.resolve(null);
+ const reqId = ++this.reqSeq;
+ return new Promise((resolve) => {
+ this.pending.set(reqId, (data) => resolve((data as SubsystemStatus[]) ?? null));
+ this.post({ type: 'estella:play:query', kind: 'subsystems', reqId });
+ setTimeout(() => { if (this.pending.delete(reqId)) resolve(null); }, 2000);
+ });
+ }
+
/** Live-edit a field of a running entity (debug; reverts on Stop). */
setField(entityId: number, comp: string, key: string, value: unknown): void {
this.post({ type: 'estella:play:setField', entityId, comp, key, value });
diff --git a/desktop/src/layout/SubsystemIndicator.tsx b/desktop/src/layout/SubsystemIndicator.tsx
index 14a4a7149..77fe1e893 100644
--- a/desktop/src/layout/SubsystemIndicator.tsx
+++ b/desktop/src/layout/SubsystemIndicator.tsx
@@ -3,6 +3,7 @@
import { useSyncExternalStore, useState, useRef, useEffect } from 'react';
import type { SubsystemStatus } from 'esengine';
import { EngineHost } from '@/engine/EngineHost';
+import { PlayRealm } from '@/engine/PlayRealm';
// Status-bar indicator for engine subsystem (module) health. A single dot
// summarizes the worst state; clicking opens a popover that lists each module
@@ -30,10 +31,29 @@ function overall(list: SubsystemStatus[]): DotKind {
}
export function SubsystemIndicator() {
- const subsystems = useSyncExternalStore(
+ const editSubsystems = useSyncExternalStore(
EngineHost.subscribeSubsystems,
EngineHost.getSubsystemsSnapshot,
);
+ // While playing, the real subsystems run in the play realm (iframe) — poll those so
+ // the indicator reflects the running game, not the frozen edit App. One observability
+ // surface across both realms.
+ const play = useSyncExternalStore(PlayRealm.subscribe, PlayRealm.getSnapshot);
+ const [playSubsystems, setPlaySubsystems] = useState<SubsystemStatus[]>([]);
+ useEffect(() => {
+ if (!play.playing || !play.ready) { setPlaySubsystems([]); return; }
+ let alive = true;
+ const poll = async () => {
+ const s = await PlayRealm.subsystems();
+ if (alive && s) setPlaySubsystems(s);
+ };
+ void poll();
+ const t = setInterval(() => void poll(), 500);
+ return () => { alive = false; clearInterval(t); };
+ }, [play.playing, play.ready]);
+
+ const inPlay = play.playing && playSubsystems.length > 0;
+ const subsystems = inPlay ? playSubsystems : editSubsystems;
const [open, setOpen] = useState(false);
const wrapRef = useRef<HTMLDivElement>(null);
@@ -62,7 +82,7 @@ export function SubsystemIndicator() {
</button>
{open && (
<div className="mods-pop" role="menu">
- <h4>Engine Modules</h4>
+ <h4>Engine Modules{inPlay ? ' · Play' : ''}</h4>
{subsystems.length === 0 ? (
<div className="mods-empty">Engine not booted</div>
) : (
diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.ts
index a0b646edd..95e390525 100644
--- a/desktop/src/playHost.ts
+++ b/desktop/src/playHost.ts
@@ -269,6 +269,9 @@ window.addEventListener('message', (e: MessageEvent) => {
const phases = app ? Object.fromEntries(app.getPhaseTimings() ?? []) : {};
const systems = app ? Object.fromEntries(app.getSystemTimings() ?? []) : {};
post({ type: 'estella:play:reply', reqId: data.reqId, data: { phases, systems } });
+ } else if (data.kind === 'subsystems') {
+ // The running game's module health (for the editor's Modules indicator).
+ post({ type: 'estella:play:reply', reqId: data.reqId, data: app ? app.subsystems.getStatuses() : [] });
}
break;
case 'estella:play:setField':