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.

perf(ecs): batch builtin component inspection through the core

yhhdd40fde20bd9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 225cc6b5d..3ba5c1762 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Runtime inspection batches builtin membership across the core boundary.** Generated web and native bindings report an entity's current builtin component names in one call. The SDK merges script and extension components, refreshes extension bindings on registration or reconnect, and falls back to individual checks on older cores. Entity destruction, id reuse and separate registries retain their live membership semantics.
+
- **Runtime inspection avoids duplicate builtin component checks.** Entity component enumeration checks cached builtin bindings once and reads the shared builtin catalogue instead of allocating a merged builtin/script map for every entity. Live tree snapshots retain uncached membership checks and immediately reflect component additions and removals.
- **Unused transient streams no longer reserve GPU buffers.** Renderer pools initialize pipeline layouts without reserving vertex/index buffers or CPU staging for every stream. Each stream allocates storage on its first non-empty write, preserving buffer reuse, growth and recovery while avoiding unused particle, shape and sky allocations in 2D scenes.
diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.md
index 97ff4064a..a58d44537 100644
--- a/sdk/etc/wasm.api.md
+++ b/sdk/etc/wasm.api.md
@@ -69,6 +69,7 @@ entityCount: () => number
getBitmapText: (entity: Entity) => BitmapText
getBoxCollider2D: (entity: Entity) => BoxCollider2D
getBoxCollider3D: (entity: Entity) => BoxCollider3D
+getBuiltinComponentNames: ((entity: Entity) => string) | undefined
getCamera: (entity: Entity) => Camera
getCanvas: (entity: Entity) => Canvas
getCapsuleCollider2D: (entity: Entity) => CapsuleCollider2D
diff --git a/sdk/src/ecs/bridge/BuiltinBridge.ts b/sdk/src/ecs/bridge/BuiltinBridge.ts
index 8cc58d3fe..a5300ca1a 100644
--- a/sdk/src/ecs/bridge/BuiltinBridge.ts
+++ b/sdk/src/ecs/bridge/BuiltinBridge.ts
@@ -455,6 +455,7 @@ export class BuiltinBridge {
private transformComposition_: TransformComposition | null = null;
private memory_: MemoryProvider | null = null;
private builtinMethodCache_ = new Map<string, BuiltinMethods>();
+ private extraMethodCache_ = new Map<string, BuiltinMethods>();
private builtinEntitySets_ = new Map<string, Set<Entity>>();
/**
@@ -493,6 +494,7 @@ export class BuiltinBridge {
this.memory_ = options.memory
?? (module ? new WasmMemoryProvider(module, cppRegistry) : null);
this.builtinMethodCache_.clear();
+ this.extraMethodCache_.clear();
this.builtinEntitySets_.clear();
// Install the terminal-abort guard so a C++ abort flips the module-dead
@@ -513,6 +515,7 @@ export class BuiltinBridge {
this.module_ = null;
this.memory_ = null;
this.builtinMethodCache_.clear();
+ this.extraMethodCache_.clear();
throw new Error(formatBridgeDiagnostic(verification));
}
}
@@ -524,6 +527,7 @@ export class BuiltinBridge {
this.transformComposition_ = null;
this.transformEpochWord_ = -1;
this.builtinMethodCache_.clear();
+ this.extraMethodCache_.clear();
this.builtinEntitySets_.clear();
}
@@ -753,9 +757,32 @@ export class BuiltinBridge {
remove: guard('remove', (removeFn as (e: Entity) => void).bind(reg)),
};
this.builtinMethodCache_.set(cppName, methods);
+ if (!hasOwn(COMPONENT_META, cppName)) this.extraMethodCache_.set(cppName, methods);
return methods;
}
+ /** @internal One core call for all generated builtin memberships, when supported. */
+ componentNames(entity: Entity): string[] | null {
+ const registry = this.cppRegistry_;
+ if (!registry?.getBuiltinComponentNames) return null;
+ throwIfModuleAborted(this.module_, 'getBuiltinComponentNames');
+ try {
+ const names = registry.getBuiltinComponentNames(entity);
+ if (typeof names !== 'string') return null;
+ return names ? names.split('|') : [];
+ } catch (err) {
+ if (isModuleAborted(this.module_)) {
+ throw new WasmModuleAborted('getBuiltinComponentNames', undefined, err);
+ }
+ throw err;
+ }
+ }
+
+ /** @internal Bindings outside the generated membership query. */
+ getExtraMethodCache(): ReadonlyMap<string, BuiltinMethods> {
+ return this.extraMethodCache_;
+ }
+
getMethodCache(): Map<string, BuiltinMethods> {
return this.builtinMethodCache_;
}
diff --git a/sdk/src/ecs/bridge/nativeBindings.ts b/sdk/src/ecs/bridge/nativeBindings.ts
index 8e0385d63..6e520dc7e 100644
--- a/sdk/src/ecs/bridge/nativeBindings.ts
+++ b/sdk/src/ecs/bridge/nativeBindings.ts
@@ -219,6 +219,11 @@ export function hasRendererBindings(
return Object.values(RENDERER_BINDINGS).every((name) => typeof scope[name] === 'function');
}
+/** Optional bulk inspection; older hosts retain individual component checks. */
+export const INSPECTION_BINDINGS = {
+ getBuiltinComponentNames: 'es_getBuiltinComponentNames',
+} as const;
+
/**
* Scene queries the wasm module answers as module-level functions over the
* registry. The native registry answers them itself (see createNativeRegistry);
diff --git a/sdk/src/ecs/bridge/nativeRegistry.ts b/sdk/src/ecs/bridge/nativeRegistry.ts
index 2eb714869..766b074b3 100644
--- a/sdk/src/ecs/bridge/nativeRegistry.ts
+++ b/sdk/src/ecs/bridge/nativeRegistry.ts
@@ -17,7 +17,7 @@
import type { CppRegistry } from '../../wasm';
import type { Entity } from '../../types';
import { PTR_ACCESSORS } from './ptrAccessors.generated';
-import { REGISTRY_BINDINGS, SCENE_QUERY_BINDINGS, ACTIVITY_BINDINGS, DESTRUCTION_BINDINGS } from './nativeBindings';
+import { REGISTRY_BINDINGS, SCENE_QUERY_BINDINGS, ACTIVITY_BINDINGS, DESTRUCTION_BINDINGS, INSPECTION_BINDINGS } from './nativeBindings';
import { COMPONENT_META } from '../component.generated';
import { convertForWasm, convertFromWasm } from './BuiltinBridge';
@@ -88,6 +88,9 @@ export function createNativeRegistry(
scope: Record<string, unknown> = globalThis as unknown as Record<string, unknown>,
): CppRegistry {
const reg: Record<string, unknown> = {};
+ for (const [method, binding] of Object.entries(INSPECTION_BINDINGS)) {
+ if (typeof scope[binding] === 'function') reg[method] = (entity: Entity) => hostCall(scope, binding, [entity]);
+ }
for (const [method, binding] of Object.entries(ACTIVITY_BINDINGS)) {
if (typeof scope[binding] === 'function') reg[method] = (...args: unknown[]) => hostCall(scope, binding, args);
}
diff --git a/sdk/src/ecs/component.ts b/sdk/src/ecs/component.ts
index 63b9bc5f0..6076b7c77 100644
--- a/sdk/src/ecs/component.ts
+++ b/sdk/src/ecs/component.ts
@@ -570,9 +570,12 @@ export function isBuiltinComponent(comp: AnyComponentDef): comp is BuiltinCompon
// Global builtin (C++-backed) component types — defined once at module load and
// shared across every context. User components are per-AppContext (see above).
const builtinRegistry = new Map<string, AnyComponentDef>();
+let builtinRegistryVersion_ = 0;
+let extraBuiltinCache_: { version: number; definitions: ReadonlyMap<string, AnyComponentDef> } | null = null;
export function registerComponent(name: string, def: AnyComponentDef): void {
builtinRegistry.set(name, def);
+ builtinRegistryVersion_++;
}
/** Complete catalogue: global builtins + the current context's user components. */
@@ -587,6 +590,14 @@ export function builtinComponentRegistry(): ReadonlyMap<string, AnyComponentDef>
return builtinRegistry;
}
+/** @internal Definitions outside the generated core catalogue, refreshed on registration. */
+export function extraBuiltinComponentRegistry(): ReadonlyMap<string, AnyComponentDef> {
+ if (extraBuiltinCache_?.version === builtinRegistryVersion_) return extraBuiltinCache_.definitions;
+ const definitions = new Map([...builtinRegistry].filter(([name]) => !hasOwn(COMPONENT_META, name)));
+ extraBuiltinCache_ = { version: builtinRegistryVersion_, definitions };
+ return definitions;
+}
+
/** Just the current context's user/script components (excludes builtins). */
export function getUserComponents(): Map<string, AnyComponentDef> {
return userComponents();
diff --git a/sdk/src/ecs/world.ts b/sdk/src/ecs/world.ts
index 7b5dcb6a2..a409bdc6e 100644
--- a/sdk/src/ecs/world.ts
+++ b/sdk/src/ecs/world.ts
@@ -6,7 +6,7 @@
*/
import { Entity, entityGeneration, entityIndex, makeEntity, INVALID_ENTITY } from '../types';
-import { AnyComponentDef, ComponentDef, ComponentData, BuiltinComponentDef, isBuiltinComponent, builtinComponentRegistry, getUserComponents, getComponent, Disabled, Name, Parent, Children, type ParentData, type ChildrenData } from './component';
+import { AnyComponentDef, ComponentDef, ComponentData, BuiltinComponentDef, isBuiltinComponent, builtinComponentRegistry, extraBuiltinComponentRegistry, getUserComponents, getComponent, Disabled, Name, Parent, Children, type ParentData, type ChildrenData } from './component';
import type { CppRegistry, ESEngineModule } from '../wasm';
import { handleWasmError } from '../wasm/wasmError';
import { BuiltinBridge, builtinFromWasm, numberListFieldsOf, convertForWasm, type BridgeConnectOptions,
@@ -1086,13 +1086,14 @@ export class World {
/** The names of every component on `entity` — for inspectors and diagnostics;
* a system asks {@link has} about the definitions it knows. */
getComponentTypes(entity: Entity): string[] {
- const types = new Set<string>();
+ const names = this.builtin_.componentNames(entity);
+ const types = new Set<string>(names ?? []);
const methods = this.builtin_.getMethodCache();
- for (const [name, binding] of methods) {
+ for (const [name, binding] of names === null ? methods : this.builtin_.getExtraMethodCache()) {
try { if (binding.has(entity)) types.add(name); } catch (e) { log.warn('world', `Component check failed for ${name}`, e); }
}
if (this.builtin_.hasCpp) {
- for (const [name, comp] of builtinComponentRegistry()) {
+ for (const [name, comp] of names === null ? builtinComponentRegistry() : extraBuiltinComponentRegistry()) {
if (isBuiltinComponent(comp) && !methods.has(name)) {
try {
const m = this.builtin_.getBuiltinMethods(comp._cppName);
diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.ts
index 2c42087cb..bbc8230a1 100644
--- a/sdk/src/wasm/wasm.generated.ts
+++ b/sdk/src/wasm/wasm.generated.ts
@@ -937,6 +937,8 @@ export interface Registry {
destroy(entity: Entity): void;
valid(entity: Entity): boolean;
entityCount(): number;
+ /** All generated builtin names, separated by |; absent on older cores. */
+ getBuiltinComponentNames?(entity: Entity): string;
hasBitmapText(entity: Entity): boolean;
getBitmapText(entity: Entity): BitmapText;
diff --git a/sdk/tests/component-inspection-wasm.test.ts b/sdk/tests/component-inspection-wasm.test.ts
new file mode 100644
index 000000000..28c1245a4
--- /dev/null
+++ b/sdk/tests/component-inspection-wasm.test.ts
@@ -0,0 +1,58 @@
+import { beforeAll, describe, expect, it } from 'vitest';
+import { World } from '../src/ecs/world';
+import { Transform, Sprite, Disabled, defineComponent } from '../src/ecs/component';
+import type { ESEngineModule } from '../src/wasm';
+import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';
+
+describe.skipIf(!HAS_WASM)('bulk builtin inspection on the core', () => {
+ let module: ESEngineModule;
+ beforeAll(async () => { module = await loadWasmModule(); });
+
+ it('reflects native and script edits and preserves the legacy answer', () => {
+ const registry = new module.Registry();
+ const world = new World();
+ world.connectCpp(registry, module);
+ const script = defineComponent('BulkInspectionScript', { value: 1 });
+ const entity = world.spawn('Actor');
+ try {
+ expect(typeof registry.getBuiltinComponentNames).toBe('function');
+ world.insert(entity, Transform);
+ world.insert(entity, Sprite);
+ world.insert(entity, script);
+ world.insert(entity, Disabled);
+ const bulk = world.getComponentTypes(entity);
+ expect(bulk).toEqual(expect.arrayContaining(['Name', 'Transform', 'Sprite', 'Disabled', 'BulkInspectionScript']));
+ const read = registry.getBuiltinComponentNames!;
+ registry.getBuiltinComponentNames = undefined;
+ const legacy = world.getComponentTypes(entity);
+ registry.getBuiltinComponentNames = read;
+ expect(bulk).toEqual(legacy);
+ registry.removeSprite(entity);
+ expect(world.getComponentTypes(entity)).not.toContain('Sprite');
+ world.remove(entity, script);
+ expect(world.getComponentTypes(entity)).not.toContain('BulkInspectionScript');
+ world.despawn(entity);
+ expect(registry.getBuiltinComponentNames!(entity)).toBe('');
+ } finally { world.disconnectCpp(); registry.delete(); }
+ });
+
+ it('reads the registry it is called on, including recycled entity ids', () => {
+ const first = new module.Registry(), second = new module.Registry();
+ const a = new World(), b = new World();
+ a.connectCpp(first, module); b.connectCpp(second, module);
+ try {
+ const e = a.spawn(), other = b.spawn();
+ expect(e).toBe(other);
+ a.insert(e, Sprite);
+ b.insert(other, Transform);
+ expect(a.getComponentTypes(e)).toContain('Sprite');
+ expect(a.getComponentTypes(e)).not.toContain('Transform');
+ expect(b.getComponentTypes(other)).toContain('Transform');
+ expect(b.getComponentTypes(other)).not.toContain('Sprite');
+ a.despawn(e);
+ const next = a.spawn();
+ expect(a.getComponentTypes(next)).not.toContain('Sprite');
+ expect(first.getBuiltinComponentNames!(e)).toBe('');
+ } finally { a.disconnectCpp(); b.disconnectCpp(); first.delete(); second.delete(); }
+ });
+});
diff --git a/sdk/tests/native-registry.test.ts b/sdk/tests/native-registry.test.ts
index 46d26e63d..40c21833b 100644
--- a/sdk/tests/native-registry.test.ts
+++ b/sdk/tests/native-registry.test.ts
@@ -36,6 +36,17 @@ function mockNativeScope(byteSize = 256): Record<string, unknown> {
}
describe('createNativeRegistry', () => {
+ it('uses optional bulk membership on hosts that provide it', () => {
+ const calls: number[] = [];
+ const reg = createNativeRegistry({ es_getBuiltinComponentNames: (entity: number) => {
+ calls.push(entity);
+ return 'Name|Sprite';
+ } });
+ expect(reg.getBuiltinComponentNames!(12 as never)).toBe('Name|Sprite');
+ expect(calls).toEqual([12]);
+ expect(createNativeRegistry({}).getBuiltinComponentNames).toBeUndefined();
+ });
+
it('resolves a three-byte native component without constructing misaligned word views', () => {
const buffer = new ArrayBuffer(3);
const resolve = new NativeMemoryProvider({ es_Interactable_buffer: () => buffer })
diff --git a/sdk/tests/world.test.ts b/sdk/tests/world.test.ts
index f78bd2093..bb62b1dfe 100644
--- a/sdk/tests/world.test.ts
+++ b/sdk/tests/world.test.ts
@@ -791,6 +791,28 @@ describe('World', () => {
// =========================================================================
describe('getComponentTypes', () => {
+ it('bulk inspection keeps late builtin extensions and clears bindings on reconnect', () => {
+ const module = createMockModule();
+ const registry = module.getRegistry();
+ registry.getBuiltinComponentNames = () => '';
+ const inspected = new World();
+ inspected.connectCpp(registry, module);
+ const entity = inspected.spawn();
+ expect(inspected.getComponentTypes(entity)).toEqual([]);
+ const extension = defineBuiltin('BulkInspectionExtension', { value: 0 });
+ inspected.insert(entity, extension, { value: 3 });
+ expect(inspected.getComponentTypes(entity)).toContain('BulkInspectionExtension');
+ inspected.remove(entity, extension);
+ expect(inspected.getComponentTypes(entity)).not.toContain('BulkInspectionExtension');
+ inspected.insert(entity, extension, { value: 4 });
+ const nextModule = createMockModule();
+ const nextRegistry = nextModule.getRegistry();
+ nextRegistry.getBuiltinComponentNames = () => '';
+ inspected.disconnectCpp();
+ inspected.connectCpp(nextRegistry, nextModule);
+ expect(inspected.getComponentTypes(entity)).not.toContain('BulkInspectionExtension');
+ });
+
it('checks each known builtin once and reflects component mutations immediately', () => {
const module = createMockModule();
const registry = module.getRegistry();
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index e0e417271..e5d87eb66 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -2077,6 +2077,59 @@ EMSCRIPTEN_BINDINGS(esengine_registry) {
}))
.function("entityCount", &Registry::entityCount)
+ .function("getBuiltinComponentNames", optional_override([](Registry& r, u32 e) {
+ const auto entity = static_cast<Entity>(e);
+ std::string names;
+ if (r.has<esengine::ecs::BitmapText>(entity)) { if (!names.empty()) names += "|"; names += "BitmapText"; }
+ if (r.has<esengine::ecs::BoxCollider2D>(entity)) { if (!names.empty()) names += "|"; names += "BoxCollider2D"; }
+ if (r.has<esengine::ecs::BoxCollider3D>(entity)) { if (!names.empty()) names += "|"; names += "BoxCollider3D"; }
+ if (r.has<esengine::ecs::Camera>(entity)) { if (!names.empty()) names += "|"; names += "Camera"; }
+ if (r.has<esengine::ecs::Canvas>(entity)) { if (!names.empty()) names += "|"; names += "Canvas"; }
+ if (r.has<esengine::ecs::CapsuleCollider2D>(entity)) { if (!names.empty()) names += "|"; names += "CapsuleCollider2D"; }
+ if (r.has<esengine::ecs::CapsuleCollider3D>(entity)) { if (!names.empty()) names += "|"; names += "CapsuleCollider3D"; }
+ if (r.has<esengine::ecs::CharacterController3D>(entity)) { if (!names.empty()) names += "|"; names += "CharacterController3D"; }
+ if (r.has<esengine::ecs::Children>(entity)) { if (!names.empty()) names += "|"; names += "Children"; }
+ if (r.has<esengine::ecs::CircleCollider2D>(entity)) { if (!names.empty()) names += "|"; names += "CircleCollider2D"; }
+ if (r.has<esengine::ecs::ConvexCollider3D>(entity)) { if (!names.empty()) names += "|"; names += "ConvexCollider3D"; }
+ if (r.has<esengine::ecs::Draggable>(entity)) { if (!names.empty()) names += "|"; names += "Draggable"; }
+ if (r.has<esengine::ecs::DragonBonesAnimation>(entity)) { if (!names.empty()) names += "|"; names += "DragonBonesAnimation"; }
+ if (r.has<esengine::ecs::FlexContainer>(entity)) { if (!names.empty()) names += "|"; names += "FlexContainer"; }
+ if (r.has<esengine::ecs::Interactable>(entity)) { if (!names.empty()) names += "|"; names += "Interactable"; }
+ if (r.has<esengine::ecs::LODGroup>(entity)) { if (!names.empty()) names += "|"; names += "LODGroup"; }
+ if (r.has<esengine::ecs::Light>(entity)) { if (!names.empty()) names += "|"; names += "Light"; }
+ if (r.has<esengine::ecs::LightProbeVolume>(entity)) { if (!names.empty()) names += "|"; names += "LightProbeVolume"; }
+ if (r.has<esengine::ecs::MeshCollider3D>(entity)) { if (!names.empty()) names += "|"; names += "MeshCollider3D"; }
+ if (r.has<esengine::ecs::MeshLightmap>(entity)) { if (!names.empty()) names += "|"; names += "MeshLightmap"; }
+ if (r.has<esengine::ecs::MeshMorph>(entity)) { if (!names.empty()) names += "|"; names += "MeshMorph"; }
+ if (r.has<esengine::ecs::MeshRenderer>(entity)) { if (!names.empty()) names += "|"; names += "MeshRenderer"; }
+ if (r.has<esengine::ecs::MeshSkin>(entity)) { if (!names.empty()) names += "|"; names += "MeshSkin"; }
+ if (r.has<esengine::ecs::Occluder>(entity)) { if (!names.empty()) names += "|"; names += "Occluder"; }
+ if (r.has<esengine::ecs::Parent>(entity)) { if (!names.empty()) names += "|"; names += "Parent"; }
+ if (r.has<esengine::ecs::ParticleEmitter>(entity)) { if (!names.empty()) names += "|"; names += "ParticleEmitter"; }
+ if (r.has<esengine::ecs::ParticleForceField>(entity)) { if (!names.empty()) names += "|"; names += "ParticleForceField"; }
+ if (r.has<esengine::ecs::ReflectionProbe>(entity)) { if (!names.empty()) names += "|"; names += "ReflectionProbe"; }
+ if (r.has<esengine::ecs::RigidBody2D>(entity)) { if (!names.empty()) names += "|"; names += "RigidBody2D"; }
+ if (r.has<esengine::ecs::RigidBody3D>(entity)) { if (!names.empty()) names += "|"; names += "RigidBody3D"; }
+ if (r.has<esengine::ecs::SegmentCollider2D>(entity)) { if (!names.empty()) names += "|"; names += "SegmentCollider2D"; }
+ if (r.has<esengine::ecs::ShadowCaster2D>(entity)) { if (!names.empty()) names += "|"; names += "ShadowCaster2D"; }
+ if (r.has<esengine::ecs::ShapeRenderer>(entity)) { if (!names.empty()) names += "|"; names += "ShapeRenderer"; }
+ if (r.has<esengine::ecs::SortingGroup>(entity)) { if (!names.empty()) names += "|"; names += "SortingGroup"; }
+ if (r.has<esengine::ecs::SphereCollider3D>(entity)) { if (!names.empty()) names += "|"; names += "SphereCollider3D"; }
+ if (r.has<esengine::ecs::SpineAnimation>(entity)) { if (!names.empty()) names += "|"; names += "SpineAnimation"; }
+ if (r.has<esengine::ecs::Sprite>(entity)) { if (!names.empty()) names += "|"; names += "Sprite"; }
+ if (r.has<esengine::ecs::SpriteMask>(entity)) { if (!names.empty()) names += "|"; names += "SpriteMask"; }
+ if (r.has<esengine::ecs::TilemapLayer>(entity)) { if (!names.empty()) names += "|"; names += "TilemapLayer"; }
+ if (r.has<esengine::ecs::TrailRenderer>(entity)) { if (!names.empty()) names += "|"; names += "TrailRenderer"; }
+ if (r.has<esengine::ecs::Transform>(entity)) { if (!names.empty()) names += "|"; names += "Transform"; }
+ if (r.has<esengine::ecs::UIInteraction>(entity)) { if (!names.empty()) names += "|"; names += "UIInteraction"; }
+ if (r.has<esengine::ecs::UIMask>(entity)) { if (!names.empty()) names += "|"; names += "UIMask"; }
+ if (r.has<esengine::ecs::UINode>(entity)) { if (!names.empty()) names += "|"; names += "UINode"; }
+ if (r.has<esengine::ecs::UIScroll>(entity)) { if (!names.empty()) names += "|"; names += "UIScroll"; }
+ if (r.has<esengine::ecs::UIVisual>(entity)) { if (!names.empty()) names += "|"; names += "UIVisual"; }
+ if (r.has<esengine::ecs::Velocity>(entity)) { if (!names.empty()) names += "|"; names += "Velocity"; }
+ return names;
+ }))
+
// BitmapText
.function("hasBitmapText", optional_override([](Registry& r, u32 e) {
return r.has<esengine::ecs::BitmapText>(static_cast<Entity>(e));
diff --git a/tools/eht/generators/embind.py b/tools/eht/generators/embind.py
index 084238cce..d73211583 100644
--- a/tools/eht/generators/embind.py
+++ b/tools/eht/generators/embind.py
@@ -381,6 +381,16 @@ class EmbindGenerator:
'',
]
+ lines.extend([
+ ' .function("getBuiltinComponentNames", optional_override([](Registry& r, u32 e) {',
+ ' const auto entity = static_cast<Entity>(e);',
+ ' std::string names;',
+ ])
+ for comp in self.components:
+ full = f'{comp.namespace}::{comp.name}' if comp.namespace else comp.name
+ lines.append(f' if (r.has<{full}>(entity)) {{ if (!names.empty()) names += "|"; names += "{comp.name}"; }}')
+ lines.extend([' return names;', ' }))', ''])
+
for comp in self.components:
full = f'{comp.namespace}::{comp.name}' if comp.namespace else comp.name
name = comp.name
diff --git a/tools/eht/generators/native_bindings.py b/tools/eht/generators/native_bindings.py
index 79ae99f9b..aa4af45b2 100644
--- a/tools/eht/generators/native_bindings.py
+++ b/tools/eht/generators/native_bindings.py
@@ -239,6 +239,7 @@ class NativeBindingsGenerator:
f'#include "{self.shim_header}"',
'#include <type_traits>',
'#include <cstddef>',
+ '#include <string>',
'',
]
components = sorted(self.components, key=lambda c: c.name)
@@ -259,7 +260,22 @@ class NativeBindingsGenerator:
lines.append('')
for comp in components:
lines.extend(self._component(comp))
+ lines.extend([
+ 'static JSValue es_getBuiltinComponentNames(JSContext* ctx, JSValueConst, int argc, JSValueConst* argv) {',
+ ' if (argc < 1) return JS_UNDEFINED;',
+ ' const auto e = esn_entity(ctx, argv[0]);',
+ ' std::string names;',
+ ])
+ for comp in components:
+ full = f'{comp.namespace}::{comp.name}' if comp.namespace else comp.name
+ lines.append(f' if (esn_reg().has<{full}>(e)) {{ if (!names.empty()) names += "|"; names += "{comp.name}"; }}')
+ lines.extend([
+ ' return JS_NewStringLen(ctx, names.data(), names.size());',
+ '}', '',
+ ])
lines.append('void esn_register(JSContext* ctx, JSValue global) {')
+ lines.append(' JS_SetPropertyStr(ctx, global, "es_getBuiltinComponentNames", '
+ 'JS_NewCFunction(ctx, es_getBuiltinComponentNames, "es_getBuiltinComponentNames", 1));')
for comp in components:
setter = f'es_set_{comp.name}'
buffer = f'es_{comp.name}_buffer'
diff --git a/tools/eht/generators/typescript.py b/tools/eht/generators/typescript.py
index 55fd23aa5..cda84718e 100644
--- a/tools/eht/generators/typescript.py
+++ b/tools/eht/generators/typescript.py
@@ -96,6 +96,8 @@ class TypeScriptGenerator:
' destroy(entity: Entity): void;',
' valid(entity: Entity): boolean;',
' entityCount(): number;',
+ ' /** All generated builtin names, separated by |; absent on older cores. */',
+ ' getBuiltinComponentNames?(entity: Entity): string;',
'',
]
for comp in self.components:
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 8ee8ebe77..c2a2d7ed4 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'perf(ecs): batch builtin component inspection through the core':
+ { note: 'Runtime inspection batches builtin membership across the core boundary.' },
'perf(ecs): avoid duplicate component checks during inspection':
{ note: 'Runtime inspection avoids duplicate builtin component checks.' },
'perf(renderer): allocate transient stream storage on first use':