@daneren2005/shared-memory-ecs 1.7.2 → 1.8.1
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 +25 -3
- package/dist/component-definition.d.ts +1 -1
- package/dist/{create-system-worker-CDQmmww7.js → create-system-worker-C4aS3-3R.js} +14 -3
- package/dist/{create-system-worker-CDQmmww7.js.map → create-system-worker-C4aS3-3R.js.map} +1 -1
- package/dist/entity-factory.d.ts +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +159 -69
- package/dist/index.js.map +1 -1
- package/dist/systems/entity-system.d.ts +4 -0
- package/dist/systems/entity-worker-system.d.ts +7 -1
- package/dist/systems/system.d.ts +9 -1
- package/dist/systems/worker-system.d.ts +1 -2
- package/dist/systems/workers/create-system-worker.d.ts +2 -1
- package/dist/systems/workers/entity-system-worker-message.d.ts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/dist/world.d.ts +1 -0
- package/package.json +10 -9
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _ } from "./create-system-worker-
|
|
1
|
+
import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g, v as _ } from "./create-system-worker-C4aS3-3R.js";
|
|
2
2
|
import v from "@daneren2005/shared-memory-objects/memory-heap";
|
|
3
3
|
import { MAX_BYTE_OFFSET_LENGTH as y } from "@daneren2005/shared-memory-objects/utils/pointer";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
@@ -8,7 +8,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
8
8
|
enumerable: !(r = S(t, s)) || r.enumerable
|
|
9
9
|
});
|
|
10
10
|
return e;
|
|
11
|
-
}, O = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : b(w(e)), D(t || !e || !e.__esModule ? x(n, "default", {
|
|
11
|
+
}, O = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : b(w(e)), D(t || !e || !e.__esModule || !T.call(e, "default") ? x(n, "default", {
|
|
12
12
|
value: e,
|
|
13
13
|
enumerable: !0
|
|
14
14
|
}) : n, e)))((/* @__PURE__ */ E(((e, t) => {
|
|
@@ -112,11 +112,13 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
112
112
|
this.currentDelta = 0;
|
|
113
113
|
}
|
|
114
114
|
finishLoading() {}
|
|
115
|
+
addEntities(e) {}
|
|
115
116
|
update(e) {
|
|
116
117
|
if (this.currentDelta += e, this.currentDelta >= this.deltaBetweenRuns || this.firstRun) {
|
|
117
118
|
let e = 0;
|
|
118
119
|
return this.deltaBetweenRuns > 0 && (e = this.currentDelta % this.deltaBetweenRuns), this.run(this.currentDelta - e), this.currentDelta = e, this.firstRun = !1, this.onRunFinished(), !0;
|
|
119
|
-
}
|
|
120
|
+
}
|
|
121
|
+
return !1;
|
|
120
122
|
}
|
|
121
123
|
onError(e, t = {}) {
|
|
122
124
|
let n = t.entityId === void 0 ? "" : ` (entity ${t.entityId})`;
|
|
@@ -142,7 +144,14 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
142
144
|
destroy() {
|
|
143
145
|
this.removeAllListeners();
|
|
144
146
|
}
|
|
145
|
-
}
|
|
147
|
+
};
|
|
148
|
+
function A(e, t, n) {
|
|
149
|
+
let r = e.groups.map(t);
|
|
150
|
+
for (let t = 0; t < e.entities.length; t++) r[e.groupIndexes[t]] && n(e.entities[t]);
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/systems/iterable-system.ts
|
|
154
|
+
var j = class extends k {
|
|
146
155
|
remainingInstancesToRun = [];
|
|
147
156
|
remainingInstancesStartTime = null;
|
|
148
157
|
iterationsPerCheck;
|
|
@@ -192,12 +201,12 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
192
201
|
}
|
|
193
202
|
beforeRunIterables() {}
|
|
194
203
|
getIterableEntityId(e) {}
|
|
195
|
-
},
|
|
204
|
+
}, M = class e extends j {
|
|
196
205
|
entities = /* @__PURE__ */ new Map();
|
|
197
206
|
options;
|
|
198
207
|
constructor(e, t = { name: "EntitySystem" }) {
|
|
199
|
-
t.iterationsPerCheck ||= 10, t.maxMsPerFrame ||= 4, super(e, t), this.options = t, e.on("entity-added", (
|
|
200
|
-
|
|
208
|
+
t.iterationsPerCheck ||= 10, t.maxMsPerFrame ||= 4, super(e, t), this.options = t, e.on("entity-added", (t) => {
|
|
209
|
+
e.isBulkLoading || this.onEntityAdded(t);
|
|
201
210
|
}), e.on("entity-removed", (e) => {
|
|
202
211
|
this.removeEntity(e);
|
|
203
212
|
}), e.entities.forEach((e) => {
|
|
@@ -222,8 +231,23 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
222
231
|
isEntityInSystem(e) {
|
|
223
232
|
return this.entities.has(e.eid);
|
|
224
233
|
}
|
|
234
|
+
onEntityAdded(e) {
|
|
235
|
+
this.checkAddEntity(e) && this.options.updateEntityOnAdd && this.updateEntity(e, 0);
|
|
236
|
+
}
|
|
237
|
+
addEntities(t) {
|
|
238
|
+
if (this.checkAddEntity !== e.prototype.checkAddEntity) {
|
|
239
|
+
t.entities.forEach((e) => this.onEntityAdded(e));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
A(t, (e) => this.hasComponents(e), (e) => {
|
|
243
|
+
this.filterEntity(e) && (this.entities.set(e.eid, e), this.options.updateEntityOnAdd && this.updateEntity(e, 0));
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
hasComponents(e) {
|
|
247
|
+
return !this.options.components || this.options.components.every((t) => !!e.components[t]);
|
|
248
|
+
}
|
|
225
249
|
checkAddEntity(e) {
|
|
226
|
-
return this.
|
|
250
|
+
return this.hasComponents(e) && this.filterEntity(e) ? (this.entities.set(e.eid, e), !0) : !1;
|
|
227
251
|
}
|
|
228
252
|
removeEntity(e) {
|
|
229
253
|
this.entities.delete(e.eid);
|
|
@@ -231,9 +255,9 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
231
255
|
shouldRun() {
|
|
232
256
|
return this.isCurrentlyRunning() || this.entities.size > 0;
|
|
233
257
|
}
|
|
234
|
-
},
|
|
258
|
+
}, N = class {
|
|
235
259
|
onmessage(e, t = []) {}
|
|
236
|
-
},
|
|
260
|
+
}, P = class extends N {
|
|
237
261
|
updateFunction;
|
|
238
262
|
entities = [];
|
|
239
263
|
queryEntities = {};
|
|
@@ -316,7 +340,18 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
316
340
|
componentName: String(t)
|
|
317
341
|
});
|
|
318
342
|
}
|
|
319
|
-
}
|
|
343
|
+
};
|
|
344
|
+
if (this.updateFunction.queryChanged) {
|
|
345
|
+
for (let [t, n] of Object.entries(e.queries)) if (n.added.length || n.removed.length) try {
|
|
346
|
+
this.updateFunction.queryChanged(e.world, t, n, d);
|
|
347
|
+
} catch (e) {
|
|
348
|
+
c.push({
|
|
349
|
+
error: e,
|
|
350
|
+
phase: "queryChanged"
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
let f = !1;
|
|
320
355
|
if (this.updateFunction.preRun) try {
|
|
321
356
|
this.updateFunction.preRun(e.world, this.entities, u, d);
|
|
322
357
|
} catch (e) {
|
|
@@ -360,7 +395,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
360
395
|
onMessageTyped(e) {
|
|
361
396
|
this.onmessage({ data: e });
|
|
362
397
|
}
|
|
363
|
-
},
|
|
398
|
+
}, F = "___main", I = class e extends k {
|
|
364
399
|
entities = /* @__PURE__ */ new Map();
|
|
365
400
|
options;
|
|
366
401
|
worker;
|
|
@@ -376,8 +411,8 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
376
411
|
constructor(e, t) {
|
|
377
412
|
super(e, t), this.options = t, Object.keys(this.options.queries ?? {}).forEach((e) => {
|
|
378
413
|
this.queryEntities[e] = /* @__PURE__ */ new Map();
|
|
379
|
-
}), e.on("entity-added", (
|
|
380
|
-
this.checkAddEntity(
|
|
414
|
+
}), e.on("entity-added", (t) => {
|
|
415
|
+
e.isBulkLoading || this.checkAddEntity(t);
|
|
381
416
|
}), e.on("entity-removed", (e) => {
|
|
382
417
|
this.removeEntity(e);
|
|
383
418
|
}), e.entities.forEach((e) => {
|
|
@@ -387,7 +422,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
387
422
|
type: "grow-buffer",
|
|
388
423
|
buffer: e
|
|
389
424
|
});
|
|
390
|
-
})) : (this.worker = new
|
|
425
|
+
})) : (this.worker = new P(t.updateFunction, e, !!t.createsEntities, !!t.addsComponents), this.isWorkerThread = !1), this.initWorker();
|
|
391
426
|
}
|
|
392
427
|
initWorker() {
|
|
393
428
|
this.worker.onmessage = (e) => {
|
|
@@ -489,7 +524,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
489
524
|
elapsedTime: e
|
|
490
525
|
};
|
|
491
526
|
this.addDataToWorld?.(t), this.isRunning = !0;
|
|
492
|
-
let n = this.buildQueryDelta(
|
|
527
|
+
let n = this.buildQueryDelta(F, this.options), r = {};
|
|
493
528
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
494
529
|
r[e] = this.buildQueryDelta(e, t);
|
|
495
530
|
});
|
|
@@ -530,7 +565,10 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
530
565
|
return this.entities.has(e.eid);
|
|
531
566
|
}
|
|
532
567
|
matchesQuery(e, t) {
|
|
533
|
-
return !(e.components.entity.dead ||
|
|
568
|
+
return !(e.components.entity.dead || !this.matchesComponents(e, t) || t.filter && !t.filter(e));
|
|
569
|
+
}
|
|
570
|
+
matchesComponents(e, t) {
|
|
571
|
+
return !(t.required.find((t) => !e.components[t]) || t.not?.find((t) => !!e.components[t]));
|
|
534
572
|
}
|
|
535
573
|
getQueryDelta(e) {
|
|
536
574
|
let t = this.queryDeltas[e];
|
|
@@ -549,15 +587,34 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
549
587
|
let i = this.getQueryDelta(e);
|
|
550
588
|
r ? (t.set(n.eid, n), this.markAdded(i, n)) : t.delete(n.eid) && this.markRemoved(i, n);
|
|
551
589
|
}
|
|
590
|
+
get tracksMainQuery() {
|
|
591
|
+
return !0;
|
|
592
|
+
}
|
|
552
593
|
checkAddEntity(e) {
|
|
553
|
-
let t = this.matchesQuery(e, this.options);
|
|
554
|
-
return this.updateEntityList(
|
|
594
|
+
let t = this.tracksMainQuery && this.matchesQuery(e, this.options);
|
|
595
|
+
return this.updateEntityList(F, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
555
596
|
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
556
597
|
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
557
598
|
}), t;
|
|
558
599
|
}
|
|
600
|
+
addEntities(t) {
|
|
601
|
+
if (this.checkAddEntity !== e.prototype.checkAddEntity || this.matchesQuery !== e.prototype.matchesQuery) {
|
|
602
|
+
t.entities.forEach((e) => this.checkAddEntity(e));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
this.tracksMainQuery && this.addBatchToQuery(F, this.entities, this.options, t), Object.entries(this.options.queries ?? {}).forEach(([e, n]) => {
|
|
606
|
+
let r = this.queryEntities[e] ?? (this.queryEntities[e] = /* @__PURE__ */ new Map());
|
|
607
|
+
this.addBatchToQuery(e, r, n, t);
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
addBatchToQuery(e, t, n, r) {
|
|
611
|
+
let i = this.getQueryDelta(e);
|
|
612
|
+
A(r, (e) => this.matchesComponents(e, n), (e) => {
|
|
613
|
+
e.components.entity.dead || n.filter && !n.filter(e) || (t.set(e.eid, e), this.markAdded(i, e));
|
|
614
|
+
});
|
|
615
|
+
}
|
|
559
616
|
removeEntity(e) {
|
|
560
|
-
this.updateEntityList(
|
|
617
|
+
this.updateEntityList(F, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
|
|
561
618
|
this.updateEntityList(t, n, e, !1);
|
|
562
619
|
});
|
|
563
620
|
}
|
|
@@ -572,7 +629,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
572
629
|
destroy() {
|
|
573
630
|
super.destroy(), "terminate" in this.worker && this.worker.terminate();
|
|
574
631
|
}
|
|
575
|
-
},
|
|
632
|
+
}, L = class extends O.default {
|
|
576
633
|
eid;
|
|
577
634
|
config;
|
|
578
635
|
world;
|
|
@@ -593,7 +650,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
593
650
|
}
|
|
594
651
|
loadComponent(e, t, n = !0) {
|
|
595
652
|
this.assertComponentAllowed(e);
|
|
596
|
-
let r = this.world.registry[e], i = r.memoryComponent, a = i.create(r.toBlock(t, this)), o = r.attach(this, i, a);
|
|
653
|
+
let r = this.world.registry[e], i = r.memoryComponent, a = i.create(r.toBlock(t, this)), o = r.attach(this, i, a, t);
|
|
597
654
|
return o.block ??= i.getBlock(a), this.components[e] = o, n && this.emit("component-added", e, o), o;
|
|
598
655
|
}
|
|
599
656
|
attachComponent(e, t, n = !1) {
|
|
@@ -673,11 +730,12 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
673
730
|
assertComponentPropertyMutable(e, t) {
|
|
674
731
|
if (e === "entity" && (t === "type" || t === "class")) throw Error(`Entity ${t} is immutable`);
|
|
675
732
|
}
|
|
676
|
-
},
|
|
733
|
+
}, R = class e {
|
|
677
734
|
world;
|
|
678
735
|
configs;
|
|
679
736
|
classes;
|
|
680
737
|
allowedComponents = /* @__PURE__ */ new Map();
|
|
738
|
+
forbiddenProperties = /* @__PURE__ */ new Map();
|
|
681
739
|
constructor(e = {}, t = {}) {
|
|
682
740
|
this.configs = e, this.classes = t;
|
|
683
741
|
for (let e of Object.keys(t)) this.allowedComponents.set(e, new Set(t[e].components));
|
|
@@ -686,10 +744,10 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
686
744
|
this.world && this.validateTemplate(e, t), this.configs[e] = t;
|
|
687
745
|
}
|
|
688
746
|
setWorld(e) {
|
|
689
|
-
this.world = e;
|
|
747
|
+
this.world = e, this.forbiddenProperties.clear();
|
|
690
748
|
for (let t of Object.keys(this.classes)) {
|
|
691
749
|
let n = this.classes[t].entity;
|
|
692
|
-
if (n !==
|
|
750
|
+
if (n !== L && !(n.prototype instanceof L)) throw Error(`Entity class ${t} must extend BaseEntity`);
|
|
693
751
|
for (let n of this.classes[t].components) if (n === "entity" || !(n in e.registry)) throw Error(`Entity class ${t} contains unknown or reserved component ${n}`);
|
|
694
752
|
}
|
|
695
753
|
for (let e of Object.keys(this.configs)) this.validateTemplate(e, this.configs[e]);
|
|
@@ -706,16 +764,16 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
706
764
|
} : e;
|
|
707
765
|
return this.hasClasses && n && this.validateResolvedConfig(n, i), i;
|
|
708
766
|
}
|
|
709
|
-
loadEntity(
|
|
710
|
-
let
|
|
711
|
-
this.hasClasses &&
|
|
712
|
-
let
|
|
713
|
-
return this.world.addEntity(
|
|
767
|
+
loadEntity(t, n = !0) {
|
|
768
|
+
let r = t.type, i = this.getConfig(t);
|
|
769
|
+
this.hasClasses && r && this.getConfig !== e.prototype.getConfig && this.validateResolvedConfig(r, i);
|
|
770
|
+
let a = this.getClassDefinition(i), o = a ? this.constructEntity(a, i) : this.createEntity(i);
|
|
771
|
+
return this.world.addEntity(o, n);
|
|
714
772
|
}
|
|
715
773
|
createAdoptedEntity(e, t, n) {
|
|
716
774
|
if (!t) {
|
|
717
775
|
if (this.hasClasses) throw Error(`Entity type ${e} has no class`);
|
|
718
|
-
return new
|
|
776
|
+
return new L(this.world, void 0, n);
|
|
719
777
|
}
|
|
720
778
|
let r = this.classes[t];
|
|
721
779
|
if (!r) throw Error(`Unknown entity class: ${t}`);
|
|
@@ -741,7 +799,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
741
799
|
return e ? this.getAllowedComponents(e) : void 0;
|
|
742
800
|
}
|
|
743
801
|
createEntity(e) {
|
|
744
|
-
return new
|
|
802
|
+
return new L(this.world, e);
|
|
745
803
|
}
|
|
746
804
|
get hasClasses() {
|
|
747
805
|
return this.allowedComponents.size > 0;
|
|
@@ -781,6 +839,21 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
781
839
|
if (!n || n.class !== t) throw Error(`Entity type ${e} does not belong to class ${t}`);
|
|
782
840
|
}
|
|
783
841
|
validateComponentTriggers(e, t, n) {
|
|
842
|
+
let r = this.getForbiddenProperties(t);
|
|
843
|
+
for (let i in n) r.has(i) && this.throwComponentTriggerError(e, t, n);
|
|
844
|
+
}
|
|
845
|
+
getForbiddenProperties(e) {
|
|
846
|
+
let t = this.forbiddenProperties.get(e);
|
|
847
|
+
if (!t) {
|
|
848
|
+
let n = this.allowedComponents.get(e), r = /* @__PURE__ */ new Set();
|
|
849
|
+
for (let e of n) for (let t of this.world.registry[e].loadProperties) r.add(t);
|
|
850
|
+
let i = /* @__PURE__ */ new Set();
|
|
851
|
+
for (let e of Object.keys(this.world.registry)) if (!(e === "entity" || n.has(e))) for (let t of this.world.registry[e].loadProperties) r.has(t) || i.add(t);
|
|
852
|
+
t = i, this.forbiddenProperties.set(e, t);
|
|
853
|
+
}
|
|
854
|
+
return t;
|
|
855
|
+
}
|
|
856
|
+
throwComponentTriggerError(e, t, n) {
|
|
784
857
|
let r = this.allowedComponents.get(t), i = /* @__PURE__ */ new Set();
|
|
785
858
|
for (let e of r) for (let t of this.world.registry[e].loadProperties) i.add(t);
|
|
786
859
|
let a = n;
|
|
@@ -789,8 +862,9 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
789
862
|
let o = this.world.registry[n].loadProperties.find((e) => e in a && !i.has(e));
|
|
790
863
|
if (o) throw Error(`Entity type ${e} class ${t} cannot load component ${n} from property ${o}`);
|
|
791
864
|
}
|
|
865
|
+
throw Error(`Entity type ${e} class ${t} loads a component outside its class`);
|
|
792
866
|
}
|
|
793
|
-
},
|
|
867
|
+
}, z = y, B = 1e4, V = class extends O.default {
|
|
794
868
|
heap;
|
|
795
869
|
constantStrings;
|
|
796
870
|
eidCounter;
|
|
@@ -804,6 +878,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
804
878
|
paused = !1;
|
|
805
879
|
destroyed = !1;
|
|
806
880
|
pristine = !0;
|
|
881
|
+
isBulkLoading = !1;
|
|
807
882
|
activeFreeBuffer = {
|
|
808
883
|
frees: [],
|
|
809
884
|
waitingSystems: /* @__PURE__ */ new Set(),
|
|
@@ -815,7 +890,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
815
890
|
waitElapsed: 0
|
|
816
891
|
};
|
|
817
892
|
constructor(t, n = {}) {
|
|
818
|
-
super(), this.heap = new v({ bufferSize: n.heapSize ??
|
|
893
|
+
super(), this.heap = new v({ bufferSize: n.heapSize ?? z }), this.constantStrings = new e(this.heap), this.eidCounter = this.heap.allocUI32(1), this.heap.addOnGrowBufferHandlers((e) => this.emit("grow-buffer", e));
|
|
819
894
|
let r = {
|
|
820
895
|
...t,
|
|
821
896
|
entity: i
|
|
@@ -827,7 +902,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
827
902
|
memoryComponent: new _(this.heap, t.type, t.size)
|
|
828
903
|
};
|
|
829
904
|
}
|
|
830
|
-
this.registry = a, this.factory = n.factory ?? new
|
|
905
|
+
this.registry = a, this.factory = n.factory ?? new R(), this.factory.setWorld(this);
|
|
831
906
|
}
|
|
832
907
|
allocateEid() {
|
|
833
908
|
return Atomics.add(this.eidCounter.data, 0, 1) + 1;
|
|
@@ -844,7 +919,7 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
844
919
|
this.heap.buffers[e.bufferPosition] === void 0 && this.heap.addSharedBuffer(e), this.emit("grow-buffer", e);
|
|
845
920
|
}
|
|
846
921
|
get needsSpareBuffer() {
|
|
847
|
-
return this.systems.some((e) => e instanceof
|
|
922
|
+
return this.systems.some((e) => e instanceof I && e.isWorkerThread && (!!e.options.createsEntities || !!e.options.addsComponents));
|
|
848
923
|
}
|
|
849
924
|
async init() {
|
|
850
925
|
await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
|
|
@@ -891,11 +966,17 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
891
966
|
}
|
|
892
967
|
for (let e of Object.keys(this.factory.configs)) this.constantStrings.getOrCreate(e);
|
|
893
968
|
for (let e of Object.keys(this.factory.classes)) this.constantStrings.getOrCreate(e);
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
this.
|
|
897
|
-
|
|
898
|
-
|
|
969
|
+
this.isBulkLoading = !0;
|
|
970
|
+
try {
|
|
971
|
+
let t = e.entities.map((e) => this.loadEntity(e, !1));
|
|
972
|
+
for (let e of t) e.finishLoading(), this.emit("entity-added", e), e.on("death", () => {
|
|
973
|
+
this.onEntityDied(e);
|
|
974
|
+
});
|
|
975
|
+
} finally {
|
|
976
|
+
this.isBulkLoading = !1;
|
|
977
|
+
}
|
|
978
|
+
let t = H(this.entities.values());
|
|
979
|
+
this.systems.forEach((e) => e.addEntities(t)), this.gameTime = e.gameTime ?? 0, this.playerTime = e.playerTime ?? 0, this.timeScale = e.timeScale ?? 1, this.finishLoadingSystems();
|
|
899
980
|
}
|
|
900
981
|
async clear() {
|
|
901
982
|
if (!this.pristine) {
|
|
@@ -961,9 +1042,9 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
961
1042
|
}
|
|
962
1043
|
checkFreeBufferTimeout(e) {
|
|
963
1044
|
let t = this.activeFreeBuffer;
|
|
964
|
-
if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >=
|
|
1045
|
+
if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >= B)) {
|
|
965
1046
|
let e = Array.from(t.waitingSystems).map((e) => e.name).join(", ");
|
|
966
|
-
console.warn(`shared-memory-ecs: deferred component free waited over ${
|
|
1047
|
+
console.warn(`shared-memory-ecs: deferred component free waited over ${B}ms on system(s): ${e}; freeing anyway`), t.waitingSystems.clear(), this.processFreeBuffers();
|
|
967
1048
|
}
|
|
968
1049
|
}
|
|
969
1050
|
addSystem(e) {
|
|
@@ -1016,13 +1097,13 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
1016
1097
|
this.paused = !1;
|
|
1017
1098
|
}
|
|
1018
1099
|
addEntityToEntityWorkerSystem(e, t) {
|
|
1019
|
-
this.systems.forEach((n) => {
|
|
1020
|
-
(n instanceof
|
|
1100
|
+
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1101
|
+
(n instanceof M && n.options.components?.includes(t) || n instanceof I && this.componentAffectsEntityWorkerSystem(n, t)) && n.checkAddEntity(e);
|
|
1021
1102
|
});
|
|
1022
1103
|
}
|
|
1023
1104
|
removeEntityFromEntityWorkerSystem(e, t) {
|
|
1024
|
-
this.systems.forEach((n) => {
|
|
1025
|
-
n instanceof
|
|
1105
|
+
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1106
|
+
n instanceof M && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof I && this.componentAffectsEntityWorkerSystem(n, t) && n.checkAddEntity(e);
|
|
1026
1107
|
});
|
|
1027
1108
|
}
|
|
1028
1109
|
componentAffectsEntityWorkerSystem(e, t) {
|
|
@@ -1035,29 +1116,41 @@ var b = Object.create, x = Object.defineProperty, S = Object.getOwnPropertyDescr
|
|
|
1035
1116
|
}), !0);
|
|
1036
1117
|
}
|
|
1037
1118
|
};
|
|
1119
|
+
function H(e) {
|
|
1120
|
+
let t = {
|
|
1121
|
+
entities: [],
|
|
1122
|
+
groupIndexes: [],
|
|
1123
|
+
groups: []
|
|
1124
|
+
}, n = /* @__PURE__ */ new Map();
|
|
1125
|
+
for (let r of e) {
|
|
1126
|
+
let e = Object.keys(r.components).sort().join(","), i = n.get(e);
|
|
1127
|
+
i === void 0 && (i = t.groups.push(r) - 1, n.set(e, i)), t.entities.push(r), t.groupIndexes.push(i);
|
|
1128
|
+
}
|
|
1129
|
+
return t;
|
|
1130
|
+
}
|
|
1038
1131
|
//#endregion
|
|
1039
1132
|
//#region src/entity-class.ts
|
|
1040
|
-
function
|
|
1133
|
+
function U(e, t) {
|
|
1041
1134
|
return t;
|
|
1042
1135
|
}
|
|
1043
|
-
function
|
|
1136
|
+
function W(e, t) {
|
|
1044
1137
|
return t;
|
|
1045
1138
|
}
|
|
1046
1139
|
//#endregion
|
|
1047
1140
|
//#region src/actions/kill-entity.ts
|
|
1048
|
-
function
|
|
1141
|
+
function G(e) {
|
|
1049
1142
|
e.components.entity.dead = !0, e.emit("death");
|
|
1050
1143
|
}
|
|
1051
1144
|
//#endregion
|
|
1052
1145
|
//#region src/performance-timing.ts
|
|
1053
|
-
var
|
|
1146
|
+
var K = 1e3, q = {
|
|
1054
1147
|
avg: 0,
|
|
1055
1148
|
min: 0,
|
|
1056
1149
|
max: 0,
|
|
1057
1150
|
samples: 0
|
|
1058
1151
|
};
|
|
1059
|
-
function
|
|
1060
|
-
if (!e.length) return { ...
|
|
1152
|
+
function J(e) {
|
|
1153
|
+
if (!e.length) return { ...q };
|
|
1061
1154
|
let t = 0, n = Infinity, r = 0;
|
|
1062
1155
|
for (let i of e) t += i, i < n && (n = i), i > r && (r = i);
|
|
1063
1156
|
return {
|
|
@@ -1067,13 +1160,13 @@ function K(e) {
|
|
|
1067
1160
|
samples: e.length
|
|
1068
1161
|
};
|
|
1069
1162
|
}
|
|
1070
|
-
var
|
|
1163
|
+
var Y = class extends O.default {
|
|
1071
1164
|
world;
|
|
1072
1165
|
ticksBetweenUpdates;
|
|
1073
1166
|
stats = {
|
|
1074
|
-
update: { ...
|
|
1167
|
+
update: { ...q },
|
|
1075
1168
|
systems: [],
|
|
1076
|
-
events: { ...
|
|
1169
|
+
events: { ...q }
|
|
1077
1170
|
};
|
|
1078
1171
|
ticks = 0;
|
|
1079
1172
|
updateStart = 0;
|
|
@@ -1090,9 +1183,9 @@ var q = class extends O.default {
|
|
|
1090
1183
|
this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
1091
1184
|
e.run = [], e.events = [], e.eventStart = -1;
|
|
1092
1185
|
}), this.stats = {
|
|
1093
|
-
update: { ...
|
|
1186
|
+
update: { ...q },
|
|
1094
1187
|
systems: [],
|
|
1095
|
-
events: { ...
|
|
1188
|
+
events: { ...q }
|
|
1096
1189
|
};
|
|
1097
1190
|
}
|
|
1098
1191
|
destroy() {
|
|
@@ -1134,21 +1227,21 @@ var q = class extends O.default {
|
|
|
1134
1227
|
let t = this.systemTimings.get(e.name);
|
|
1135
1228
|
return {
|
|
1136
1229
|
name: e.name,
|
|
1137
|
-
run:
|
|
1138
|
-
events:
|
|
1230
|
+
run: J(t?.run ?? []),
|
|
1231
|
+
events: J(t?.events ?? [])
|
|
1139
1232
|
};
|
|
1140
|
-
}), t = { ...
|
|
1233
|
+
}), t = { ...q };
|
|
1141
1234
|
e.forEach((e) => {
|
|
1142
1235
|
t.avg += e.events.avg, t.min += e.events.min, t.max += e.events.max, t.samples += e.events.samples;
|
|
1143
1236
|
}), this.stats = {
|
|
1144
|
-
update:
|
|
1237
|
+
update: J(this.updateTimes),
|
|
1145
1238
|
systems: e,
|
|
1146
1239
|
events: t
|
|
1147
1240
|
}, this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
1148
1241
|
e.run = [], e.events = [];
|
|
1149
1242
|
}), this.emit("stats-updated", this.stats);
|
|
1150
1243
|
}
|
|
1151
|
-
},
|
|
1244
|
+
}, X = class extends I {
|
|
1152
1245
|
constructor(e, t) {
|
|
1153
1246
|
super(e, {
|
|
1154
1247
|
...t,
|
|
@@ -1156,17 +1249,14 @@ var q = class extends O.default {
|
|
|
1156
1249
|
updateFunction: u(t.updateFunction)
|
|
1157
1250
|
});
|
|
1158
1251
|
}
|
|
1159
|
-
|
|
1160
|
-
return
|
|
1161
|
-
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
1162
|
-
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
1163
|
-
}), !1;
|
|
1252
|
+
get tracksMainQuery() {
|
|
1253
|
+
return !1;
|
|
1164
1254
|
}
|
|
1165
1255
|
shouldRun() {
|
|
1166
1256
|
return !0;
|
|
1167
1257
|
}
|
|
1168
1258
|
};
|
|
1169
1259
|
//#endregion
|
|
1170
|
-
export {
|
|
1260
|
+
export { L as BaseEntity, V as BaseWorld, n as CLASS_INDEX, f as Component, e as ConstantStringCache, c as DEAD_INDEX, K as DEFAULT_TICKS_BETWEEN_UPDATES, R as EntityFactory, M as EntitySystem, P as EntitySystemWebWorker, I as EntityWorkerSystem, j as IterableSystem, _ as MemoryComponent, Y as PerformanceTiming, g as STATIC_INDEX, k as System, r as TYPE_INDEX, N as WebWorker, X as WorkerSystem, t as addComponentWorker, p as createEntitySystemWorker, d as createEntityWorker, h as createSystemWorker, U as defineEntityClasses, W as defineEntityConfigs, i as entityDefinition, G as killEntity, m as killEntityWorker, s as removeComponentWorker };
|
|
1171
1261
|
|
|
1172
1262
|
//# sourceMappingURL=index.js.map
|