@daneren2005/shared-memory-ecs 1.10.3 → 1.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/component-trigger-index.d.ts +17 -0
- package/dist/{create-system-worker-BU5CnyVh.js → create-system-worker-CkPwxmmr.js} +102 -70
- package/dist/create-system-worker-CkPwxmmr.js.map +1 -0
- package/dist/entity-compression.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +362 -267
- package/dist/index.js.map +1 -1
- package/dist/node/node-worker-adapter.d.ts +1 -1
- package/dist/node-worker-self.js +1 -2
- package/dist/node-worker-self.js.map +1 -1
- package/dist/node.js +3 -4
- package/dist/node.js.map +1 -1
- package/dist/systems/entity-worker-system.d.ts +2 -0
- package/dist/systems/workers/entity-system-worker-message.d.ts +12 -3
- package/dist/systems/workers/packed-membership.d.ts +16 -0
- package/dist/worker.js +1 -2
- package/dist/world.d.ts +23 -2
- package/package.json +9 -9
- package/dist/create-system-worker-BU5CnyVh.js.map +0 -1
|
@@ -6,6 +6,6 @@ export default class NodeWorkerAdapter {
|
|
|
6
6
|
}) => void) | null;
|
|
7
7
|
private worker;
|
|
8
8
|
constructor(url: string | URL, options?: WorkerOptions);
|
|
9
|
-
postMessage(message: unknown): void;
|
|
9
|
+
postMessage(message: unknown, transfer?: ReadonlyArray<Transferable>): void;
|
|
10
10
|
terminate(): void;
|
|
11
11
|
}
|
package/dist/node-worker-self.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parentPort as e } from "node:worker_threads";
|
|
2
|
-
|
|
2
|
+
// src/node/worker-self.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
port;
|
|
5
5
|
handler = null;
|
|
@@ -28,7 +28,6 @@ function n() {
|
|
|
28
28
|
if (!e) throw Error("installWorkerSelf must be called inside a worker thread");
|
|
29
29
|
globalThis.self = new t(e);
|
|
30
30
|
}
|
|
31
|
-
//#endregion
|
|
32
31
|
export { t as NodeWorkerSelf, n as installWorkerSelf };
|
|
33
32
|
|
|
34
33
|
//# sourceMappingURL=node-worker-self.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-worker-self.js","names":[],"sources":["../src/node/worker-self.ts"],"sourcesContent":["import { parentPort } from 'node:worker_threads';\n\n// Node counterpart to a Web Worker's global `self`. The ECS worker runtime drives its worker through the\n// browser onmessage/postMessage contract; under Node there is no `self`, so bridge that contract onto\n// parentPort. Messages that arrive before onmessage is assigned are buffered so the initial `init` handshake\n// is never dropped.\ntype MessageHandler = (event: { data: unknown }) => void;\ninterface WorkerPort {\n\ton(event: 'message', listener: (data: unknown) => void): void\n\tpostMessage(message: unknown): void\n}\n\nexport class NodeWorkerSelf {\n\tprivate handler: MessageHandler | null = null;\n\tprivate pending: Array<unknown> = [];\n\n\tconstructor(private port: WorkerPort) {\n\t\tport.on('message', data => this.deliver(data));\n\t}\n\n\tset onmessage(handler: MessageHandler | null) {\n\t\tthis.handler = handler;\n\t\tif(handler) {\n\t\t\tconst buffered = this.pending;\n\t\t\tthis.pending = [];\n\t\t\tfor(const data of buffered) {\n\t\t\t\thandler({ data });\n\t\t\t}\n\t\t}\n\t}\n\tget onmessage(): MessageHandler | null {\n\t\treturn this.handler;\n\t}\n\n\tpostMessage(message: unknown): void {\n\t\tthis.port.postMessage(message);\n\t}\n\n\tprivate deliver(data: unknown): void {\n\t\tif(this.handler) {\n\t\t\tthis.handler({ data });\n\t\t} else {\n\t\t\tthis.pending.push(data);\n\t\t}\n\t}\n}\n\n// Defines `globalThis.self` as the parentPort bridge so a bundled worker entry that calls\n// createEntitySystemWorker(self, ...) works under Node. Call once, before importing the worker module.\nexport function installWorkerSelf(): void {\n\tif(!parentPort) {\n\t\tthrow new Error('installWorkerSelf must be called inside a worker thread');\n\t}\n\t(globalThis as { self?: unknown }).self = new NodeWorkerSelf(parentPort);\n}\n"],"mappings":";;AAYA,
|
|
1
|
+
{"version":3,"file":"node-worker-self.js","names":["NodeWorkerSelf","port","data","handler","buffered","message","installWorkerSelf","parentPort"],"sources":["../src/node/worker-self.ts"],"sourcesContent":["import { parentPort } from 'node:worker_threads';\n\n// Node counterpart to a Web Worker's global `self`. The ECS worker runtime drives its worker through the\n// browser onmessage/postMessage contract; under Node there is no `self`, so bridge that contract onto\n// parentPort. Messages that arrive before onmessage is assigned are buffered so the initial `init` handshake\n// is never dropped.\ntype MessageHandler = (event: { data: unknown }) => void;\ninterface WorkerPort {\n\ton(event: 'message', listener: (data: unknown) => void): void\n\tpostMessage(message: unknown): void\n}\n\nexport class NodeWorkerSelf {\n\tprivate handler: MessageHandler | null = null;\n\tprivate pending: Array<unknown> = [];\n\n\tconstructor(private port: WorkerPort) {\n\t\tport.on('message', data => this.deliver(data));\n\t}\n\n\tset onmessage(handler: MessageHandler | null) {\n\t\tthis.handler = handler;\n\t\tif(handler) {\n\t\t\tconst buffered = this.pending;\n\t\t\tthis.pending = [];\n\t\t\tfor(const data of buffered) {\n\t\t\t\thandler({ data });\n\t\t\t}\n\t\t}\n\t}\n\tget onmessage(): MessageHandler | null {\n\t\treturn this.handler;\n\t}\n\n\tpostMessage(message: unknown): void {\n\t\tthis.port.postMessage(message);\n\t}\n\n\tprivate deliver(data: unknown): void {\n\t\tif(this.handler) {\n\t\t\tthis.handler({ data });\n\t\t} else {\n\t\t\tthis.pending.push(data);\n\t\t}\n\t}\n}\n\n// Defines `globalThis.self` as the parentPort bridge so a bundled worker entry that calls\n// createEntitySystemWorker(self, ...) works under Node. Call once, before importing the worker module.\nexport function installWorkerSelf(): void {\n\tif(!parentPort) {\n\t\tthrow new Error('installWorkerSelf must be called inside a worker thread');\n\t}\n\t(globalThis as { self?: unknown }).self = new NodeWorkerSelf(parentPort);\n}\n"],"mappings":";;AAYA,IAAaA,IAAb,MAA4B;CAIP;CAHpB,UAAyC;CACzC,UAAkC,CAAC;CAEnC,YAAY,GAA0B;EACrC,AADmB,KAAA,OAAAC,GACnBA,EAAK,GAAG,YAAW,MAAQ,KAAK,QAAQC,CAAI,CAAC;CAC9C;CAEA,IAAI,UAAU,GAAgC;EAE7C,IADA,KAAK,UAAUC,GACZA,GAAS;GACX,IAAMC,IAAW,KAAK;GACtB,KAAK,UAAU,CAAC;GAChB,KAAI,IAAMF,KAAQE,GACjB,EAAQ,EAAE,QAAK,CAAC;EAElB;CACD;CACA,IAAI,YAAmC;EACtC,OAAO,KAAK;CACb;CAEA,YAAY,GAAwB;EACnC,KAAK,KAAK,YAAYC,CAAO;CAC9B;CAEA,QAAgB,GAAqB;EACpC,AAAG,KAAK,UACP,KAAK,QAAQ,EAAE,QAAK,CAAC,IAErB,KAAK,QAAQ,KAAKH,CAAI;CAExB;AACD;AAIA,SAAgBI,IAA0B;CACzC,IAAG,CAACC,GACH,MAAU,MAAM,yDAAyD;CAE1E,WAAmC,OAAO,IAAIP,EAAeO,CAAU;AACxE"}
|
package/dist/node.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { installWorkerSelf as e } from "./node-worker-self.js";
|
|
2
2
|
import { Worker as t } from "node:worker_threads";
|
|
3
|
-
|
|
3
|
+
// src/node/node-worker-adapter.ts
|
|
4
4
|
var n = class {
|
|
5
5
|
onmessage = null;
|
|
6
6
|
worker;
|
|
7
7
|
constructor(e, n) {
|
|
8
8
|
this.worker = new t(e, n), this.worker.on("message", (e) => this.onmessage?.({ data: e }));
|
|
9
9
|
}
|
|
10
|
-
postMessage(e) {
|
|
11
|
-
this.worker.postMessage(e);
|
|
10
|
+
postMessage(e, t) {
|
|
11
|
+
this.worker.postMessage(e, t);
|
|
12
12
|
}
|
|
13
13
|
terminate() {
|
|
14
14
|
this.worker.terminate();
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
//#endregion
|
|
18
17
|
export { n as default, e as installWorkerSelf };
|
|
19
18
|
|
|
20
19
|
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":[],"sources":["../src/node/node-worker-adapter.ts"],"sourcesContent":["import { Worker as NodeWorker, type WorkerOptions } from 'node:worker_threads';\n\nexport { installWorkerSelf } from './worker-self';\n\n// Web Worker-compatible wrapper over a Node worker_threads Worker. The ECS worker runtime drives its worker\n// through the browser `worker.onmessage` / `worker.postMessage` API; Node exposes messages as EventEmitter\n// events instead, so bridge the two. Lets worker systems run on real OS threads under Node (headless sim).\nexport default class NodeWorkerAdapter {\n\tonmessage: ((event: { data: unknown }) => void) | null = null;\n\tprivate worker: NodeWorker;\n\n\tconstructor(url: string | URL, options?: WorkerOptions) {\n\t\tthis.worker = new NodeWorker(url, options);\n\t\tthis.worker.on('message', data => this.onmessage?.({ data }));\n\t}\n\n\tpostMessage(message: unknown): void {\n\t\tthis.worker.postMessage(message);\n\t}\n\n\tterminate(): void {\n\t\tvoid this.worker.terminate();\n\t}\n}\n"],"mappings":";;;AAOA,
|
|
1
|
+
{"version":3,"file":"node.js","names":["NodeWorker","NodeWorkerAdapter","Worker","url","options","message","transfer","installWorkerSelf"],"sources":["../src/node/node-worker-adapter.ts"],"sourcesContent":["import { Worker as NodeWorker, type WorkerOptions } from 'node:worker_threads';\n\nexport { installWorkerSelf } from './worker-self';\n\n// Web Worker-compatible wrapper over a Node worker_threads Worker. The ECS worker runtime drives its worker\n// through the browser `worker.onmessage` / `worker.postMessage` API; Node exposes messages as EventEmitter\n// events instead, so bridge the two. Lets worker systems run on real OS threads under Node (headless sim).\nexport default class NodeWorkerAdapter {\n\tonmessage: ((event: { data: unknown }) => void) | null = null;\n\tprivate worker: NodeWorker;\n\n\tconstructor(url: string | URL, options?: WorkerOptions) {\n\t\tthis.worker = new NodeWorker(url, options);\n\t\tthis.worker.on('message', data => this.onmessage?.({ data }));\n\t}\n\n\tpostMessage(message: unknown, transfer?: ReadonlyArray<Transferable>): void {\n\t\tthis.worker.postMessage(message, transfer as ReadonlyArray<ArrayBuffer>);\n\t}\n\n\tterminate(): void {\n\t\tvoid this.worker.terminate();\n\t}\n}\n"],"mappings":";;;AAOA,IAAqBC,IAArB,MAAuC;CACtC,YAAyD;CACzD;CAEA,YAAY,GAAmB,GAAyB;EAEvD,AADA,KAAK,SAAS,IAAID,EAAWG,GAAKC,CAAO,GACzC,KAAK,OAAO,GAAG,YAAW,MAAQ,KAAK,YAAY,EAAE,QAAK,CAAC,CAAC;CAC7D;CAEA,YAAY,GAAkB,GAA8C;EAC3E,KAAK,OAAO,YAAYC,GAASC,CAAsC;CACxE;CAEA,YAAkB;EACjB,KAAU,OAAO,UAAU;CAC5B;AACD"}
|
|
@@ -25,6 +25,7 @@ export default abstract class EntityWorkerSystem<C extends ComponentMap, T exten
|
|
|
25
25
|
[key: string]: Map<number, BaseEntity<C>>;
|
|
26
26
|
};
|
|
27
27
|
private queryDeltas;
|
|
28
|
+
private bulkMembershipPending;
|
|
28
29
|
addDataToWorld?(world: W): void;
|
|
29
30
|
constructor(world: BaseWorld<ComponentDefinitionMap, C>, options: EntityWorkerSystemConfig<C, T, W, D>);
|
|
30
31
|
private initWorker;
|
|
@@ -44,6 +45,7 @@ export default abstract class EntityWorkerSystem<C extends ComponentMap, T exten
|
|
|
44
45
|
waitForRunToComplete(): void | Promise<void>;
|
|
45
46
|
run(elapsedTime: number): void;
|
|
46
47
|
private buildQueryDelta;
|
|
48
|
+
private buildLoadDelta;
|
|
47
49
|
private buildComponents;
|
|
48
50
|
isEntityInSystem(entity: BaseEntity<C>): boolean;
|
|
49
51
|
protected matchesQuery(entity: BaseEntity<C>, query: EntityWorkerSystemQuery<C>): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MemoryHeapMemory, GrowBufferData } from '@daneren2005/shared-memory-objects/memory-heap';
|
|
2
2
|
import type { WorldSharedMemory } from '../../world';
|
|
3
|
-
import type { EntityWorkerSystemWorld, QueryDelta, WorkerComponentChange, WorkerCreatedEntity } from '../entity-worker-system';
|
|
3
|
+
import type { EntityUpdateComponents, EntityWorkerSystemWorld, QueryDelta, WorkerComponentChange, WorkerCreatedEntity } from '../entity-worker-system';
|
|
4
4
|
import type { WorkerEntityClassRegistry } from '../../entity-class';
|
|
5
5
|
interface InitMessage {
|
|
6
6
|
type: 'init';
|
|
@@ -25,9 +25,18 @@ interface LoadMessage<D = unknown> extends LoadDeltas {
|
|
|
25
25
|
addsComponents?: boolean;
|
|
26
26
|
}
|
|
27
27
|
export interface LoadDeltas {
|
|
28
|
-
entities:
|
|
28
|
+
entities: LoadQueryDelta;
|
|
29
29
|
queries: {
|
|
30
|
-
[key: string]:
|
|
30
|
+
[key: string]: LoadQueryDelta;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface LoadQueryDelta<T extends EntityUpdateComponents = EntityUpdateComponents> extends QueryDelta<T> {
|
|
34
|
+
packedAdded?: PackedEntities;
|
|
35
|
+
}
|
|
36
|
+
export interface PackedEntities {
|
|
37
|
+
entityIds: Uint32Array<ArrayBuffer>;
|
|
38
|
+
components: {
|
|
39
|
+
[name: string]: Int32Array<ArrayBuffer>;
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
interface GrowBufferMessage {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type BaseEntity from '../../entity';
|
|
2
|
+
import type { ComponentMap } from '../../component-definition';
|
|
3
|
+
import type MemoryComponent from '../../memory-component';
|
|
4
|
+
import type { EntityUpdateComponents, UpdateEntityConfigObject } from '../entity-worker-system';
|
|
5
|
+
import type { LoadQueryDelta, PackedEntities } from './entity-system-worker-message';
|
|
6
|
+
export declare function packEntities<C extends ComponentMap>(members: {
|
|
7
|
+
size: number;
|
|
8
|
+
values(): Iterable<BaseEntity<C>>;
|
|
9
|
+
}, componentNames: ReadonlyArray<keyof C>): PackedEntities;
|
|
10
|
+
export declare function getPackedTransferables(packed: PackedEntities): Array<Transferable>;
|
|
11
|
+
export declare function unpackEntities<T extends EntityUpdateComponents>(packed: PackedEntities, pools: {
|
|
12
|
+
[name: string]: MemoryComponent;
|
|
13
|
+
}): Array<UpdateEntityConfigObject<T>>;
|
|
14
|
+
export declare function expandPackedAdded(delta: LoadQueryDelta, pools: {
|
|
15
|
+
[name: string]: MemoryComponent;
|
|
16
|
+
}): void;
|
package/dist/worker.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { t as CLASS_INDEX, i as DEAD_INDEX, n as TYPE_INDEX, e as addComponentWorker, o as createEntitySystemWorker, a as createEntityWorker, c as createSystemWorker, s as killEntityWorker, r as removeComponentWorker };
|
|
1
|
+
export { c as CLASS_INDEX, l as DEAD_INDEX, d as TYPE_INDEX, a as addComponentWorker, r as createEntitySystemWorker, o as createEntityWorker, t as createSystemWorker, s as killEntityWorker, i as removeComponentWorker } from "./create-system-worker-CkPwxmmr.js";
|
package/dist/world.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { GrowBufferData } from '@daneren2005/shared-memory-objects/memory-h
|
|
|
4
4
|
import type { SharedAllocatedMemory } from '@daneren2005/shared-memory-objects/allocated-memory';
|
|
5
5
|
import type { SharedPoolMemory } from '@daneren2005/shared-memory-objects/shared-pool';
|
|
6
6
|
import MemoryComponent from './memory-component';
|
|
7
|
+
import ComponentTriggerIndex from './component-trigger-index';
|
|
7
8
|
import ConstantStringCache from './constant-string-cache';
|
|
8
9
|
import type BaseEntity from './entity';
|
|
9
10
|
import type System from './systems/system';
|
|
@@ -25,6 +26,20 @@ export interface WorldConfig<Cfg = any> {
|
|
|
25
26
|
timeScale?: number;
|
|
26
27
|
}
|
|
27
28
|
export type CompressedWorldConfig<Cfg = any> = Omit<WorldConfig<Cfg>, 'entities'> & CompressedEntities<Cfg>;
|
|
29
|
+
export type WorldLoadPhase = 'entities' | 'linking' | 'systems' | 'workers';
|
|
30
|
+
export interface WorldLoadProgress {
|
|
31
|
+
phase: WorldLoadPhase;
|
|
32
|
+
done: number;
|
|
33
|
+
total: number;
|
|
34
|
+
fraction: number;
|
|
35
|
+
}
|
|
36
|
+
export interface WorldLoadOptions {
|
|
37
|
+
sliceMs?: number;
|
|
38
|
+
yieldTo?: () => Promise<void>;
|
|
39
|
+
onProgress?: (progress: WorldLoadProgress) => void;
|
|
40
|
+
onEntitiesReady?: () => void;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
28
43
|
export interface WorldSharedMemory {
|
|
29
44
|
components: {
|
|
30
45
|
[name: string]: SharedPoolMemory;
|
|
@@ -38,6 +53,7 @@ export default class BaseWorld<R extends ComponentDefinitionMap = ComponentDefin
|
|
|
38
53
|
registry: RegisteredComponentRegistry<C> & {
|
|
39
54
|
entity: RegisteredComponentDefinition<EntityComponent>;
|
|
40
55
|
};
|
|
56
|
+
readonly componentTriggers: ComponentTriggerIndex;
|
|
41
57
|
factory: EntityFactory<C, Cfg, E>;
|
|
42
58
|
entities: Map<number, E>;
|
|
43
59
|
systems: Array<System<C>>;
|
|
@@ -49,6 +65,8 @@ export default class BaseWorld<R extends ComponentDefinitionMap = ComponentDefin
|
|
|
49
65
|
destroyed: boolean;
|
|
50
66
|
pristine: boolean;
|
|
51
67
|
isBulkLoading: boolean;
|
|
68
|
+
isLoading: boolean;
|
|
69
|
+
private activeLoad;
|
|
52
70
|
private activeFreeBuffer;
|
|
53
71
|
private nextFreeBuffer;
|
|
54
72
|
private clearing;
|
|
@@ -58,11 +76,14 @@ export default class BaseWorld<R extends ComponentDefinitionMap = ComponentDefin
|
|
|
58
76
|
addGrownBuffer(data: GrowBufferData): void;
|
|
59
77
|
private get needsSpareBuffer();
|
|
60
78
|
init(): Promise<void>;
|
|
61
|
-
private finishLoadingSystems;
|
|
62
79
|
addEntity(entity: E, created?: boolean): E;
|
|
63
80
|
loadEntity(config: Cfg, created?: boolean): E;
|
|
64
81
|
adoptEntity(descriptor: WorkerCreatedEntity): E;
|
|
65
|
-
load(config: WorldConfig<Cfg> | CompressedWorldConfig<Cfg
|
|
82
|
+
load(config: WorldConfig<Cfg> | CompressedWorldConfig<Cfg>, options?: WorldLoadOptions): Promise<void>;
|
|
83
|
+
private loadSliced;
|
|
84
|
+
private loadSteps;
|
|
85
|
+
private awaitWorkers;
|
|
86
|
+
private abortActiveLoad;
|
|
66
87
|
clear(): Promise<void>;
|
|
67
88
|
removeEntity(entity: E): void;
|
|
68
89
|
onEntityDied(entity: E): void;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@daneren2005/shared-memory-ecs",
|
|
3
3
|
"description": "A small, reusable Entity/Component/System core backed by shared memory.",
|
|
4
4
|
"author": "Scott Jackson",
|
|
5
|
-
"version": "1.10.
|
|
5
|
+
"version": "1.10.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"license": "MIT",
|
|
@@ -64,19 +64,19 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@semantic-release/git": "^11.0.1",
|
|
66
66
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
67
|
-
"@types/node": "^26.6.
|
|
68
|
-
"@vitest/web-worker": "^5.0.
|
|
67
|
+
"@types/node": "^26.6.6",
|
|
68
|
+
"@vitest/web-worker": "^5.0.5",
|
|
69
69
|
"cross-env": "^10.1.0",
|
|
70
70
|
"husky": "^9.1.7",
|
|
71
|
-
"lint-staged": "^17.
|
|
72
|
-
"oxlint": "^1.
|
|
73
|
-
"oxlint-tsgolint": "^7.0.
|
|
71
|
+
"lint-staged": "^17.6.0",
|
|
72
|
+
"oxlint": "^1.90.0",
|
|
73
|
+
"oxlint-tsgolint": "^7.0.2005",
|
|
74
74
|
"semantic-release": "^25.0.9",
|
|
75
75
|
"typescript": "^7.0.2",
|
|
76
|
-
"vite": "^8.3.
|
|
77
|
-
"vitest": "^5.0.
|
|
76
|
+
"vite": "^8.3.5",
|
|
77
|
+
"vitest": "^5.0.5"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@daneren2005/shared-memory-objects": "^1.6.
|
|
80
|
+
"@daneren2005/shared-memory-objects": "^1.6.2"
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-system-worker-BU5CnyVh.js","names":[],"sources":["../src/memory-component.ts","../src/constant-string-cache.ts","../src/systems/workers/query-membership.ts","../src/systems/workers/entity-work-batch.ts","../src/actions/build-worker-entity.ts","../src/component.ts","../src/entity-component.ts","../src/actions/kill-entity-worker.ts","../src/actions/create-entity-worker.ts","../src/actions/add-component-worker.ts","../src/actions/remove-component-worker.ts","../src/systems/workers/create-entity-system-worker.ts","../src/systems/workers/create-system-worker.ts"],"sourcesContent":["import SharedPool from '@daneren2005/shared-memory-objects/shared-pool';\nimport type { SharedPoolMemory } from '@daneren2005/shared-memory-objects/shared-pool';\nimport type MemoryHeap from '@daneren2005/shared-memory-objects/memory-heap';\nimport type { TypedArrayConstructor } from '@daneren2005/shared-memory-objects/interfaces/typed-array-constructor';\n\nexport type ComponentTypedArray = Uint32Array | Int32Array | Float32Array | Float64Array;\n\n// Backed by a SharedPool: all bookkeeping lives in the shared heap, so a worker can reconstruct a handle over\n// the same pool (pass the owner's getSharedMemory() as `memory`) and allocate/read blocks off-thread.\nexport default class MemoryComponent<T extends ComponentTypedArray = ComponentTypedArray> {\n\theap: MemoryHeap;\n\tpool: SharedPool<T>;\n\n\tconstructor(heap: MemoryHeap, type: TypedArrayConstructor<T>, dataLength: number, memory?: SharedPoolMemory) {\n\t\tthis.heap = heap;\n\t\tthis.pool = memory\n\t\t\t? new SharedPool<T>(heap, memory)\n\t\t\t: new SharedPool<T>(heap, {\n\t\t\t\ttype,\n\t\t\t\tdataLength,\n\t\t\t});\n\t}\n\n\t// Reconstructs a handle over an existing pool (from the owner's getSharedMemory()) — used in a worker, where the\n\t// pool's type/dataLength are already recorded in the heap header, so no definition is needed.\n\tstatic fromSharedMemory<T extends ComponentTypedArray = ComponentTypedArray>(heap: MemoryHeap, memory: SharedPoolMemory): MemoryComponent<T> {\n\t\treturn new MemoryComponent<T>(heap, Uint32Array as unknown as TypedArrayConstructor<T>, 1, memory);\n\t}\n\n\tgetSharedMemory(): SharedPoolMemory {\n\t\treturn this.pool.getSharedMemory();\n\t}\n\n\tget length() {\n\t\treturn this.pool.length;\n\t}\n\tget rawLength() {\n\t\treturn this.pool.bufferLength;\n\t}\n\n\tcreate(values: Array<number>): number {\n\t\treturn this.pool.push(values);\n\t}\n\n\tgetBlock(index: number): T {\n\t\treturn this.pool.at(index);\n\t}\n\tget(index: number, dataIndex: number): number {\n\t\treturn this.pool.get(index, dataIndex);\n\t}\n\tset(index: number, dataIndex: number, value: number) {\n\t\tlet array = this.pool.at(index);\n\t\tarray[dataIndex] = value;\n\t}\n\n\tdelete(index: number) {\n\t\tthis.pool.deleteIndex(index);\n\t}\n\tclear() {\n\t\tthis.pool.clear();\n\t}\n}\n","import ConstantString from '@daneren2005/shared-memory-objects/constant-string';\nimport { getPointer } from '@daneren2005/shared-memory-objects/utils/pointer';\nimport type MemoryHeap from '@daneren2005/shared-memory-objects/memory-heap';\n\n// Interns immutable strings in the heap and resolves them back from a pointer. Every distinct value is allocated\n// once as a single ConstantString shared by all users (15 \"Space Ship\" entities point at one allocation), and a\n// pointer resolves to its string through a Map hit before ever rebuilding it from memory. Both sides of the\n// worker boundary hold one: the main thread creates + interns; a worker (with a heap reconstructed from the same\n// SharedArrayBuffers) only ever resolves pointers and caches the results.\nexport default class ConstantStringCache {\n\tprivate heap: MemoryHeap;\n\t// value -> the one interned allocation. Only the creating (main) thread populates this; it owns the memory.\n\tprivate byValue = new Map<string, ConstantString>();\n\t// pointer -> value: the fast lookup every thread checks before touching memory.\n\tprivate byPointer = new Map<number, string>();\n\n\tconstructor(heap: MemoryHeap) {\n\t\tthis.heap = heap;\n\t}\n\n\t// Dedupes on value, so repeated types share a single ConstantString. Main-thread only.\n\tgetOrCreate(value: string): ConstantString {\n\t\tlet existing = this.byValue.get(value);\n\t\tif(existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst string = new ConstantString(this.heap, value);\n\t\tthis.byValue.set(value, string);\n\t\tthis.byPointer.set(string.pointer, value);\n\n\t\treturn string;\n\t}\n\n\t// pointer -> string, checking the cache before rebuilding from memory. A pointer of 0 is the empty string; a\n\t// pointer into a buffer that has not synced to this thread yet returns undefined.\n\tgetString(pointer: number): string | undefined {\n\t\tif(pointer === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\tlet cached = this.byPointer.get(pointer);\n\t\tif(cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\n\t\tconst memory = getPointer(pointer, this.heap.positionBits);\n\t\tif(this.heap.buffers[memory.bufferPosition] === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst value = new ConstantString(this.heap, memory).value;\n\t\tthis.byPointer.set(pointer, value);\n\n\t\treturn value;\n\t}\n\n\t// Frees every allocation this cache owns and empties the lookups. A worker's cache owns nothing (it only ever\n\t// resolved views), so this just drops its pointer lookups.\n\tclear() {\n\t\tthis.byValue.forEach(string => string.free());\n\t\tthis.byValue.clear();\n\t\tthis.byPointer.clear();\n\t}\n}\n","import type { EntityUpdateComponents, QueryDelta, UpdateEntityConfigObject } from '../entity-worker-system';\n\n// A query's persistent member list on the worker side, kept from each run's delta. The eid index lives across runs so\n// a delta costs only its own size: removal swaps the last member into the gap, so order is not kept across removals.\n// `entries` is the same array for the membership's whole life; update functions are handed it directly.\nexport default class QueryMembership<T extends EntityUpdateComponents> {\n\treadonly entries: Array<UpdateEntityConfigObject<T>> = [];\n\tprivate readonly indexByEid = new Map<number, number>();\n\n\t// Removals first, so a remove+add of the same eid in one delta keeps the fresh entry.\n\tapply(delta: QueryDelta<T>): void {\n\t\tfor(const entityId of delta.removed) {\n\t\t\tconst index = this.indexByEid.get(entityId);\n\t\t\tif(index === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.indexByEid.delete(entityId);\n\t\t\tconst last = this.entries.pop()!;\n\t\t\tif(index < this.entries.length) {\n\t\t\t\tthis.entries[index] = last;\n\t\t\t\tthis.indexByEid.set(last.entityId, index);\n\t\t\t}\n\t\t}\n\t\tfor(const entity of delta.added) {\n\t\t\tconst existing = this.indexByEid.get(entity.entityId);\n\t\t\tif(existing !== undefined) {\n\t\t\t\t// Upsert: a re-added entity brings fresh block views.\n\t\t\t\tthis.entries[existing] = entity;\n\t\t\t} else {\n\t\t\t\tthis.indexByEid.set(entity.entityId, this.entries.length);\n\t\t\t\tthis.entries.push(entity);\n\t\t\t}\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.entries.length = 0;\n\t\tthis.indexByEid.clear();\n\t}\n}\n","import type { EntityUpdateComponents, EntityWorkerSystemWorld, QueryDelta, UpdateEntityConfigObject } from '../entity-worker-system';\nimport type { EntityWorkBatch } from './entity-system-worker-message';\n\nexport default class EntityWorkBatchState<T extends EntityUpdateComponents, W extends EntityWorkerSystemWorld> {\n\tprivate world: W | undefined;\n\tprivate entities = new Map<number, UpdateEntityConfigObject<T>>();\n\n\tgetWorld(world: W, batch: EntityWorkBatch | undefined): W {\n\t\tif(!batch || batch.first || !this.world) {\n\t\t\tthis.world = world;\n\t\t}\n\t\treturn this.world;\n\t}\n\tgetEntities(entities: Array<UpdateEntityConfigObject<T>>, delta: QueryDelta<T>, batch: EntityWorkBatch | undefined): Array<UpdateEntityConfigObject<T>> {\n\t\tif(!batch) {\n\t\t\tthis.entities.clear();\n\t\t\treturn entities;\n\t\t}\n\t\tif(!this.entities.size) {\n\t\t\tfor(const entity of entities) {\n\t\t\t\tthis.entities.set(entity.entityId, entity);\n\t\t\t}\n\t\t}\n\t\tdelta.removed.forEach(eid => this.entities.delete(eid));\n\t\tdelta.added.forEach(entity => this.entities.set(entity.entityId, entity));\n\t\tconst selected: Array<UpdateEntityConfigObject<T>> = [];\n\t\tfor(const eid of batch.entityIds) {\n\t\t\tconst entity = this.entities.get(eid);\n\t\t\tif(entity) {\n\t\t\t\tselected.push(entity);\n\t\t\t}\n\t\t}\n\t\treturn selected;\n\t}\n\tfinish(batch: EntityWorkBatch | undefined, failed: boolean): void {\n\t\tif(!batch || batch.last || failed) {\n\t\t\tthis.world = undefined;\n\t\t}\n\t}\n\tclear(): void {\n\t\tthis.world = undefined;\n\t\tthis.entities.clear();\n\t}\n}\n","import type { WorkerAllocator, WorkerCreateEntityConfig, WorkerCreatedComponent, WorkerCreatedEntity } from '../systems/entity-worker-system';\nimport type { WorkerEntityClassRegistry } from '../entity-class';\n\n// The slice of a component definition worker-side creation needs. Both the game's ComponentDefinitionMap and the\n// world's RegisteredComponentRegistry satisfy it.\nexport interface WorkerCreatableComponent {\n\tloadProperties: Array<string>\n\tloadInFinishLoading?: boolean\n\ttoBlock(config: Record<string, unknown>): Array<number>\n}\nexport type WorkerCreateRegistry = { [name: string]: WorkerCreatableComponent };\nexport type FactoryConfigs = { [type: string]: Record<string, unknown> };\n\n// Turns a factory-style config ({ type, ...overrides }) into a WorkerCreatedEntity, off-thread: layers the type's\n// factory template under the overrides, mints an id, and allocates + writes each triggered component's block via its\n// toBlock(). The always-present `entity` component is NOT built here - the main thread builds it on adopt (interning\n// the type is main-thread-only), reading `type`/`isStatic` off this descriptor. Shared by the real worker and the\n// main-thread fallback so both behave identically.\nexport function buildWorkerEntity(\n\tconfig: WorkerCreateEntityConfig,\n\tfactoryConfigs: FactoryConfigs,\n\tregistry: WorkerCreateRegistry,\n\tallocator: WorkerAllocator,\n\tclasses?: WorkerEntityClassRegistry,\n): WorkerCreatedEntity {\n\tconst template = factoryConfigs[config.type] ?? {};\n\tif(classes && Object.prototype.hasOwnProperty.call(config, 'class')) {\n\t\tthrow new Error('Entity class comes from its type template and cannot be supplied by a worker config');\n\t}\n\tconst merged: Record<string, unknown> = { ...template, ...config };\n\tconst entityClass = typeof template.class === 'string' ? template.class : undefined;\n\tlet componentNames = Object.keys(registry);\n\tif(classes) {\n\t\tif(template.type !== config.type) {\n\t\t\tthrow new Error(`Entity template ${config.type} must declare the same type`);\n\t\t}\n\t\tconst definition = entityClass ? classes[entityClass] : undefined;\n\t\tif(!definition) {\n\t\t\tthrow new Error(`Entity type ${config.type} has unknown class ${entityClass ?? ''}`);\n\t\t}\n\t\tcomponentNames = definition.components;\n\t}\n\n\tconst eid = allocator.allocateEid();\n\tconst components: { [name: string]: number } = {};\n\tfor(let name of componentNames) {\n\t\t// The entity component is always built on the main thread when the descriptor is adopted (interning the type),\n\t\t// never off-thread - skip it here whether or not the registry includes it.\n\t\tif(name === 'entity') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst definition = registry[name];\n\t\tif(!definition) {\n\t\t\tthrow new Error(`Entity class ${entityClass ?? ''} contains unknown component ${name}`);\n\t\t}\n\t\t// Deferred components need the whole world (other entities) that a worker doesn't have; skip them.\n\t\tif(definition.loadInFinishLoading) {\n\t\t\tcontinue;\n\t\t}\n\t\tif(definition.loadProperties.some(prop => prop in merged)) {\n\t\t\tcomponents[name] = allocator.allocateComponentBlock(name, definition.toBlock(merged));\n\t\t}\n\t}\n\n\treturn {\n\t\teid,\n\t\ttype: config.type,\n\t\tclass: entityClass,\n\t\tisStatic: merged.isStatic as boolean | undefined,\n\t\tcomponents,\n\t};\n}\n\nexport function buildWorkerComponent(\n\tname: string,\n\tconfig: Record<string, unknown>,\n\tregistry: WorkerCreateRegistry,\n\tallocator: WorkerAllocator,\n): WorkerCreatedComponent {\n\tif(name === 'entity') {\n\t\tthrow new Error('The entity component cannot be added at runtime');\n\t}\n\tconst definition = registry[name];\n\tif(!definition) {\n\t\tthrow new Error(`Unknown component: ${name}`);\n\t}\n\tif(definition.loadInFinishLoading) {\n\t\tthrow new Error(`Component ${name} requires main-thread finishLoading and cannot be added in a worker`);\n\t}\n\n\treturn {\n\t\tname,\n\t\tindex: allocator.allocateComponentBlock(name, definition.toBlock(config)),\n\t};\n}\n","import type { ComponentTypedArray } from './memory-component';\nimport type { BaseComponent } from './component-definition';\n\n// Base class for a memory-backed component accessor. Subclass it, declare prototype get/set accessors over\n// `this.block` indexed by the component's exported *_INDEX constants, and return `new YourComponent(block, index)`\n// from `attach`. Because the accessors live on one shared prototype - not fresh closures captured per entity -\n// reads off thousands of entities every frame stay monomorphic and inline, and constructing a component allocates\n// just the instance instead of a closure per accessor. Components that own no extra memory need nothing else; a\n// subclass that does can take more constructor args (the entity, another pool) and store them as fields.\nexport default abstract class Component<T extends ComponentTypedArray = ComponentTypedArray> implements BaseComponent {\n\treadonly index: number;\n\treadonly block: T;\n\n\tconstructor(block: T, index: number) {\n\t\tthis.block = block;\n\t\tthis.index = index;\n\t}\n}\n","import type { ComponentDefinition } from './component-definition';\nimport Component from './component';\nimport type ConstantStringCache from './constant-string-cache';\n\nexport interface EntityComponent {\n\tindex: number\n\treadonly type: string\n\treadonly class: string\n\tdead: boolean\n\tisStatic: boolean\n}\n\nexport interface EntityComponentConfig {\n\ttype: string\n\tisStatic?: boolean\n}\n\nexport interface EntityClassConfig {\n\treadonly class: string\n}\n\nexport interface EntityComponentSerialization {\n\ttype?: string\n\tdead?: boolean\n}\n\nexport const DEAD_INDEX = 0;\nexport const STATIC_INDEX = 1;\nexport const TYPE_INDEX = 2;\nexport const CLASS_INDEX = 3;\n\n// Identity strings are interned, so the accessor needs the world's cache to resolve their pointers.\nclass EntityComponentImpl extends Component<Uint32Array> implements EntityComponent {\n\tprivate cache: ConstantStringCache;\n\n\tconstructor(block: Uint32Array, index: number, cache: ConstantStringCache) {\n\t\tsuper(block, index);\n\t\tthis.cache = cache;\n\t}\n\n\tget type() {\n\t\treturn this.cache.getString(this.block[TYPE_INDEX]) ?? '';\n\t}\n\tget class() {\n\t\treturn this.cache.getString(this.block[CLASS_INDEX]) ?? '';\n\t}\n\tget dead() {\n\t\treturn this.block[DEAD_INDEX] === 1;\n\t}\n\tset dead(value: boolean) {\n\t\tthis.block[DEAD_INDEX] = value ? 1 : 0;\n\t}\n\tget isStatic() {\n\t\treturn this.block[STATIC_INDEX] === 1;\n\t}\n\tset isStatic(value: boolean) {\n\t\tthis.block[STATIC_INDEX] = value ? 1 : 0;\n\t}\n}\n\nexport const entityDefinition: ComponentDefinition<EntityComponent, Uint32Array, EntityComponentConfig & Partial<EntityClassConfig>, EntityComponentSerialization> = {\n\ttype: Uint32Array,\n\tsize: 4,\n\tloadProperties: ['type', 'isStatic'],\n\t// The only component that reads the entity (never worker-created): it interns its identity strings through the heap and\n\t// stores the pointer. `entity` is always passed here since loadComponent runs on the main thread.\n\ttoBlock(config, entity) {\n\t\tconst cache = entity!.world.constantStrings;\n\t\tconst typePointer = config.type ? cache.getOrCreate(config.type).pointer : 0;\n\t\tconst classPointer = config.class ? cache.getOrCreate(config.class).pointer : 0;\n\t\treturn [config.dead ? 1 : 0, config.isStatic ? 1 : 0, typePointer, classPointer];\n\t},\n\tattach(entity, memory, index) {\n\t\treturn new EntityComponentImpl(memory.getBlock(index), index, entity.world.constantStrings);\n\t},\n\tsave(component) {\n\t\tconst config: EntityComponentSerialization = {};\n\t\tif(component.type) {\n\t\t\tconfig.type = component.type;\n\t\t}\n\t\tif(component.dead) {\n\t\t\tconfig.dead = true;\n\t\t}\n\n\t\treturn config;\n\t},\n};\n","import type { ComponentTypedArray } from '../memory-component';\nimport type { EntityWorkerSystemCallbacks, EntityUpdateComponents } from '../systems/entity-worker-system';\nimport { DEAD_INDEX } from '../entity-component';\n\n// Worker-side killEntity: flags the entity dead in its block and reports the death back via callbacks. The\n// entity component must be in the system's query for its block to be available here.\nexport default function killEntityWorker(entityId: number, components: EntityUpdateComponents, callbacks: EntityWorkerSystemCallbacks): void {\n\tconst block = (components as { entity?: ComponentTypedArray }).entity;\n\tif(block) {\n\t\tblock[DEAD_INDEX] = 1;\n\t}\n\n\tcallbacks.entityDied(entityId);\n}\n","import type { EntityWorkerSystemCallbacks, EntityWorkerSystemWorld, WorkerCreateEntityConfig } from '../systems/entity-worker-system';\n\n// Worker-side entity creation from a factory config. The worker merges the selected type template, resolves its\n// optional class, mints a unique id, and allocates + writes every allowed, triggered component block\n// directly into the shared pools (off-thread) via each component's toBlock(). It reports the descriptor back; the main\n// thread adopts it on run-complete (world.adoptEntity), building the `entity` component and class wrapper there\n// worker-written blocks, so the entity first exists on the following frame.\n//\n// Requires the system to be registered with `createsEntities: true` and its worker entry to pass the component\n// registry to createEntitySystemWorker (so the worker has each component's toBlock).\nexport default function createEntityWorker(world: EntityWorkerSystemWorld, config: WorkerCreateEntityConfig, callbacks: EntityWorkerSystemCallbacks): void {\n\tif(!world.buildEntityDescriptor) {\n\t\tthrow new Error('createEntityWorker requires the system to be registered with createsEntities: true and the component registry passed to createEntitySystemWorker');\n\t}\n\n\tcallbacks.createEntity(world.buildEntityDescriptor(config));\n}\n","import type { ComponentMap } from '../component-definition';\nimport type { EntityWorkerSystemCallbacks, EntityWorkerSystemWorld } from '../systems/entity-worker-system';\n\n// Allocates a component block in the worker and asks the main thread to attach it after the run. The entity's\n// current query snapshot is intentionally unchanged until the next run.\nexport default function addComponentWorker<C extends ComponentMap, K extends keyof C>(\n\tworld: EntityWorkerSystemWorld,\n\tentityId: number,\n\tcomponentName: K,\n\tconfig: Record<string, unknown>,\n\tcallbacks: EntityWorkerSystemCallbacks<C>,\n): void {\n\tif(!world.buildComponentDescriptor) {\n\t\tthrow new Error('addComponentWorker requires addsComponents: true and the component registry passed to createEntitySystemWorker');\n\t}\n\n\tcallbacks.addComponent(entityId, world.buildComponentDescriptor(String(componentName), config));\n}\n","import type { ComponentMap } from '../component-definition';\nimport type { EntityWorkerSystemCallbacks } from '../systems/entity-worker-system';\n\n// Requests a main-thread detach after the worker run. Shared memory is freed only after every system that could\n// still hold the old block has completed a run.\nexport default function removeComponentWorker<C extends ComponentMap, K extends keyof C>(\n\tentityId: number,\n\tcomponentName: K,\n\tcallbacks: EntityWorkerSystemCallbacks<C>,\n): void {\n\tcallbacks.removeComponent(entityId, componentName);\n}\n","import MemoryHeap from '@daneren2005/shared-memory-objects/memory-heap';\nimport type AllocatedMemory from '@daneren2005/shared-memory-objects/allocated-memory';\nimport type EntitySystemWorkerMessage from './entity-system-worker-message';\nimport type { EntityEvent, SystemEvents, WorkerRunError } from './entity-system-worker-message';\nimport ConstantStringCache from '../../constant-string-cache';\nimport MemoryComponent from '../../memory-component';\nimport type { ComponentDefinitionMap, ComponentMap } from '../../component-definition';\nimport type {\n\tEntityWorkerSystemCallbacks, EntityWorkerSystemWorld, EntityQueryComponents, EntityUpdateComponents,\n\tEntityUpdateFunction, QueryDelta, WorkerComponentChange, WorkerCreatedEntity,\n} from '../entity-worker-system';\nimport { buildWorkerComponent, buildWorkerEntity, type FactoryConfigs } from '../../actions/build-worker-entity';\nimport type { WorkerEntityClassRegistry } from '../../entity-class';\nimport QueryMembership from './query-membership';\nimport EntityWorkBatchState from './entity-work-batch';\n\n// The slice of the worker global scope createEntitySystemWorker touches. Passing `self` explicitly (rather than\n// using the global) lets runners like @vitest/web-worker, which inject `self` as a module local, drive it.\nexport interface EntitySystemWorkerScope {\n\tonmessage: ((e: MessageEvent) => void) | null\n\tpostMessage(message: EntitySystemWorkerMessage): void\n\taddEventListener?(type: 'unhandledrejection', listener: (event: PromiseRejectionEvent) => void): void\n}\n\nexport default function createEntitySystemWorker<\n\tC extends ComponentMap,\n\tT extends EntityUpdateComponents<C>,\n\tW extends EntityWorkerSystemWorld = EntityWorkerSystemWorld,\n\tD = unknown,\n>(scope: EntitySystemWorkerScope, updateFunction: EntityUpdateFunction<C, T, W, D>, definitions?: ComponentDefinitionMap) {\n\tscope.addEventListener?.('unhandledrejection', event => {\n\t\tconst reason: unknown = event.reason;\n\t\t// Copy error details without a potentially uncloneable rejection reason or cause.\n\t\tconst error = new Error(reason instanceof Error ? reason.message : String(reason));\n\t\tif(reason instanceof Error) {\n\t\t\terror.name = reason.name;\n\t\t\terror.stack = reason.stack;\n\t\t}\n\t\tpostMessageTyped(scope, { type: 'unhandled-rejection', error });\n\t});\n\n\t// Persistent lists, carried across runs and mutated by each run's delta.\n\tconst entities = new QueryMembership<T>();\n\tconst workState = new EntityWorkBatchState<T, W>();\n\tconst queryEntities: { [key: string]: QueryMembership<T> } = {};\n\tconst applyQueryDeltas = (deltas: { [key: string]: QueryDelta }): EntityQueryComponents<C> => {\n\t\tconst queries: EntityQueryComponents<C> = {};\n\t\tfor(const [queryKey, delta] of Object.entries(deltas)) {\n\t\t\tconst membership = queryEntities[queryKey] ??= new QueryMembership<T>();\n\t\t\tmembership.apply(delta as QueryDelta<T>);\n\t\t\tqueries[queryKey] = membership.entries;\n\t\t}\n\t\treturn queries;\n\t};\n\t// What updateFunction.init returned: persistent state (e.g. a seeded RNG) merged onto `world` each run.\n\tlet worldExtension: Partial<W> | undefined;\n\tlet heap: MemoryHeap | undefined;\n\tlet stringCache: ConstantStringCache | undefined;\n\t// Reconstructed pool handles over the world's shared state, plus the factory templates - for off-thread entity\n\t// allocation. `definitions` (passed by the game's worker entry) supplies each component's toBlock/loadProperties.\n\tlet pools: { [name: string]: MemoryComponent } = {};\n\tlet eidCounter: AllocatedMemory | undefined;\n\tlet factoryConfigs: FactoryConfigs | undefined;\n\tlet factoryClasses: WorkerEntityClassRegistry | undefined;\n\tlet addsComponents = false;\n\tconst getString = (pointer: number): string => stringCache?.getString(pointer) ?? '';\n\n\tscope.onmessage = function(e) {\n\t\tconst message = e.data as EntitySystemWorkerMessage<W, D>;\n\n\t\tif(message.type === 'init') {\n\t\t\tpostMessageTyped(scope, {\n\t\t\t\ttype: 'init-complete',\n\t\t\t});\n\t\t} else if(message.type === 'load') {\n\t\t\tif(message.heap) {\n\t\t\t\theap = new MemoryHeap(message.heap);\n\t\t\t\tstringCache = new ConstantStringCache(heap);\n\t\t\t\t// Report any buffer this worker grows (while allocating off-thread) back to the main thread, which adopts\n\t\t\t\t// it and fans it out to sibling workers.\n\t\t\t\theap.addOnGrowBufferHandlers(buffer => postMessageTyped(scope, { type: 'grow-buffer-from-worker', buffer }));\n\t\t\t}\n\t\t\tif(heap && message.sharedMemory) {\n\t\t\t\tpools = {};\n\t\t\t\tfor(const name of Object.keys(message.sharedMemory.components)) {\n\t\t\t\t\tpools[name] = MemoryComponent.fromSharedMemory(heap, message.sharedMemory.components[name]);\n\t\t\t\t}\n\t\t\t\teidCounter = heap.getSharedAlloc(message.sharedMemory.eidCounter);\n\t\t\t}\n\t\t\tfactoryConfigs = message.factoryConfigs;\n\t\t\tfactoryClasses = message.factoryClasses;\n\t\t\taddsComponents = !!message.addsComponents;\n\t\t\tentities.apply(message.entities as QueryDelta<T>);\n\t\t\tconst queries = applyQueryDeltas(message.queries);\n\t\t\tworldExtension = updateFunction.init?.({ gameTime: message.gameTime, getString, heap }, message.data, entities.entries, queries) ?? undefined;\n\t\t\tpostMessageTyped(scope, {\n\t\t\t\ttype: 'loaded',\n\t\t\t});\n\t\t} else if(message.type === 'grow-buffer') {\n\t\t\t// Never replace a buffer this worker already holds: the main thread fans a worker-grown buffer back out to\n\t\t\t// every worker (including the one that grew it), and overwriting our own live MemoryBuffer would discard its\n\t\t\t// allocation bookkeeping. The SharedArrayBuffer at that position is already the same one.\n\t\t\tif(heap && heap.buffers[message.buffer.bufferPosition] === undefined) {\n\t\t\t\theap.addSharedBuffer(message.buffer);\n\t\t\t}\n\t\t} else if(message.type === 'reset') {\n\t\t\tworkState.clear();\n\t\t\t// Drop the persistent lists so a reused world starts empty; worldExtension is refreshed by the next load.\n\t\t\tentities.clear();\n\t\t\tfor(const key of Object.keys(queryEntities)) {\n\t\t\t\tdelete queryEntities[key];\n\t\t\t}\n\t\t\tworldExtension = undefined;\n\t\t} else if(message.type === 'run') {\n\t\t\tmessage.world = workState.getWorld(message.world, message.workBatch);\n\t\t\tif(worldExtension) {\n\t\t\t\tObject.assign(message.world, worldExtension);\n\t\t\t}\n\t\t\tmessage.world.getString = getString;\n\t\t\tmessage.world.heap = heap;\n\t\t\tconst allocator = {\n\t\t\t\tallocateEid: () => eidCounter ? Atomics.add(eidCounter.data, 0, 1) + 1 : 0,\n\t\t\t\tallocateComponentBlock: (name: string, values: Array<number>) => pools[name].create(values),\n\t\t\t};\n\t\t\tmessage.world.allocate = allocator;\n\t\t\t// Only a system registered with createsEntities (factoryConfigs shipped) whose worker entry passed the\n\t\t\t// component definitions can create entities from a config.\n\t\t\tif(factoryConfigs && definitions) {\n\t\t\t\tmessage.world.buildEntityDescriptor = config => buildWorkerEntity(config, factoryConfigs!, definitions, allocator, factoryClasses);\n\t\t\t}\n\t\t\tif(addsComponents && definitions) {\n\t\t\t\tmessage.world.buildComponentDescriptor = (name, config) => buildWorkerComponent(name, config, definitions, allocator);\n\t\t\t}\n\t\t\tconst start = performance.now();\n\t\t\tlet entityEvents: Array<EntityEvent> = [];\n\t\t\tlet systemEvents: SystemEvents = {};\n\t\t\tlet createdEntities: Array<WorkerCreatedEntity> = [];\n\t\t\tlet componentChanges: Array<WorkerComponentChange> = [];\n\t\t\tlet errors: Array<WorkerRunError> = [];\n\n\t\t\tentities.apply(message.entities as QueryDelta<T>);\n\t\t\tconst runEntities = workState.getEntities(entities.entries, message.entities as QueryDelta<T>, message.workBatch);\n\t\t\tconst queries = applyQueryDeltas(message.queries);\n\n\t\t\tlet callbacks: EntityWorkerSystemCallbacks<C> = {\n\t\t\t\tentityComponentChanged<K extends keyof C, P extends keyof C[K]>(entityId: number, componentName: K, prop: P, value: C[K][P]) {\n\t\t\t\t\tentityEvents.push({\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tevent: 'component-property-updated',\n\t\t\t\t\t\targs: [componentName, prop, value],\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\temitEntityEvent(entityId: number, event: string, ...args: Array<unknown>) {\n\t\t\t\t\tentityEvents.push({\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\targs,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\temitSystemEvent(event: string, entityId: number) {\n\t\t\t\t\t(systemEvents[event] ?? (systemEvents[event] = [])).push(entityId);\n\t\t\t\t},\n\t\t\t\tentityDied(entityId: number) {\n\t\t\t\t\tentityEvents.push({\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tevent: 'death',\n\t\t\t\t\t\targs: [],\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tcreateEntity(entity: WorkerCreatedEntity) {\n\t\t\t\t\tcreatedEntities.push(entity);\n\t\t\t\t},\n\t\t\t\taddComponent(entityId, component) {\n\t\t\t\t\tcomponentChanges.push({ type: 'add', entityId, component });\n\t\t\t\t},\n\t\t\t\tremoveComponent(entityId, componentName) {\n\t\t\t\t\tcomponentChanges.push({ type: 'remove', entityId, componentName: String(componentName) });\n\t\t\t\t},\n\t\t\t};\n\t\t\tif(updateFunction.queryChanged) {\n\t\t\t\tfor(const [queryName, delta] of Object.entries(message.queries)) {\n\t\t\t\t\tif(!delta.added.length && !delta.removed.length) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tupdateFunction.queryChanged(message.world, queryName, delta, callbacks);\n\t\t\t\t\t} catch(err) {\n\t\t\t\t\t\terrors.push({ error: err as Error, phase: 'queryChanged' });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet preRunFailed = false;\n\t\t\tif(updateFunction.preRun && (!message.workBatch || message.workBatch.first)) {\n\t\t\t\ttry {\n\t\t\t\t\tupdateFunction.preRun(message.world, entities.entries, queries, callbacks);\n\t\t\t\t} catch(err) {\n\t\t\t\t\tpreRunFailed = true;\n\t\t\t\t\terrors.push({ error: err as Error, phase: 'preRun' });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// preRun sets up the run's state; if it threw, skip the entity loop rather than run over half-prepared data.\n\t\t\tif(!preRunFailed && updateFunction.preBatch) {\n\t\t\t\ttry {\n\t\t\t\t\tupdateFunction.preBatch(message.world, runEntities, queries, callbacks);\n\t\t\t\t} catch(err) {\n\t\t\t\t\tpreRunFailed = true;\n\t\t\t\t\terrors.push({ error: err as Error, phase: 'preBatch' });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!preRunFailed) {\n\t\t\t\trunEntities.forEach(entity => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tupdateFunction(message.world, entity.entityId, entity.components, queries, callbacks);\n\t\t\t\t\t} catch(err) {\n\t\t\t\t\t\t// One entity failing must not stop the rest of the run.\n\t\t\t\t\t\terrors.push({ error: err as Error, phase: 'update', entityId: entity.entityId });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif(updateFunction.entityRemoved) {\n\t\t\t\tmessage.entities.removed.forEach(entityId => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tupdateFunction.entityRemoved!(message.world, entityId, callbacks);\n\t\t\t\t\t} catch(err) {\n\t\t\t\t\t\terrors.push({ error: err as Error, phase: 'entityRemoved', entityId });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst runTime = performance.now() - start;\n\t\t\tworkState.finish(message.workBatch, preRunFailed);\n\n\t\t\tpostMessageTyped(scope, {\n\t\t\t\ttype: 'run-complete',\n\t\t\t\tgeneration: message.generation,\n\t\t\t\trunTime,\n\t\t\t\tevents: entityEvents,\n\t\t\t\tsystemEvents,\n\t\t\t\tcreated: createdEntities,\n\t\t\t\tcomponentChanges,\n\t\t\t\terrors,\n\t\t\t\tworkFailed: preRunFailed,\n\t\t\t});\n\t\t}\n\t};\n}\n\nfunction postMessageTyped(scope: EntitySystemWorkerScope, message: EntitySystemWorkerMessage) {\n\tscope.postMessage(message);\n}\n","import createEntitySystemWorker, { type EntitySystemWorkerScope } from './create-entity-system-worker';\nimport type { ComponentDefinitionMap, ComponentMap } from '../../component-definition';\nimport type {\n\tEntityWorkerSystemCallbacks, EntityWorkerSystemInitWorld, EntityWorkerSystemWorld, EntityQueryComponents, EntityUpdateComponents,\n\tEntityUpdateFunction, EntityRemovedFunction, EntityQueryChangedFunction,\n} from '../entity-worker-system';\n\n// A WorkerSystem's single per-run function: called once per run over the named sub-queries, not once per entity.\n// Optional `init`/`queryChanged`/`entityRemoved` mirror EntityUpdateFunction's hooks.\nexport type WorkerSystemRunFunction<\n\tC extends ComponentMap,\n\tW extends EntityWorkerSystemWorld = EntityWorkerSystemWorld,\n\tD = unknown,\n> = ((world: W, queries: EntityQueryComponents<C>, callbacks: EntityWorkerSystemCallbacks<C>) => void) & {\n\tinit?: WorkerSystemInitFunction<C, W, D>\n\tqueryChanged?: EntityQueryChangedFunction<C, W>\n\tentityRemoved?: EntityRemovedFunction<C, W>\n};\n// No entities argument: a WorkerSystem has no main query.\nexport type WorkerSystemInitFunction<\n\tC extends ComponentMap,\n\tW extends EntityWorkerSystemWorld = EntityWorkerSystemWorld,\n\tD = unknown,\n> = (world: EntityWorkerSystemInitWorld, data: D | undefined, queries: EntityQueryComponents<C>) => Partial<W> | void;\n\n// A WorkerSystem reuses the EntityWorkerSystem worker machinery: the single run function becomes `preRun` (which runs\n// once with query access) and the per-entity body is a no-op, since a WorkerSystem never populates its main query.\nexport function toEntityUpdateFunction<\n\tC extends ComponentMap,\n\tW extends EntityWorkerSystemWorld = EntityWorkerSystemWorld,\n\tD = unknown,\n>(run: WorkerSystemRunFunction<C, W, D>): EntityUpdateFunction<C, EntityUpdateComponents<C>, W, D> {\n\tconst updateFunction = (() => {}) as EntityUpdateFunction<C, EntityUpdateComponents<C>, W, D>;\n\tupdateFunction.preRun = (world, _entities, queries, callbacks) => run(world, queries, callbacks);\n\tconst init = run.init;\n\tif(init) {\n\t\tupdateFunction.init = (world, data, _entities, queries) => init(world, data, queries);\n\t}\n\tif(run.queryChanged) {\n\t\tupdateFunction.queryChanged = run.queryChanged;\n\t}\n\tif(run.entityRemoved) {\n\t\tupdateFunction.entityRemoved = run.entityRemoved;\n\t}\n\n\treturn updateFunction;\n}\n\n// Worker entry helper for a WorkerSystem (mirrors createEntitySystemWorker). Pass the component registry only for a\n// worker that creates entities.\nexport default function createSystemWorker<\n\tC extends ComponentMap,\n\tW extends EntityWorkerSystemWorld = EntityWorkerSystemWorld,\n\tD = unknown,\n>(scope: EntitySystemWorkerScope, runFunction: WorkerSystemRunFunction<C, W, D>, definitions?: Com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