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.

refactor(aot): one door onto where a component's bytes are

yhh6ab128f4a038
diff --git a/sdk/src/ecs/aot/AotRuntime.ts b/sdk/src/ecs/aot/AotRuntime.ts
index c67b72248..fd4c8d3dc 100644
--- a/sdk/src/ecs/aot/AotRuntime.ts
+++ b/sdk/src/ecs/aot/AotRuntime.ts
@@ -4,25 +4,22 @@
* @file AotRuntime.ts
* @brief What the runner needs to call a twin instead of a closure.
*
- * @details Three things, and no more: which twins exist, where a component's and
- * a resource's bytes are, and one arena to lay a call out in.
+ * @details Three things, and no more: which twins exist, what the manifest's
+ * names mean here, and one arena to lay a call out in.
*
- * Addresses are asked for by DEFINITION and by NAME rather than
- * resolved here, because where a component lives depends on which kind
- * it is — an engine component is at an EHT offset in the C++ pools, a
- * `defineComponent` one is a row in a `ScriptPool` — and that is the
- * storage layer's knowledge, not this one's.
+ * A COMPONENT's address is deliberately absent: `AotDispatch` asks the
+ * world for a resolver once per system and calls it per row, and a
+ * second door onto the same fact is a second thing to keep true.
+ * A resource's is here because a resource has no address of its own
+ * until something mirrors it, and that something is per world.
*/
import type { AnyComponentDef } from '../component';
-import type { Entity } from '../../types';
import type { AotContext } from './AotContext';
import type { AotSystems } from './AotSystems';
/** Where the bytes are, in the memory the compiled code reads. */
export interface AotAddresses {
- /** `component`'s bytes for `entity`, or undefined when it has none. */
- componentAt(component: AnyComponentDef, entity: Entity): number | undefined;
/**
* The named resource's bytes, ready for THIS call. A resource is a host
* record with no address of its own, so an implementation mirrors it — and
diff --git a/sdk/src/ecs/aot/installAot.ts b/sdk/src/ecs/aot/installAot.ts
index 57434cf43..3c315f457 100644
--- a/sdk/src/ecs/aot/installAot.ts
+++ b/sdk/src/ecs/aot/installAot.ts
@@ -71,7 +71,7 @@ export async function installAot(opts: InstallAotOptions): Promise<AotRuntime> {
const runtime: AotRuntime = {
systems,
- addresses: worldAddresses(opts.world, new AotResources(memory, opts.resources)),
+ addresses: worldAddresses(new AotResources(memory, opts.resources)),
ctx: new AotContext(memory),
};
opts.runner.useAot(runtime);
@@ -94,15 +94,13 @@ function componentNamed(name: string): AnyComponentDef | undefined {
}
/**
- * Where things are, asked of the world. One question for both kinds of
- * component, because a system may name an engine one and a script one in the
- * same query and the runner has no business knowing which is which.
+ * What the manifest's names mean here, and where a resource's mirror is. A
+ * COMPONENT's address is not among them: `AotDispatch` takes a resolver from the
+ * world once per system rather than asking per row.
*/
-export function worldAddresses(world: World, resources: AotResources): AotAddresses {
+export function worldAddresses(resources: AotResources): AotAddresses {
return {
componentNamed,
- componentAt: (component: AnyComponentDef, entity: Entity) =>
- world.addressOfComponent(component, entity),
resourceAt: (name: string) => resources.addressOf(name),
};
}
diff --git a/sdk/tests/aot-dispatch.test.ts b/sdk/tests/aot-dispatch.test.ts
index 29691d7a0..81f168789 100644
--- a/sdk/tests/aot-dispatch.test.ts
+++ b/sdk/tests/aot-dispatch.test.ts
@@ -197,7 +197,6 @@ describe('the scheduler and its compiled twin', () => {
const addresses: AotAddresses = {
componentNamed: (name) => (name === 'Decay' ? b.Decay : undefined),
- componentAt: (comp, entity) => b.world.addressOfComponent(comp, entity),
resourceAt: () => undefined,
};
const runtime: AotRuntime = { systems, addresses, ctx: new AotContext(memory) };
@@ -250,7 +249,6 @@ describe('the scheduler and its compiled twin', () => {
systems,
addresses: {
componentNamed: (name) => (name === 'Decay' ? w.Decay : undefined),
- componentAt: (c, e) => w.world.addressOfComponent(c, e),
resourceAt: () => undefined,
},
ctx: new AotContext(memory),