@daneren2005/shared-memory-ecs 1.5.1 → 1.6.0
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 +104 -28
- package/dist/actions/build-worker-entity.d.ts +1 -1
- package/dist/actions/create-entity-worker.d.ts +2 -2
- package/dist/actions/kill-entity-worker.d.ts +2 -2
- package/dist/component-definition.d.ts +2 -0
- package/dist/{create-component-worker-BM942gjg.js → create-system-worker-BM5E-S92.js} +13 -4
- package/dist/create-system-worker-BM5E-S92.js.map +1 -0
- package/dist/entity.d.ts +1 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +130 -92
- package/dist/index.js.map +1 -1
- package/dist/systems/{component-system.d.ts → entity-worker-system.d.ts} +20 -18
- package/dist/systems/system.d.ts +1 -1
- package/dist/systems/worker-system.d.ts +22 -0
- package/dist/systems/workers/apply-query-delta.d.ts +1 -1
- package/dist/systems/workers/create-entity-system-worker.d.ts +8 -0
- package/dist/systems/workers/create-system-worker.d.ts +9 -0
- package/dist/systems/workers/entity-system-web-worker.d.ts +17 -0
- package/dist/systems/workers/{component-worker-message.d.ts → entity-system-worker-message.d.ts} +4 -4
- package/dist/worker.d.ts +7 -5
- package/dist/worker.js +2 -2
- package/dist/world.d.ts +4 -4
- package/package.json +2 -1
- package/dist/create-component-worker-BM942gjg.js.map +0 -1
- package/dist/systems/workers/component-web-worker.d.ts +0 -17
- package/dist/systems/workers/create-component-worker.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i, l as a,
|
|
2
|
-
import
|
|
3
|
-
import { MAX_BYTE_OFFSET_LENGTH as
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./create-system-worker-BM5E-S92.js";
|
|
2
|
+
import m from "@daneren2005/shared-memory-objects/memory-heap";
|
|
3
|
+
import { MAX_BYTE_OFFSET_LENGTH as h } from "@daneren2005/shared-memory-objects/utils/pointer";
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
|
-
var
|
|
6
|
-
if (t && typeof t == "object" || typeof t == "function") for (var i =
|
|
5
|
+
var g = Object.create, _ = Object.defineProperty, v = Object.getOwnPropertyDescriptor, y = Object.getOwnPropertyNames, b = Object.getPrototypeOf, x = Object.prototype.hasOwnProperty, S = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), C = (e, t, n, r) => {
|
|
6
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = y(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !x.call(e, s) && s !== n && _(e, s, {
|
|
7
7
|
get: ((e) => t[e]).bind(null, s),
|
|
8
|
-
enumerable: !(r =
|
|
8
|
+
enumerable: !(r = v(t, s)) || r.enumerable
|
|
9
9
|
});
|
|
10
10
|
return e;
|
|
11
|
-
},
|
|
11
|
+
}, w = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : g(b(e)), C(t || !e || !e.__esModule ? _(n, "default", {
|
|
12
12
|
value: e,
|
|
13
13
|
enumerable: !0
|
|
14
|
-
}) : n, e)))((/* @__PURE__ */
|
|
14
|
+
}) : n, e)))((/* @__PURE__ */ S(((e, t) => {
|
|
15
15
|
var n = Object.prototype.hasOwnProperty, r = "~";
|
|
16
16
|
function i() {}
|
|
17
17
|
Object.create && (i.prototype = Object.create(null), new i().__proto__ || (r = !1));
|
|
@@ -98,10 +98,11 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
98
98
|
var t;
|
|
99
99
|
return e ? (t = r ? r + e : e, this._events[t] && s(this, t)) : (this._events = new i(), this._eventsCount = 0), this;
|
|
100
100
|
}, c.prototype.off = c.prototype.removeListener, c.prototype.addListener = c.prototype.on, c.prefixed = r, c.EventEmitter = c, t !== void 0 && (t.exports = c);
|
|
101
|
-
})))(), 1),
|
|
101
|
+
})))(), 1), T = class extends w.default {
|
|
102
102
|
eid;
|
|
103
103
|
config;
|
|
104
104
|
world;
|
|
105
|
+
componentMemoryDeletionScheduled = !1;
|
|
105
106
|
components = {};
|
|
106
107
|
constructor(e, t, n) {
|
|
107
108
|
super(), this.world = e, this.eid = n ?? e.allocateEid(), n === void 0 && (this.loadComponent("entity", t ?? {}, !1), t && this.load(t));
|
|
@@ -115,6 +116,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
115
116
|
return r.block ??= n.memoryComponent.getBlock(t), this.components[e] = r, r;
|
|
116
117
|
}
|
|
117
118
|
removeComponent(e) {
|
|
119
|
+
if (this.componentMemoryDeletionScheduled) return;
|
|
118
120
|
let t = this.components[e];
|
|
119
121
|
if (t) {
|
|
120
122
|
let n = this.world.registry[e];
|
|
@@ -134,6 +136,8 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
134
136
|
n && (delete n[t], this.emit("component-property-deleted", e, t));
|
|
135
137
|
}
|
|
136
138
|
deleteAllComponentMemory() {
|
|
139
|
+
if (this.componentMemoryDeletionScheduled) return;
|
|
140
|
+
this.componentMemoryDeletionScheduled = !0;
|
|
137
141
|
let e = this.world.registry, t = this.components;
|
|
138
142
|
for (let n of Object.keys(t)) {
|
|
139
143
|
let r = e[n], i = t[n];
|
|
@@ -167,7 +171,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
167
171
|
i.loadInFinishLoading && i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
|
-
},
|
|
174
|
+
}, E = class extends w.default {
|
|
171
175
|
world;
|
|
172
176
|
name;
|
|
173
177
|
currentDelta = 0;
|
|
@@ -211,7 +215,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
211
215
|
destroy() {
|
|
212
216
|
this.removeAllListeners();
|
|
213
217
|
}
|
|
214
|
-
},
|
|
218
|
+
}, D = class extends E {
|
|
215
219
|
remainingInstancesToRun = [];
|
|
216
220
|
remainingInstancesStartTime = null;
|
|
217
221
|
iterationsPerCheck;
|
|
@@ -261,7 +265,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
261
265
|
}
|
|
262
266
|
beforeRunIterables() {}
|
|
263
267
|
getIterableEntityId(e) {}
|
|
264
|
-
},
|
|
268
|
+
}, O = class extends D {
|
|
265
269
|
entities = /* @__PURE__ */ new Map();
|
|
266
270
|
options;
|
|
267
271
|
constructor(e, t = { name: "EntitySystem" }) {
|
|
@@ -280,7 +284,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
280
284
|
}), e;
|
|
281
285
|
}
|
|
282
286
|
updateIterable(e, t) {
|
|
283
|
-
e.components.entity.dead || this.updateEntity(e, t);
|
|
287
|
+
e.components.entity.dead || this.entities.get(e.eid) !== e || this.updateEntity(e, t);
|
|
284
288
|
}
|
|
285
289
|
filterEntity(e) {
|
|
286
290
|
return !e.components.entity.isStatic;
|
|
@@ -298,11 +302,11 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
298
302
|
this.entities.delete(e.eid);
|
|
299
303
|
}
|
|
300
304
|
shouldRun() {
|
|
301
|
-
return this.entities.size > 0;
|
|
305
|
+
return this.isCurrentlyRunning() || this.entities.size > 0;
|
|
302
306
|
}
|
|
303
|
-
},
|
|
307
|
+
}, k = class {
|
|
304
308
|
onmessage(e, t = []) {}
|
|
305
|
-
},
|
|
309
|
+
}, A = class extends k {
|
|
306
310
|
updateFunction;
|
|
307
311
|
entities = [];
|
|
308
312
|
queryEntities = {};
|
|
@@ -325,91 +329,91 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
325
329
|
else if (e.type === "run") {
|
|
326
330
|
if (this.worldExtension && Object.assign(e.world, this.worldExtension), e.world.getString = (e) => this.world.constantStrings.getString(e) ?? "", e.world.heap = this.world.heap, e.world.allocate = this.allocator, this.createsEntities) {
|
|
327
331
|
let t = this.world.registry;
|
|
328
|
-
e.world.buildEntityDescriptor = (e) =>
|
|
332
|
+
e.world.buildEntityDescriptor = (e) => n(e, this.world.factory.configs, t, this.allocator);
|
|
329
333
|
}
|
|
330
|
-
let t = performance.now(),
|
|
331
|
-
this.entities =
|
|
332
|
-
let
|
|
334
|
+
let t = performance.now(), i = [], a = {}, o = [], s = [];
|
|
335
|
+
this.entities = r(this.entities, e.entities);
|
|
336
|
+
let c = {};
|
|
333
337
|
Object.entries(e.queries).forEach(([e, t]) => {
|
|
334
|
-
let n =
|
|
335
|
-
this.queryEntities[e] = n,
|
|
338
|
+
let n = r(this.queryEntities[e] ?? [], t);
|
|
339
|
+
this.queryEntities[e] = n, c[e] = n;
|
|
336
340
|
});
|
|
337
|
-
let
|
|
338
|
-
entityComponentChanged(e, t,
|
|
339
|
-
|
|
341
|
+
let l = {
|
|
342
|
+
entityComponentChanged(e, t, n, r) {
|
|
343
|
+
i.push({
|
|
340
344
|
entityId: e,
|
|
341
345
|
event: "component-property-updated",
|
|
342
346
|
args: [
|
|
343
347
|
t,
|
|
344
|
-
|
|
345
|
-
|
|
348
|
+
n,
|
|
349
|
+
r
|
|
346
350
|
]
|
|
347
351
|
});
|
|
348
352
|
},
|
|
349
|
-
emitEntityEvent(e, t, ...
|
|
350
|
-
|
|
353
|
+
emitEntityEvent(e, t, ...n) {
|
|
354
|
+
i.push({
|
|
351
355
|
entityId: e,
|
|
352
356
|
event: t,
|
|
353
|
-
args:
|
|
357
|
+
args: n
|
|
354
358
|
});
|
|
355
359
|
},
|
|
356
360
|
emitSystemEvent(e, t) {
|
|
357
|
-
(
|
|
361
|
+
(a[e] ?? (a[e] = [])).push(t);
|
|
358
362
|
},
|
|
359
363
|
entityDied(e) {
|
|
360
|
-
|
|
364
|
+
i.push({
|
|
361
365
|
entityId: e,
|
|
362
366
|
event: "death",
|
|
363
367
|
args: []
|
|
364
368
|
});
|
|
365
369
|
},
|
|
366
370
|
createEntity(e) {
|
|
367
|
-
|
|
371
|
+
o.push(e);
|
|
368
372
|
}
|
|
369
|
-
},
|
|
373
|
+
}, u = !1;
|
|
370
374
|
if (this.updateFunction.preRun) try {
|
|
371
|
-
this.updateFunction.preRun(e.world, this.entities,
|
|
375
|
+
this.updateFunction.preRun(e.world, this.entities, c, l);
|
|
372
376
|
} catch (e) {
|
|
373
|
-
|
|
377
|
+
u = !0, s.push({
|
|
374
378
|
error: e,
|
|
375
379
|
phase: "preRun"
|
|
376
380
|
});
|
|
377
381
|
}
|
|
378
|
-
if (
|
|
382
|
+
if (u || this.entities.forEach((t) => {
|
|
379
383
|
try {
|
|
380
|
-
this.updateFunction(e.world, t.entityId, t.components,
|
|
384
|
+
this.updateFunction(e.world, t.entityId, t.components, c, l);
|
|
381
385
|
} catch (e) {
|
|
382
|
-
|
|
386
|
+
s.push({
|
|
383
387
|
error: e,
|
|
384
388
|
phase: "update",
|
|
385
389
|
entityId: t.entityId
|
|
386
390
|
});
|
|
387
391
|
}
|
|
388
392
|
}), this.updateFunction.entityRemoved) for (let t of e.entities.removed) try {
|
|
389
|
-
this.updateFunction.entityRemoved(e.world, t,
|
|
393
|
+
this.updateFunction.entityRemoved(e.world, t, l);
|
|
390
394
|
} catch (e) {
|
|
391
|
-
|
|
395
|
+
s.push({
|
|
392
396
|
error: e,
|
|
393
397
|
phase: "entityRemoved",
|
|
394
398
|
entityId: t
|
|
395
399
|
});
|
|
396
400
|
}
|
|
397
|
-
let
|
|
401
|
+
let d = performance.now() - t;
|
|
398
402
|
this.onMessageTyped({
|
|
399
403
|
type: "run-complete",
|
|
400
404
|
generation: e.generation,
|
|
401
|
-
runTime:
|
|
402
|
-
events:
|
|
403
|
-
systemEvents:
|
|
404
|
-
created:
|
|
405
|
-
errors:
|
|
405
|
+
runTime: d,
|
|
406
|
+
events: i,
|
|
407
|
+
systemEvents: a,
|
|
408
|
+
created: o,
|
|
409
|
+
errors: s
|
|
406
410
|
});
|
|
407
411
|
}
|
|
408
412
|
}
|
|
409
413
|
onMessageTyped(e) {
|
|
410
414
|
this.onmessage({ data: e });
|
|
411
415
|
}
|
|
412
|
-
},
|
|
416
|
+
}, j = "___main", M = class extends E {
|
|
413
417
|
entities = /* @__PURE__ */ new Map();
|
|
414
418
|
options;
|
|
415
419
|
worker;
|
|
@@ -436,7 +440,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
436
440
|
type: "grow-buffer",
|
|
437
441
|
buffer: e
|
|
438
442
|
});
|
|
439
|
-
})) : (this.worker = new
|
|
443
|
+
})) : (this.worker = new A(t.updateFunction, e, !!t.createsEntities), this.isWorkerThread = !1), this.initWorker();
|
|
440
444
|
}
|
|
441
445
|
initWorker() {
|
|
442
446
|
this.worker.onmessage = (e) => {
|
|
@@ -525,7 +529,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
525
529
|
elapsedTime: e
|
|
526
530
|
};
|
|
527
531
|
this.addDataToWorld?.(t), this.isRunning = !0;
|
|
528
|
-
let n = this.buildQueryDelta(
|
|
532
|
+
let n = this.buildQueryDelta(j, this.options), r = {};
|
|
529
533
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
530
534
|
r[e] = this.buildQueryDelta(e, t);
|
|
531
535
|
});
|
|
@@ -587,13 +591,13 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
587
591
|
}
|
|
588
592
|
checkAddEntity(e) {
|
|
589
593
|
let t = this.matchesQuery(e, this.options);
|
|
590
|
-
return this.updateEntityList(
|
|
594
|
+
return this.updateEntityList(j, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
591
595
|
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
592
596
|
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
593
597
|
}), t;
|
|
594
598
|
}
|
|
595
599
|
removeEntity(e) {
|
|
596
|
-
this.updateEntityList(
|
|
600
|
+
this.updateEntityList(j, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
|
|
597
601
|
this.updateEntityList(t, n, e, !1);
|
|
598
602
|
});
|
|
599
603
|
}
|
|
@@ -608,7 +612,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
608
612
|
destroy() {
|
|
609
613
|
super.destroy(), "terminate" in this.worker && this.worker.terminate();
|
|
610
614
|
}
|
|
611
|
-
},
|
|
615
|
+
}, N = class {
|
|
612
616
|
world;
|
|
613
617
|
configs;
|
|
614
618
|
constructor(e = {}) {
|
|
@@ -629,9 +633,9 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
629
633
|
return this.world.addEntity(n, t);
|
|
630
634
|
}
|
|
631
635
|
createEntity(e) {
|
|
632
|
-
return new
|
|
636
|
+
return new T(this.world, e);
|
|
633
637
|
}
|
|
634
|
-
},
|
|
638
|
+
}, P = h, F = 1e4, I = class extends w.default {
|
|
635
639
|
heap;
|
|
636
640
|
constantStrings;
|
|
637
641
|
eidCounter;
|
|
@@ -656,19 +660,19 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
656
660
|
waitElapsed: 0
|
|
657
661
|
};
|
|
658
662
|
constructor(e, t = {}) {
|
|
659
|
-
super(), this.heap = new
|
|
660
|
-
let
|
|
663
|
+
super(), this.heap = new m({ bufferSize: t.heapSize ?? P }), this.constantStrings = new l(this.heap), this.eidCounter = this.heap.allocUI32(1), this.heap.addOnGrowBufferHandlers((e) => this.emit("grow-buffer", e));
|
|
664
|
+
let n = {
|
|
661
665
|
...e,
|
|
662
|
-
entity:
|
|
663
|
-
},
|
|
664
|
-
for (let e of Object.keys(
|
|
665
|
-
let t =
|
|
666
|
-
|
|
666
|
+
entity: a
|
|
667
|
+
}, r = {};
|
|
668
|
+
for (let e of Object.keys(n)) {
|
|
669
|
+
let t = n[e];
|
|
670
|
+
r[e] = {
|
|
667
671
|
...t,
|
|
668
|
-
memoryComponent: new
|
|
672
|
+
memoryComponent: new o(this.heap, t.type, t.size)
|
|
669
673
|
};
|
|
670
674
|
}
|
|
671
|
-
this.registry =
|
|
675
|
+
this.registry = r, this.factory = t.factory ?? new N(), this.factory.world = this;
|
|
672
676
|
}
|
|
673
677
|
allocateEid() {
|
|
674
678
|
return Atomics.add(this.eidCounter.data, 0, 1) + 1;
|
|
@@ -685,7 +689,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
685
689
|
this.heap.buffers[e.bufferPosition] === void 0 && this.heap.addSharedBuffer(e), this.emit("grow-buffer", e);
|
|
686
690
|
}
|
|
687
691
|
get needsSpareBuffer() {
|
|
688
|
-
return this.systems.some((e) => e instanceof
|
|
692
|
+
return this.systems.some((e) => e instanceof M && e.isWorkerThread && !!e.options.createsEntities);
|
|
689
693
|
}
|
|
690
694
|
async init() {
|
|
691
695
|
await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
|
|
@@ -695,9 +699,9 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
695
699
|
}
|
|
696
700
|
addEntity(e, t = !0) {
|
|
697
701
|
return this.entities.set(e.eid, e), e.world = this, this.pristine = !1, e.on("component-added", (t) => {
|
|
698
|
-
this.
|
|
702
|
+
this.addEntityToEntityWorkerSystem(e, t);
|
|
699
703
|
}), e.on("component-removed", (t) => {
|
|
700
|
-
this.
|
|
704
|
+
this.removeEntityFromEntityWorkerSystem(e, t);
|
|
701
705
|
}), t && (e.finishLoading(), this.emit("entity-added", e), e.on("death", () => {
|
|
702
706
|
this.onEntityDied(e);
|
|
703
707
|
})), e;
|
|
@@ -706,7 +710,7 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
706
710
|
return this.factory.loadEntity(e, t);
|
|
707
711
|
}
|
|
708
712
|
adoptEntity(e) {
|
|
709
|
-
let t = new
|
|
713
|
+
let t = new T(this, void 0, e.eid);
|
|
710
714
|
t.loadComponent("entity", {
|
|
711
715
|
type: e.type,
|
|
712
716
|
isStatic: e.isStatic
|
|
@@ -728,15 +732,32 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
728
732
|
}
|
|
729
733
|
async clear() {
|
|
730
734
|
if (!this.pristine) {
|
|
735
|
+
await Promise.all(this.systems.map((e) => e.waitForRunToComplete()).filter((e) => e instanceof Promise));
|
|
731
736
|
for (let e of Array.from(this.entities.values())) this.removeEntity(e);
|
|
732
|
-
this.systems.forEach((e) => e.clear()),
|
|
737
|
+
this.systems.forEach((e) => e.clear()), this.freeAllPendingBuffers(), this.pristine = !0;
|
|
733
738
|
}
|
|
734
739
|
}
|
|
735
740
|
removeEntity(e) {
|
|
736
|
-
this.entities.
|
|
741
|
+
this.entities.get(e.eid) === e && (this.entities.delete(e.eid), this.emit("entity-removed", e), e.deleteAllComponentMemory());
|
|
737
742
|
}
|
|
738
743
|
onEntityDied(e) {
|
|
739
|
-
this.
|
|
744
|
+
if (this.entities.get(e.eid) !== e) return;
|
|
745
|
+
let t = this.registry, n = e.components;
|
|
746
|
+
for (let r of Object.keys(n)) {
|
|
747
|
+
let i = t[r], a = n[r];
|
|
748
|
+
if (i?.died && a) try {
|
|
749
|
+
i.died(a, e, this);
|
|
750
|
+
} catch (t) {
|
|
751
|
+
let n = t;
|
|
752
|
+
console.error(`Error in died hook for component ${String(r)} (entity ${e.eid}): ${n.message}`, n), this.emit("system-error", {
|
|
753
|
+
system: String(r),
|
|
754
|
+
error: n,
|
|
755
|
+
entityId: e.eid,
|
|
756
|
+
phase: "died"
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
this.emit("entity-died", e), this.removeEntity(e);
|
|
740
761
|
}
|
|
741
762
|
getEntityByEid(e) {
|
|
742
763
|
return this.entities.get(e);
|
|
@@ -773,9 +794,9 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
773
794
|
}
|
|
774
795
|
checkFreeBufferTimeout(e) {
|
|
775
796
|
let t = this.activeFreeBuffer;
|
|
776
|
-
if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >=
|
|
797
|
+
if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >= F)) {
|
|
777
798
|
let e = Array.from(t.waitingSystems).map((e) => e.name).join(", ");
|
|
778
|
-
console.warn(`shared-memory-ecs: deferred component free waited over ${
|
|
799
|
+
console.warn(`shared-memory-ecs: deferred component free waited over ${F}ms on system(s): ${e}; freeing anyway`), t.waitingSystems.clear(), this.processFreeBuffers();
|
|
779
800
|
}
|
|
780
801
|
}
|
|
781
802
|
addSystem(e) {
|
|
@@ -827,17 +848,17 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
827
848
|
resume() {
|
|
828
849
|
this.paused = !1;
|
|
829
850
|
}
|
|
830
|
-
|
|
851
|
+
addEntityToEntityWorkerSystem(e, t) {
|
|
831
852
|
this.systems.forEach((n) => {
|
|
832
|
-
(n instanceof
|
|
853
|
+
(n instanceof O && n.options.components?.includes(t) || n instanceof M && this.componentAffectsEntityWorkerSystem(n, t)) && n.checkAddEntity(e);
|
|
833
854
|
});
|
|
834
855
|
}
|
|
835
|
-
|
|
856
|
+
removeEntityFromEntityWorkerSystem(e, t) {
|
|
836
857
|
this.systems.forEach((n) => {
|
|
837
|
-
n instanceof
|
|
858
|
+
n instanceof O && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof M && this.componentAffectsEntityWorkerSystem(n, t) && n.checkAddEntity(e);
|
|
838
859
|
});
|
|
839
860
|
}
|
|
840
|
-
|
|
861
|
+
componentAffectsEntityWorkerSystem(e, t) {
|
|
841
862
|
let n = e.options.required.includes(t) || !!e.options.not?.includes(t) || !!e.options.optional?.includes(t), r = Object.values(e.options.queries ?? {}).some((e) => e.required.includes(t) || !!e.not?.includes(t) || !!e.optional?.includes(t));
|
|
842
863
|
return n || r;
|
|
843
864
|
}
|
|
@@ -849,19 +870,19 @@ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescr
|
|
|
849
870
|
};
|
|
850
871
|
//#endregion
|
|
851
872
|
//#region src/actions/kill-entity.ts
|
|
852
|
-
function
|
|
873
|
+
function L(e) {
|
|
853
874
|
e.components.entity.dead = !0, e.emit("death");
|
|
854
875
|
}
|
|
855
876
|
//#endregion
|
|
856
877
|
//#region src/performance-timing.ts
|
|
857
|
-
var
|
|
878
|
+
var R = 1e3, z = {
|
|
858
879
|
avg: 0,
|
|
859
880
|
min: 0,
|
|
860
881
|
max: 0,
|
|
861
882
|
samples: 0
|
|
862
883
|
};
|
|
863
|
-
function
|
|
864
|
-
if (!e.length) return { ...
|
|
884
|
+
function B(e) {
|
|
885
|
+
if (!e.length) return { ...z };
|
|
865
886
|
let t = 0, n = Infinity, r = 0;
|
|
866
887
|
for (let i of e) t += i, i < n && (n = i), i > r && (r = i);
|
|
867
888
|
return {
|
|
@@ -871,13 +892,13 @@ function R(e) {
|
|
|
871
892
|
samples: e.length
|
|
872
893
|
};
|
|
873
894
|
}
|
|
874
|
-
var
|
|
895
|
+
var V = class extends w.default {
|
|
875
896
|
world;
|
|
876
897
|
ticksBetweenUpdates;
|
|
877
898
|
stats = {
|
|
878
|
-
update: { ...
|
|
899
|
+
update: { ...z },
|
|
879
900
|
systems: [],
|
|
880
|
-
events: { ...
|
|
901
|
+
events: { ...z }
|
|
881
902
|
};
|
|
882
903
|
ticks = 0;
|
|
883
904
|
updateStart = 0;
|
|
@@ -894,9 +915,9 @@ var z = class extends S.default {
|
|
|
894
915
|
this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
895
916
|
e.run = [], e.events = [], e.eventStart = -1;
|
|
896
917
|
}), this.stats = {
|
|
897
|
-
update: { ...
|
|
918
|
+
update: { ...z },
|
|
898
919
|
systems: [],
|
|
899
|
-
events: { ...
|
|
920
|
+
events: { ...z }
|
|
900
921
|
};
|
|
901
922
|
}
|
|
902
923
|
destroy() {
|
|
@@ -938,22 +959,39 @@ var z = class extends S.default {
|
|
|
938
959
|
let t = this.systemTimings.get(e.name);
|
|
939
960
|
return {
|
|
940
961
|
name: e.name,
|
|
941
|
-
run:
|
|
942
|
-
events:
|
|
962
|
+
run: B(t?.run ?? []),
|
|
963
|
+
events: B(t?.events ?? [])
|
|
943
964
|
};
|
|
944
|
-
}), t = { ...
|
|
965
|
+
}), t = { ...z };
|
|
945
966
|
e.forEach((e) => {
|
|
946
967
|
t.avg += e.events.avg, t.min += e.events.min, t.max += e.events.max, t.samples += e.events.samples;
|
|
947
968
|
}), this.stats = {
|
|
948
|
-
update:
|
|
969
|
+
update: B(this.updateTimes),
|
|
949
970
|
systems: e,
|
|
950
971
|
events: t
|
|
951
972
|
}, this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
952
973
|
e.run = [], e.events = [];
|
|
953
974
|
}), this.emit("stats-updated", this.stats);
|
|
954
975
|
}
|
|
976
|
+
}, H = class extends M {
|
|
977
|
+
constructor(e, t) {
|
|
978
|
+
super(e, {
|
|
979
|
+
...t,
|
|
980
|
+
required: [],
|
|
981
|
+
updateFunction: s(t.updateFunction)
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
checkAddEntity(e) {
|
|
985
|
+
return Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
986
|
+
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
987
|
+
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
988
|
+
}), !1;
|
|
989
|
+
}
|
|
990
|
+
shouldRun() {
|
|
991
|
+
return !0;
|
|
992
|
+
}
|
|
955
993
|
};
|
|
956
994
|
//#endregion
|
|
957
|
-
export {
|
|
995
|
+
export { T as BaseEntity, I as BaseWorld, p as Component, l as ConstantStringCache, c as DEAD_INDEX, R as DEFAULT_TICKS_BETWEEN_UPDATES, N as EntityFactory, O as EntitySystem, A as EntitySystemWebWorker, M as EntityWorkerSystem, D as IterableSystem, o as MemoryComponent, V as PerformanceTiming, d as STATIC_INDEX, E as System, t as TYPE_INDEX, k as WebWorker, H as WorkerSystem, u as createEntitySystemWorker, i as createEntityWorker, f as createSystemWorker, a as entityDefinition, L as killEntity, e as killEntityWorker };
|
|
958
996
|
|
|
959
997
|
//# sourceMappingURL=index.js.map
|