@daneren2005/shared-memory-ecs 1.10.0 → 1.10.2
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/dist/{create-system-worker-CNpRs2FO.js → create-system-worker-BU5CnyVh.js} +84 -83
- package/dist/create-system-worker-BU5CnyVh.js.map +1 -0
- package/dist/index.js +138 -134
- package/dist/index.js.map +1 -1
- package/dist/scheduling/scheduler.d.ts +1 -0
- package/dist/systems/workers/entity-system-web-worker.d.ts +1 -0
- package/dist/systems/workers/query-membership.d.ts +7 -0
- package/dist/worker.js +1 -1
- package/dist/world.d.ts +2 -1
- package/package.json +1 -1
- package/dist/create-system-worker-CNpRs2FO.js.map +0 -1
- package/dist/systems/workers/apply-query-delta.d.ts +0 -2
|
@@ -68,27 +68,26 @@ var i = class e {
|
|
|
68
68
|
clear() {
|
|
69
69
|
this.byValue.forEach((e) => e.free()), this.byValue.clear(), this.byPointer.clear();
|
|
70
70
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (let
|
|
83
|
-
let
|
|
84
|
-
|
|
71
|
+
}, o = class {
|
|
72
|
+
entries = [];
|
|
73
|
+
indexByEid = /* @__PURE__ */ new Map();
|
|
74
|
+
apply(e) {
|
|
75
|
+
for (let t of e.removed) {
|
|
76
|
+
let e = this.indexByEid.get(t);
|
|
77
|
+
if (e === void 0) continue;
|
|
78
|
+
this.indexByEid.delete(t);
|
|
79
|
+
let n = this.entries.pop();
|
|
80
|
+
e < this.entries.length && (this.entries[e] = n, this.indexByEid.set(n.entityId, e));
|
|
81
|
+
}
|
|
82
|
+
for (let t of e.added) {
|
|
83
|
+
let e = this.indexByEid.get(t.entityId);
|
|
84
|
+
e === void 0 ? (this.indexByEid.set(t.entityId, this.entries.length), this.entries.push(t)) : this.entries[e] = t;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var s = class {
|
|
87
|
+
clear() {
|
|
88
|
+
this.entries.length = 0, this.indexByEid.clear();
|
|
89
|
+
}
|
|
90
|
+
}, s = class {
|
|
92
91
|
world;
|
|
93
92
|
entities = /* @__PURE__ */ new Map();
|
|
94
93
|
getWorld(e, t) {
|
|
@@ -237,46 +236,48 @@ function x(t, n, r) {
|
|
|
237
236
|
error: r
|
|
238
237
|
});
|
|
239
238
|
});
|
|
240
|
-
let u =
|
|
241
|
-
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
let u = new o(), d = new s(), f = {}, p = (e) => {
|
|
240
|
+
let t = {};
|
|
241
|
+
for (let [n, r] of Object.entries(e)) {
|
|
242
|
+
let e = f[n] ??= new o();
|
|
243
|
+
e.apply(r), t[n] = e.entries;
|
|
244
|
+
}
|
|
245
|
+
return t;
|
|
246
|
+
}, m, h, g, _ = {}, v, y, b, x = !1, C = (e) => g?.getString(e) ?? "";
|
|
247
|
+
t.onmessage = function(o) {
|
|
248
|
+
let s = o.data;
|
|
249
|
+
if (s.type === "init") S(t, { type: "init-complete" });
|
|
250
|
+
else if (s.type === "load") {
|
|
251
|
+
if (s.heap && (h = new e(s.heap), g = new a(h), h.addOnGrowBufferHandlers((e) => S(t, {
|
|
246
252
|
type: "grow-buffer-from-worker",
|
|
247
253
|
buffer: e
|
|
248
|
-
}))),
|
|
249
|
-
|
|
250
|
-
for (let e of Object.keys(
|
|
251
|
-
|
|
254
|
+
}))), h && s.sharedMemory) {
|
|
255
|
+
_ = {};
|
|
256
|
+
for (let e of Object.keys(s.sharedMemory.components)) _[e] = i.fromSharedMemory(h, s.sharedMemory.components[e]);
|
|
257
|
+
v = h.getSharedAlloc(s.sharedMemory.eidCounter);
|
|
252
258
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
gameTime:
|
|
257
|
-
getString:
|
|
258
|
-
heap:
|
|
259
|
-
},
|
|
260
|
-
} else if (
|
|
261
|
-
else if (
|
|
262
|
-
d.clear(), u
|
|
259
|
+
y = s.factoryConfigs, b = s.factoryClasses, x = !!s.addsComponents, u.apply(s.entities);
|
|
260
|
+
let r = p(s.queries);
|
|
261
|
+
m = n.init?.({
|
|
262
|
+
gameTime: s.gameTime,
|
|
263
|
+
getString: C,
|
|
264
|
+
heap: h
|
|
265
|
+
}, s.data, u.entries, r) ?? void 0, S(t, { type: "loaded" });
|
|
266
|
+
} else if (s.type === "grow-buffer") h && h.buffers[s.buffer.bufferPosition] === void 0 && h.addSharedBuffer(s.buffer);
|
|
267
|
+
else if (s.type === "reset") {
|
|
268
|
+
d.clear(), u.clear();
|
|
263
269
|
for (let e of Object.keys(f)) delete f[e];
|
|
264
|
-
|
|
265
|
-
} else if (
|
|
266
|
-
|
|
270
|
+
m = void 0;
|
|
271
|
+
} else if (s.type === "run") {
|
|
272
|
+
s.world = d.getWorld(s.world, s.workBatch), m && Object.assign(s.world, m), s.world.getString = C, s.world.heap = h;
|
|
267
273
|
let e = {
|
|
268
|
-
allocateEid: () =>
|
|
269
|
-
allocateComponentBlock: (e, t) =>
|
|
274
|
+
allocateEid: () => v ? Atomics.add(v.data, 0, 1) + 1 : 0,
|
|
275
|
+
allocateComponentBlock: (e, t) => _[e].create(t)
|
|
270
276
|
};
|
|
271
|
-
|
|
272
|
-
let i = performance.now(), a = [],
|
|
273
|
-
u
|
|
274
|
-
let
|
|
275
|
-
Object.entries(C.queries).forEach(([e, t]) => {
|
|
276
|
-
let n = o(f[e] ?? [], t);
|
|
277
|
-
f[e] = n, D[e] = n;
|
|
278
|
-
});
|
|
279
|
-
let O = {
|
|
277
|
+
s.world.allocate = e, y && r && (s.world.buildEntityDescriptor = (t) => c(t, y, r, e, b)), x && r && (s.world.buildComponentDescriptor = (t, n) => l(t, n, r, e));
|
|
278
|
+
let i = performance.now(), a = [], o = {}, f = [], g = [], w = [];
|
|
279
|
+
u.apply(s.entities);
|
|
280
|
+
let T = d.getEntities(u.entries, s.entities, s.workBatch), E = p(s.queries), D = {
|
|
280
281
|
entityComponentChanged(e, t, n, r) {
|
|
281
282
|
a.push({
|
|
282
283
|
entityId: e,
|
|
@@ -296,7 +297,7 @@ function x(t, n, r) {
|
|
|
296
297
|
});
|
|
297
298
|
},
|
|
298
299
|
emitSystemEvent(e, t) {
|
|
299
|
-
(
|
|
300
|
+
(o[e] ?? (o[e] = [])).push(t);
|
|
300
301
|
},
|
|
301
302
|
entityDied(e) {
|
|
302
303
|
a.push({
|
|
@@ -306,17 +307,17 @@ function x(t, n, r) {
|
|
|
306
307
|
});
|
|
307
308
|
},
|
|
308
309
|
createEntity(e) {
|
|
309
|
-
|
|
310
|
+
f.push(e);
|
|
310
311
|
},
|
|
311
312
|
addComponent(e, t) {
|
|
312
|
-
|
|
313
|
+
g.push({
|
|
313
314
|
type: "add",
|
|
314
315
|
entityId: e,
|
|
315
316
|
component: t
|
|
316
317
|
});
|
|
317
318
|
},
|
|
318
319
|
removeComponent(e, t) {
|
|
319
|
-
|
|
320
|
+
g.push({
|
|
320
321
|
type: "remove",
|
|
321
322
|
entityId: e,
|
|
322
323
|
componentName: String(t)
|
|
@@ -324,64 +325,64 @@ function x(t, n, r) {
|
|
|
324
325
|
}
|
|
325
326
|
};
|
|
326
327
|
if (n.queryChanged) {
|
|
327
|
-
for (let [e, t] of Object.entries(
|
|
328
|
-
n.queryChanged(
|
|
328
|
+
for (let [e, t] of Object.entries(s.queries)) if (t.added.length || t.removed.length) try {
|
|
329
|
+
n.queryChanged(s.world, e, t, D);
|
|
329
330
|
} catch (e) {
|
|
330
|
-
|
|
331
|
+
w.push({
|
|
331
332
|
error: e,
|
|
332
333
|
phase: "queryChanged"
|
|
333
334
|
});
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
|
-
let
|
|
337
|
-
if (n.preRun && (!
|
|
338
|
-
n.preRun(
|
|
337
|
+
let O = !1;
|
|
338
|
+
if (n.preRun && (!s.workBatch || s.workBatch.first)) try {
|
|
339
|
+
n.preRun(s.world, u.entries, E, D);
|
|
339
340
|
} catch (e) {
|
|
340
|
-
|
|
341
|
+
O = !0, w.push({
|
|
341
342
|
error: e,
|
|
342
343
|
phase: "preRun"
|
|
343
344
|
});
|
|
344
345
|
}
|
|
345
|
-
if (!
|
|
346
|
-
n.preBatch(
|
|
346
|
+
if (!O && n.preBatch) try {
|
|
347
|
+
n.preBatch(s.world, T, E, D);
|
|
347
348
|
} catch (e) {
|
|
348
|
-
|
|
349
|
+
O = !0, w.push({
|
|
349
350
|
error: e,
|
|
350
351
|
phase: "preBatch"
|
|
351
352
|
});
|
|
352
353
|
}
|
|
353
|
-
|
|
354
|
+
O || T.forEach((e) => {
|
|
354
355
|
try {
|
|
355
|
-
n(
|
|
356
|
+
n(s.world, e.entityId, e.components, E, D);
|
|
356
357
|
} catch (t) {
|
|
357
|
-
|
|
358
|
+
w.push({
|
|
358
359
|
error: t,
|
|
359
360
|
phase: "update",
|
|
360
361
|
entityId: e.entityId
|
|
361
362
|
});
|
|
362
363
|
}
|
|
363
|
-
}), n.entityRemoved &&
|
|
364
|
+
}), n.entityRemoved && s.entities.removed.forEach((e) => {
|
|
364
365
|
try {
|
|
365
|
-
n.entityRemoved(
|
|
366
|
+
n.entityRemoved(s.world, e, D);
|
|
366
367
|
} catch (t) {
|
|
367
|
-
|
|
368
|
+
w.push({
|
|
368
369
|
error: t,
|
|
369
370
|
phase: "entityRemoved",
|
|
370
371
|
entityId: e
|
|
371
372
|
});
|
|
372
373
|
}
|
|
373
374
|
});
|
|
374
|
-
let
|
|
375
|
-
d.finish(
|
|
375
|
+
let k = performance.now() - i;
|
|
376
|
+
d.finish(s.workBatch, O), S(t, {
|
|
376
377
|
type: "run-complete",
|
|
377
|
-
generation:
|
|
378
|
-
runTime:
|
|
378
|
+
generation: s.generation,
|
|
379
|
+
runTime: k,
|
|
379
380
|
events: a,
|
|
380
|
-
systemEvents:
|
|
381
|
-
created:
|
|
382
|
-
componentChanges:
|
|
383
|
-
errors:
|
|
384
|
-
workFailed:
|
|
381
|
+
systemEvents: o,
|
|
382
|
+
created: f,
|
|
383
|
+
componentChanges: g,
|
|
384
|
+
errors: w,
|
|
385
|
+
workFailed: O
|
|
385
386
|
});
|
|
386
387
|
}
|
|
387
388
|
};
|
|
@@ -403,4 +404,4 @@ function w(e, t, n) {
|
|
|
403
404
|
//#endregion
|
|
404
405
|
export { o as _, y as a, m as c, p as d, g as f, s as g, c as h, b as i, d as l, l as m, C as n, v as o, u as p, x as r, _ as s, w as t, f as u, a as v, i as y };
|
|
405
406
|
|
|
406
|
-
//# sourceMappingURL=create-system-worker-
|
|
407
|
+
//# sourceMappingURL=create-system-worker-BU5CnyVh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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?: ComponentDefinitionMap) {\n\tcreateEntitySystemWorker(scope, toEntityUpdateFunction(runFunction), definitions);\n}\n"],"mappings":";;;;;AASA,IAAqB,IAArB,MAAqB,EAAqE;CACzF;CACA;CAEA,YAAY,GAAkB,GAAgC,GAAoB,GAA2B;EAE5G,AADA,KAAK,OAAO,GACZ,KAAK,OAAO,IACT,IAAI,EAAc,GAAM,CAAM,IAC9B,IAAI,EAAc,GAAM;GACzB;GACA;EACD,CAAC;CACH;CAIA,OAAO,iBAAsE,GAAkB,GAA8C;EAC5I,OAAO,IAAI,EAAmB,GAAM,aAAoD,GAAG,CAAM;CAClG;CAEA,kBAAoC;EACnC,OAAO,KAAK,KAAK,gBAAgB;CAClC;CAEA,IAAI,SAAS;EACZ,OAAO,KAAK,KAAK;CAClB;CACA,IAAI,YAAY;EACf,OAAO,KAAK,KAAK;CAClB;CAEA,OAAO,GAA+B;EACrC,OAAO,KAAK,KAAK,KAAK,CAAM;CAC7B;CAEA,SAAS,GAAkB;EAC1B,OAAO,KAAK,KAAK,GAAG,CAAK;CAC1B;CACA,IAAI,GAAe,GAA2B;EAC7C,OAAO,KAAK,KAAK,IAAI,GAAO,CAAS;CACtC;CACA,IAAI,GAAe,GAAmB,GAAe;EACpD,IAAI,IAA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