@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
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import { MAX_BYTE_OFFSET_LENGTH as
|
|
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 ee, v as g, y as _ } from "./create-system-worker-BU5CnyVh.js";
|
|
2
|
+
import te from "@daneren2005/shared-memory-objects/memory-heap";
|
|
3
|
+
import { MAX_BYTE_OFFSET_LENGTH as v } 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 y = Object.create, b = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, re = Object.getOwnPropertyNames, ie = Object.getPrototypeOf, x = Object.prototype.hasOwnProperty, ae = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), oe = (e, t, n, r) => {
|
|
6
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = re(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !x.call(e, s) && s !== n && b(e, s, {
|
|
7
7
|
get: ((e) => t[e]).bind(null, s),
|
|
8
|
-
enumerable: !(r =
|
|
8
|
+
enumerable: !(r = ne(t, s)) || r.enumerable
|
|
9
9
|
});
|
|
10
10
|
return e;
|
|
11
|
-
},
|
|
11
|
+
}, S = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : y(ie(e)), oe(t || !e || !e.__esModule || !x.call(e, "default") ? b(n, "default", {
|
|
12
12
|
value: e,
|
|
13
13
|
enumerable: !0
|
|
14
|
-
}) : n, e)))((/* @__PURE__ */
|
|
14
|
+
}) : n, e)))((/* @__PURE__ */ ae(((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,7 +98,7 @@ var v = Object.create, y = Object.defineProperty, re = Object.getOwnPropertyDesc
|
|
|
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), C = class extends S.default {
|
|
102
102
|
world;
|
|
103
103
|
name;
|
|
104
104
|
currentDelta = 0;
|
|
@@ -174,13 +174,13 @@ var v = Object.create, y = Object.defineProperty, re = Object.getOwnPropertyDesc
|
|
|
174
174
|
this.removeAllListeners();
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
function
|
|
177
|
+
function w(e, t, n) {
|
|
178
178
|
let r = e.groups.map(t);
|
|
179
179
|
for (let t = 0; t < e.entities.length; t++) r[e.groupIndexes[t]] && n(e.entities[t]);
|
|
180
180
|
}
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region src/systems/iterable-system.ts
|
|
183
|
-
var
|
|
183
|
+
var T = class extends C {
|
|
184
184
|
remainingInstancesToRun = [];
|
|
185
185
|
remainingInstancesStartTime = null;
|
|
186
186
|
iterationsPerCheck;
|
|
@@ -230,7 +230,7 @@ var E = class extends w {
|
|
|
230
230
|
}
|
|
231
231
|
beforeRunIterables() {}
|
|
232
232
|
getIterableEntityId(e) {}
|
|
233
|
-
},
|
|
233
|
+
}, E = class e extends T {
|
|
234
234
|
entities = /* @__PURE__ */ new Map();
|
|
235
235
|
options;
|
|
236
236
|
constructor(e, t = { name: "EntitySystem" }) {
|
|
@@ -268,7 +268,7 @@ var E = class extends w {
|
|
|
268
268
|
t.entities.forEach((e) => this.onEntityAdded(e));
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
|
-
|
|
271
|
+
w(t, (e) => this.hasComponents(e), (e) => {
|
|
272
272
|
this.filterEntity(e) && (this.entities.set(e.eid, e), this.options.updateEntityOnAdd && this.updateEntity(e, 0));
|
|
273
273
|
});
|
|
274
274
|
}
|
|
@@ -300,11 +300,11 @@ var E = class extends w {
|
|
|
300
300
|
...this.reads ?? []
|
|
301
301
|
] : void 0;
|
|
302
302
|
}
|
|
303
|
-
},
|
|
303
|
+
}, D = class {
|
|
304
304
|
onmessage(e, t = []) {}
|
|
305
|
-
},
|
|
305
|
+
}, O = class extends D {
|
|
306
306
|
updateFunction;
|
|
307
|
-
entities =
|
|
307
|
+
entities = new e();
|
|
308
308
|
workState = new a();
|
|
309
309
|
queryEntities = {};
|
|
310
310
|
worldExtension;
|
|
@@ -321,76 +321,69 @@ var E = class extends w {
|
|
|
321
321
|
};
|
|
322
322
|
}
|
|
323
323
|
getString = (e) => this.world.constantStrings.getString(e) ?? "";
|
|
324
|
-
postMessage(
|
|
325
|
-
if (
|
|
326
|
-
else if (
|
|
327
|
-
this.entities
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
let n = {
|
|
331
|
-
gameTime: t.gameTime,
|
|
324
|
+
postMessage(e) {
|
|
325
|
+
if (e.type === "init") this.onMessageTyped({ type: "init-complete" });
|
|
326
|
+
else if (e.type === "load") {
|
|
327
|
+
this.entities.apply(e.entities);
|
|
328
|
+
let t = this.applyQueryDeltas(e.queries), n = {
|
|
329
|
+
gameTime: e.gameTime,
|
|
332
330
|
getString: this.getString,
|
|
333
331
|
heap: this.world.heap
|
|
334
332
|
};
|
|
335
|
-
this.worldExtension = this.updateFunction.init?.(n,
|
|
336
|
-
} else if (
|
|
337
|
-
else if (
|
|
338
|
-
if (
|
|
339
|
-
let
|
|
340
|
-
|
|
333
|
+
this.worldExtension = this.updateFunction.init?.(n, e.data, this.entities.entries, t) ?? void 0, this.onMessageTyped({ type: "loaded" });
|
|
334
|
+
} else if (e.type === "reset") this.workState.clear(), this.entities.clear(), this.queryEntities = {};
|
|
335
|
+
else if (e.type === "run") {
|
|
336
|
+
if (e.world = this.workState.getWorld(e.world, e.workBatch), this.worldExtension && Object.assign(e.world, this.worldExtension), e.world.getString = this.getString, e.world.heap = this.world.heap, e.world.allocate = this.allocator, this.createsEntities) {
|
|
337
|
+
let t = this.world.registry;
|
|
338
|
+
e.world.buildEntityDescriptor = (e) => o(e, this.world.factory.configs, t, this.allocator, this.world.factory.getWorkerClasses());
|
|
341
339
|
}
|
|
342
340
|
if (this.addsComponents) {
|
|
343
|
-
let
|
|
344
|
-
|
|
341
|
+
let t = this.world.registry;
|
|
342
|
+
e.world.buildComponentDescriptor = (e, n) => l(e, n, t, this.allocator);
|
|
345
343
|
}
|
|
346
|
-
let
|
|
347
|
-
this.entities
|
|
348
|
-
let
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.queryEntities[t] = r, d[t] = r;
|
|
352
|
-
});
|
|
353
|
-
let f = {
|
|
354
|
-
entityComponentChanged(e, t, n, i) {
|
|
355
|
-
r.push({
|
|
344
|
+
let t = performance.now(), n = [], r = {}, i = [], a = [], s = [];
|
|
345
|
+
this.entities.apply(e.entities);
|
|
346
|
+
let c = this.workState.getEntities(this.entities.entries, e.entities, e.workBatch), u = this.applyQueryDeltas(e.queries), d = {
|
|
347
|
+
entityComponentChanged(e, t, r, i) {
|
|
348
|
+
n.push({
|
|
356
349
|
entityId: e,
|
|
357
350
|
event: "component-property-updated",
|
|
358
351
|
args: [
|
|
359
352
|
t,
|
|
360
|
-
|
|
353
|
+
r,
|
|
361
354
|
i
|
|
362
355
|
]
|
|
363
356
|
});
|
|
364
357
|
},
|
|
365
|
-
emitEntityEvent(e, t, ...
|
|
366
|
-
|
|
358
|
+
emitEntityEvent(e, t, ...r) {
|
|
359
|
+
n.push({
|
|
367
360
|
entityId: e,
|
|
368
361
|
event: t,
|
|
369
|
-
args:
|
|
362
|
+
args: r
|
|
370
363
|
});
|
|
371
364
|
},
|
|
372
365
|
emitSystemEvent(e, t) {
|
|
373
|
-
(
|
|
366
|
+
(r[e] ?? (r[e] = [])).push(t);
|
|
374
367
|
},
|
|
375
368
|
entityDied(e) {
|
|
376
|
-
|
|
369
|
+
n.push({
|
|
377
370
|
entityId: e,
|
|
378
371
|
event: "death",
|
|
379
372
|
args: []
|
|
380
373
|
});
|
|
381
374
|
},
|
|
382
375
|
createEntity(e) {
|
|
383
|
-
|
|
376
|
+
i.push(e);
|
|
384
377
|
},
|
|
385
378
|
addComponent(e, t) {
|
|
386
|
-
|
|
379
|
+
a.push({
|
|
387
380
|
type: "add",
|
|
388
381
|
entityId: e,
|
|
389
382
|
component: t
|
|
390
383
|
});
|
|
391
384
|
},
|
|
392
385
|
removeComponent(e, t) {
|
|
393
|
-
|
|
386
|
+
a.push({
|
|
394
387
|
type: "remove",
|
|
395
388
|
entityId: e,
|
|
396
389
|
componentName: String(t)
|
|
@@ -398,69 +391,77 @@ var E = class extends w {
|
|
|
398
391
|
}
|
|
399
392
|
};
|
|
400
393
|
if (this.updateFunction.queryChanged) {
|
|
401
|
-
for (let [
|
|
402
|
-
this.updateFunction.queryChanged(
|
|
394
|
+
for (let [t, n] of Object.entries(e.queries)) if (n.added.length || n.removed.length) try {
|
|
395
|
+
this.updateFunction.queryChanged(e.world, t, n, d);
|
|
403
396
|
} catch (e) {
|
|
404
|
-
|
|
397
|
+
s.push({
|
|
405
398
|
error: e,
|
|
406
399
|
phase: "queryChanged"
|
|
407
400
|
});
|
|
408
401
|
}
|
|
409
402
|
}
|
|
410
|
-
let
|
|
411
|
-
if (this.updateFunction.preRun && (!
|
|
412
|
-
this.updateFunction.preRun(
|
|
403
|
+
let f = !1;
|
|
404
|
+
if (this.updateFunction.preRun && (!e.workBatch || e.workBatch.first)) try {
|
|
405
|
+
this.updateFunction.preRun(e.world, this.entities.entries, u, d);
|
|
413
406
|
} catch (e) {
|
|
414
|
-
|
|
407
|
+
f = !0, s.push({
|
|
415
408
|
error: e,
|
|
416
409
|
phase: "preRun"
|
|
417
410
|
});
|
|
418
411
|
}
|
|
419
|
-
if (!
|
|
420
|
-
this.updateFunction.preBatch(
|
|
412
|
+
if (!f && this.updateFunction.preBatch) try {
|
|
413
|
+
this.updateFunction.preBatch(e.world, c, u, d);
|
|
421
414
|
} catch (e) {
|
|
422
|
-
|
|
415
|
+
f = !0, s.push({
|
|
423
416
|
error: e,
|
|
424
417
|
phase: "preBatch"
|
|
425
418
|
});
|
|
426
419
|
}
|
|
427
|
-
if (
|
|
420
|
+
if (f || c.forEach((t) => {
|
|
428
421
|
try {
|
|
429
|
-
this.updateFunction(
|
|
430
|
-
} catch (
|
|
431
|
-
|
|
432
|
-
error:
|
|
422
|
+
this.updateFunction(e.world, t.entityId, t.components, u, d);
|
|
423
|
+
} catch (e) {
|
|
424
|
+
s.push({
|
|
425
|
+
error: e,
|
|
433
426
|
phase: "update",
|
|
434
|
-
entityId:
|
|
427
|
+
entityId: t.entityId
|
|
435
428
|
});
|
|
436
429
|
}
|
|
437
|
-
}), this.updateFunction.entityRemoved) for (let
|
|
438
|
-
this.updateFunction.entityRemoved(
|
|
439
|
-
} catch (
|
|
440
|
-
|
|
441
|
-
error:
|
|
430
|
+
}), this.updateFunction.entityRemoved) for (let t of e.entities.removed) try {
|
|
431
|
+
this.updateFunction.entityRemoved(e.world, t, d);
|
|
432
|
+
} catch (e) {
|
|
433
|
+
s.push({
|
|
434
|
+
error: e,
|
|
442
435
|
phase: "entityRemoved",
|
|
443
|
-
entityId:
|
|
436
|
+
entityId: t
|
|
444
437
|
});
|
|
445
438
|
}
|
|
446
|
-
let
|
|
447
|
-
this.workState.finish(
|
|
439
|
+
let p = performance.now() - t;
|
|
440
|
+
this.workState.finish(e.workBatch, f), this.onMessageTyped({
|
|
448
441
|
type: "run-complete",
|
|
449
|
-
generation:
|
|
450
|
-
runTime:
|
|
451
|
-
events:
|
|
452
|
-
systemEvents:
|
|
453
|
-
created:
|
|
454
|
-
componentChanges:
|
|
455
|
-
errors:
|
|
456
|
-
workFailed:
|
|
442
|
+
generation: e.generation,
|
|
443
|
+
runTime: p,
|
|
444
|
+
events: n,
|
|
445
|
+
systemEvents: r,
|
|
446
|
+
created: i,
|
|
447
|
+
componentChanges: a,
|
|
448
|
+
errors: s,
|
|
449
|
+
workFailed: f
|
|
457
450
|
});
|
|
458
451
|
}
|
|
459
452
|
}
|
|
453
|
+
applyQueryDeltas(t) {
|
|
454
|
+
let n = {};
|
|
455
|
+
for (let [r, i] of Object.entries(t)) {
|
|
456
|
+
let t = this.queryEntities[r] ??= new e();
|
|
457
|
+
t.apply(i), n[r] = t.entries;
|
|
458
|
+
}
|
|
459
|
+
return n;
|
|
460
|
+
}
|
|
460
461
|
onMessageTyped(e) {
|
|
461
462
|
this.onmessage({ data: e });
|
|
462
463
|
}
|
|
463
|
-
},
|
|
464
|
+
}, k = "___main", A = class e extends C {
|
|
464
465
|
entities = /* @__PURE__ */ new Map();
|
|
465
466
|
options;
|
|
466
467
|
worker;
|
|
@@ -493,13 +494,13 @@ var E = class extends w {
|
|
|
493
494
|
type: "grow-buffer",
|
|
494
495
|
buffer: e
|
|
495
496
|
});
|
|
496
|
-
})) : (this.worker = new
|
|
497
|
+
})) : (this.worker = new O(t.updateFunction, e, !!t.createsEntities, !!t.addsComponents), this.isWorkerThread = !1), this.initWorker();
|
|
497
498
|
}
|
|
498
499
|
initWorker() {
|
|
499
500
|
let e = (e) => {
|
|
500
501
|
console.error(e, e.cause), this.initialized || (this.initError = e, this.initPromise?.reject(e));
|
|
501
502
|
};
|
|
502
|
-
if (!(this.worker instanceof
|
|
503
|
+
if (!(this.worker instanceof O)) {
|
|
503
504
|
let t = (t) => {
|
|
504
505
|
e(Error(`Worker ${this.name} failed to load`, { cause: t }));
|
|
505
506
|
};
|
|
@@ -604,7 +605,7 @@ var E = class extends w {
|
|
|
604
605
|
type: "load",
|
|
605
606
|
data: this.options.getInitData?.(),
|
|
606
607
|
gameTime: this.gameTime,
|
|
607
|
-
entities: this.buildQueryDelta(
|
|
608
|
+
entities: this.buildQueryDelta(k, this.options),
|
|
608
609
|
queries: n,
|
|
609
610
|
heap: this.isWorkerThread ? this.world.heap.getSharedMemory() : void 0,
|
|
610
611
|
sharedMemory: this.isWorkerThread ? this.world.getSharedComponentMemory() : void 0,
|
|
@@ -704,7 +705,7 @@ var E = class extends w {
|
|
|
704
705
|
first: t.first,
|
|
705
706
|
last: t.last
|
|
706
707
|
}, this.isRunning = !0, this.completeEffects = this.world.scheduler.prepareEffects?.(this.world, this);
|
|
707
|
-
let i = this.buildQueryDelta(
|
|
708
|
+
let i = this.buildQueryDelta(k, this.options), a = {};
|
|
708
709
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
709
710
|
a[e] = this.buildQueryDelta(e, t);
|
|
710
711
|
});
|
|
@@ -773,7 +774,7 @@ var E = class extends w {
|
|
|
773
774
|
}
|
|
774
775
|
checkAddEntity(e) {
|
|
775
776
|
let t = this.tracksMainQuery && this.matchesQuery(e, this.options);
|
|
776
|
-
return this.updateEntityList(
|
|
777
|
+
return this.updateEntityList(k, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
777
778
|
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
778
779
|
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
779
780
|
}), t;
|
|
@@ -783,19 +784,19 @@ var E = class extends w {
|
|
|
783
784
|
t.entities.forEach((e) => this.checkAddEntity(e));
|
|
784
785
|
return;
|
|
785
786
|
}
|
|
786
|
-
this.tracksMainQuery && this.addBatchToQuery(
|
|
787
|
+
this.tracksMainQuery && this.addBatchToQuery(k, this.entities, this.options, t), Object.entries(this.options.queries ?? {}).forEach(([e, n]) => {
|
|
787
788
|
let r = this.queryEntities[e] ?? (this.queryEntities[e] = /* @__PURE__ */ new Map());
|
|
788
789
|
this.addBatchToQuery(e, r, n, t);
|
|
789
790
|
});
|
|
790
791
|
}
|
|
791
792
|
addBatchToQuery(e, t, n, r) {
|
|
792
793
|
let i = this.getQueryDelta(e);
|
|
793
|
-
|
|
794
|
+
w(r, (e) => this.matchesComponents(e, n), (e) => {
|
|
794
795
|
e.components.entity.dead || n.filter && !n.filter(e) || (t.set(e.eid, e), this.markAdded(i, e));
|
|
795
796
|
});
|
|
796
797
|
}
|
|
797
798
|
removeEntity(e) {
|
|
798
|
-
this.updateEntityList(
|
|
799
|
+
this.updateEntityList(k, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
|
|
799
800
|
this.updateEntityList(t, n, e, !1);
|
|
800
801
|
});
|
|
801
802
|
}
|
|
@@ -810,7 +811,7 @@ var E = class extends w {
|
|
|
810
811
|
destroy() {
|
|
811
812
|
super.destroy(), this.pendingEffects?.discard(), "terminate" in this.worker && this.worker.terminate();
|
|
812
813
|
}
|
|
813
|
-
},
|
|
814
|
+
}, j = class extends S.default {
|
|
814
815
|
eid;
|
|
815
816
|
config;
|
|
816
817
|
world;
|
|
@@ -911,7 +912,7 @@ var E = class extends w {
|
|
|
911
912
|
assertComponentPropertyMutable(e, t) {
|
|
912
913
|
if (e === "entity" && (t === "type" || t === "class")) throw Error(`Entity ${t} is immutable`);
|
|
913
914
|
}
|
|
914
|
-
},
|
|
915
|
+
}, M = class e {
|
|
915
916
|
world;
|
|
916
917
|
configs;
|
|
917
918
|
classes;
|
|
@@ -928,7 +929,7 @@ var E = class extends w {
|
|
|
928
929
|
this.world = e, this.forbiddenProperties.clear();
|
|
929
930
|
for (let t of Object.keys(this.classes)) {
|
|
930
931
|
let n = this.classes[t].entity;
|
|
931
|
-
if (n !==
|
|
932
|
+
if (n !== j && !(n.prototype instanceof j)) throw Error(`Entity class ${t} must extend BaseEntity`);
|
|
932
933
|
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}`);
|
|
933
934
|
}
|
|
934
935
|
for (let e of Object.keys(this.configs)) this.validateTemplate(e, this.configs[e]);
|
|
@@ -954,7 +955,7 @@ var E = class extends w {
|
|
|
954
955
|
createAdoptedEntity(e, t, n) {
|
|
955
956
|
if (!t) {
|
|
956
957
|
if (this.hasClasses) throw Error(`Entity type ${e} has no class`);
|
|
957
|
-
return new
|
|
958
|
+
return new j(this.world, void 0, n);
|
|
958
959
|
}
|
|
959
960
|
let r = this.classes[t];
|
|
960
961
|
if (!r) throw Error(`Unknown entity class: ${t}`);
|
|
@@ -980,7 +981,7 @@ var E = class extends w {
|
|
|
980
981
|
return e ? this.getAllowedComponents(e) : void 0;
|
|
981
982
|
}
|
|
982
983
|
createEntity(e) {
|
|
983
|
-
return new
|
|
984
|
+
return new j(this.world, e);
|
|
984
985
|
}
|
|
985
986
|
get hasClasses() {
|
|
986
987
|
return this.allowedComponents.size > 0;
|
|
@@ -1045,26 +1046,26 @@ var E = class extends w {
|
|
|
1045
1046
|
}
|
|
1046
1047
|
throw Error(`Entity type ${e} class ${t} loads a component outside its class`);
|
|
1047
1048
|
}
|
|
1048
|
-
},
|
|
1049
|
-
for (let e = 0; e <
|
|
1050
|
-
function
|
|
1049
|
+
}, N = 45, P = "!", F = "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO", I = "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}", L = (/* @__PURE__ */ new Int8Array(128)).fill(-1);
|
|
1050
|
+
for (let e = 0; e < N; e++) L[F.charCodeAt(e)] = e, L[I.charCodeAt(e)] = e + N;
|
|
1051
|
+
function R(e) {
|
|
1051
1052
|
let t = "";
|
|
1052
|
-
for (; e >=
|
|
1053
|
-
return t +
|
|
1053
|
+
for (; e >= N;) t += I[e % N], e = Math.floor(e / N);
|
|
1054
|
+
return t + F[e];
|
|
1054
1055
|
}
|
|
1055
|
-
var
|
|
1056
|
-
function
|
|
1056
|
+
var z = /* @__PURE__ */ new Float32Array(1), B = new Uint32Array(z.buffer);
|
|
1057
|
+
function se(e, t) {
|
|
1057
1058
|
switch (e.type) {
|
|
1058
|
-
case "boolean": return typeof t == "boolean" ?
|
|
1059
|
-
case "string": return t === null ?
|
|
1060
|
-
case "float32": return typeof t != "number" || !Number.isFinite(t) || Math.fround(t) !== t ? void 0 : (
|
|
1059
|
+
case "boolean": return typeof t == "boolean" ? F[Number(t)] : void 0;
|
|
1060
|
+
case "string": return t === null ? F[0] : typeof t == "string" && t.length ? R(t.length) + t : void 0;
|
|
1061
|
+
case "float32": return typeof t != "number" || !Number.isFinite(t) || Math.fround(t) !== t ? void 0 : (z[0] = t, R(B[0]));
|
|
1061
1062
|
default: {
|
|
1062
|
-
let n =
|
|
1063
|
-
return n === void 0 ? void 0 :
|
|
1063
|
+
let n = V(e, t);
|
|
1064
|
+
return n === void 0 ? void 0 : R(n);
|
|
1064
1065
|
}
|
|
1065
1066
|
}
|
|
1066
1067
|
}
|
|
1067
|
-
function
|
|
1068
|
+
function V(e, t) {
|
|
1068
1069
|
if (typeof t != "number") return;
|
|
1069
1070
|
let n = Math.round((t - (e.offset ?? 0)) * 10 ** (e.decimals ?? 0) / (e.step ?? 1));
|
|
1070
1071
|
if (!Number.isSafeInteger(n) || H(e, n) !== t) return;
|
|
@@ -1078,7 +1079,7 @@ function H(e, t) {
|
|
|
1078
1079
|
function U(e, t) {
|
|
1079
1080
|
switch (e.type) {
|
|
1080
1081
|
case "boolean": return t !== 0;
|
|
1081
|
-
case "float32": return
|
|
1082
|
+
case "float32": return B[0] = t, z[0];
|
|
1082
1083
|
case "uint": return H(e, t);
|
|
1083
1084
|
default: return H(e, t % 2 == 0 ? t / 2 : -(t + 1) / 2);
|
|
1084
1085
|
}
|
|
@@ -1100,7 +1101,7 @@ var G = class {
|
|
|
1100
1101
|
for (let r of W(n)) {
|
|
1101
1102
|
if (this.encoders.has(r)) throw Error(`Duplicate compressed entity definition for ${r}`);
|
|
1102
1103
|
this.encoders.set(r, {
|
|
1103
|
-
prefix:
|
|
1104
|
+
prefix: R(t++),
|
|
1104
1105
|
group: e
|
|
1105
1106
|
});
|
|
1106
1107
|
}
|
|
@@ -1128,12 +1129,12 @@ var G = class {
|
|
|
1128
1129
|
if (r === "type" || i === void 0) continue;
|
|
1129
1130
|
let t = e.group.indices.get(r);
|
|
1130
1131
|
if (t === void 0) return;
|
|
1131
|
-
let a =
|
|
1132
|
+
let a = se(e.group.definition.properties[t], i);
|
|
1132
1133
|
if (a === void 0) return;
|
|
1133
1134
|
n[t] = a;
|
|
1134
1135
|
}
|
|
1135
1136
|
let r = e.prefix;
|
|
1136
|
-
for (let e = 0; e < n.length; e++) r += n[e] ??
|
|
1137
|
+
for (let e = 0; e < n.length; e++) r += n[e] ?? P;
|
|
1137
1138
|
return r;
|
|
1138
1139
|
}
|
|
1139
1140
|
};
|
|
@@ -1159,16 +1160,16 @@ function le(e) {
|
|
|
1159
1160
|
}
|
|
1160
1161
|
function q(e, t) {
|
|
1161
1162
|
let n = 0, r = () => {
|
|
1162
|
-
if (e[n] ===
|
|
1163
|
+
if (e[n] === P) {
|
|
1163
1164
|
n++;
|
|
1164
1165
|
return;
|
|
1165
1166
|
}
|
|
1166
1167
|
let t = 0, r = 1;
|
|
1167
1168
|
for (; n < e.length;) {
|
|
1168
|
-
let i = e.charCodeAt(n++), a = i < 128 ?
|
|
1169
|
+
let i = e.charCodeAt(n++), a = i < 128 ? L[i] : -1;
|
|
1169
1170
|
if (a < 0) throw Error(`Invalid compressed entity ${e}`);
|
|
1170
|
-
if (a <
|
|
1171
|
-
t += (a -
|
|
1171
|
+
if (a < N) return t + a * r;
|
|
1172
|
+
t += (a - N) * r, r *= N;
|
|
1172
1173
|
}
|
|
1173
1174
|
throw Error(`Truncated compressed entity ${e}`);
|
|
1174
1175
|
}, i = r(), a = i === void 0 ? void 0 : le(t).get(i);
|
|
@@ -1205,7 +1206,7 @@ var Y = class {
|
|
|
1205
1206
|
let i = !0, a = !1, o = !1;
|
|
1206
1207
|
e.emit(`system-${r.name}-started`);
|
|
1207
1208
|
try {
|
|
1208
|
-
i = r.shouldRun(), i
|
|
1209
|
+
i = r.shouldRun(), i ? a = r.update(t) : e.systemSkipped?.(r);
|
|
1209
1210
|
} catch (t) {
|
|
1210
1211
|
let i = t;
|
|
1211
1212
|
console.error(i.message, i), o = !0, n = i, e.emit("system-error", {
|
|
@@ -1221,7 +1222,7 @@ var Y = class {
|
|
|
1221
1222
|
});
|
|
1222
1223
|
}), { lastSystemError: n };
|
|
1223
1224
|
}
|
|
1224
|
-
}, ue =
|
|
1225
|
+
}, ue = v, X = 1e4, de = class extends S.default {
|
|
1225
1226
|
heap;
|
|
1226
1227
|
constantStrings;
|
|
1227
1228
|
eidCounter;
|
|
@@ -1249,7 +1250,7 @@ var Y = class {
|
|
|
1249
1250
|
};
|
|
1250
1251
|
clearing = !1;
|
|
1251
1252
|
constructor(e, t = {}) {
|
|
1252
|
-
super(), this.scheduler = t.scheduler ?? new Y(), this.heap = new
|
|
1253
|
+
super(), this.scheduler = t.scheduler ?? new Y(), this.heap = new te({ bufferSize: t.heapSize ?? ue }), this.constantStrings = new g(this.heap), this.eidCounter = this.heap.allocUI32(1), this.heap.addOnGrowBufferHandlers((e) => this.emit("grow-buffer", e));
|
|
1253
1254
|
let n = {
|
|
1254
1255
|
...e,
|
|
1255
1256
|
entity: i
|
|
@@ -1258,10 +1259,10 @@ var Y = class {
|
|
|
1258
1259
|
let t = n[e];
|
|
1259
1260
|
r[e] = {
|
|
1260
1261
|
...t,
|
|
1261
|
-
memoryComponent: new
|
|
1262
|
+
memoryComponent: new _(this.heap, t.type, t.size)
|
|
1262
1263
|
};
|
|
1263
1264
|
}
|
|
1264
|
-
this.registry = r, this.factory = t.factory ?? new
|
|
1265
|
+
this.registry = r, this.factory = t.factory ?? new M(), this.factory.setWorld(this);
|
|
1265
1266
|
}
|
|
1266
1267
|
allocateEid() {
|
|
1267
1268
|
return Atomics.add(this.eidCounter.data, 0, 1) + 1;
|
|
@@ -1278,7 +1279,7 @@ var Y = class {
|
|
|
1278
1279
|
this.heap.buffers[e.bufferPosition] === void 0 && this.heap.addSharedBuffer(e), this.emit("grow-buffer", e);
|
|
1279
1280
|
}
|
|
1280
1281
|
get needsSpareBuffer() {
|
|
1281
|
-
return this.systems.some((e) => e instanceof
|
|
1282
|
+
return this.systems.some((e) => e instanceof A && e.isWorkerThread && (!!e.options.createsEntities || !!e.options.addsComponents));
|
|
1282
1283
|
}
|
|
1283
1284
|
async init() {
|
|
1284
1285
|
await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
|
|
@@ -1384,6 +1385,9 @@ var Y = class {
|
|
|
1384
1385
|
notifySystemRunCompleted(e) {
|
|
1385
1386
|
this.activeFreeBuffer.waitingSystems.delete(e) && this.activeFreeBuffer.waitingSystems.size === 0 && this.processFreeBuffers(), this.scheduler.runCompleted?.(this, e);
|
|
1386
1387
|
}
|
|
1388
|
+
systemSkipped(e) {
|
|
1389
|
+
e.isCurrentlyRunning() || this.activeFreeBuffer.waitingSystems.delete(e) && this.activeFreeBuffer.waitingSystems.size === 0 && this.processFreeBuffers();
|
|
1390
|
+
}
|
|
1387
1391
|
processFreeBuffers() {
|
|
1388
1392
|
for (; this.activeFreeBuffer.waitingSystems.size === 0 && (this.activeFreeBuffer.frees.length > 0 && this.performFrees(this.activeFreeBuffer), this.nextFreeBuffer.frees.length !== 0);) this.promoteNextFreeBuffer();
|
|
1389
1393
|
}
|
|
@@ -1421,7 +1425,7 @@ var Y = class {
|
|
|
1421
1425
|
let t = this.systems.findIndex((t) => t.name === e);
|
|
1422
1426
|
if (t !== -1) {
|
|
1423
1427
|
let [e] = this.systems.splice(t, 1);
|
|
1424
|
-
this.scheduler.systemRemoved?.(this, e), this.emit("system-removed", e);
|
|
1428
|
+
this.scheduler.systemRemoved?.(this, e), this.emit("system-removed", e), this.activeFreeBuffer.waitingSystems.delete(e) && this.activeFreeBuffer.waitingSystems.size === 0 && this.processFreeBuffers();
|
|
1425
1429
|
}
|
|
1426
1430
|
}
|
|
1427
1431
|
update(e) {
|
|
@@ -1456,16 +1460,16 @@ var Y = class {
|
|
|
1456
1460
|
}
|
|
1457
1461
|
addEntityToEntityWorkerSystem(e, t) {
|
|
1458
1462
|
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1459
|
-
(n instanceof
|
|
1463
|
+
(n instanceof E && n.options.components?.includes(t) || n instanceof A && this.queriesReferenceComponent(n.options, t)) && n.checkAddEntity(e);
|
|
1460
1464
|
});
|
|
1461
1465
|
}
|
|
1462
1466
|
removeEntityFromEntityWorkerSystem(e, t) {
|
|
1463
1467
|
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1464
|
-
n instanceof
|
|
1468
|
+
n instanceof E && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof A && this.queriesReferenceComponent(n.options, t) && n.checkAddEntity(e);
|
|
1465
1469
|
});
|
|
1466
1470
|
}
|
|
1467
|
-
|
|
1468
|
-
let n = e.
|
|
1471
|
+
queriesReferenceComponent(e, t) {
|
|
1472
|
+
let n = e.required.includes(t) || !!e.not?.includes(t) || !!e.optional?.includes(t), r = Object.values(e.queries ?? {}).some((e) => e.required.includes(t) || !!e.not?.includes(t) || !!e.optional?.includes(t));
|
|
1469
1473
|
return n || r;
|
|
1470
1474
|
}
|
|
1471
1475
|
destroy() {
|
|
@@ -1571,7 +1575,7 @@ var pe = class {
|
|
|
1571
1575
|
}, 0);
|
|
1572
1576
|
}
|
|
1573
1577
|
isSliced(e) {
|
|
1574
|
-
return e.system instanceof
|
|
1578
|
+
return e.system instanceof T && e.system.remainingInstancesToRun.length > 0;
|
|
1575
1579
|
}
|
|
1576
1580
|
reset() {
|
|
1577
1581
|
this.continuationTimer !== void 0 && (clearTimeout(this.continuationTimer), this.continuationTimer = void 0);
|
|
@@ -1703,7 +1707,7 @@ var pe = class {
|
|
|
1703
1707
|
let i = this.generation, a = !0, o = !1, s = !1, c = null;
|
|
1704
1708
|
if (e.emit(`system-${r.name}-started`), this.nodes.has(t) && this.dispatchAllowed(e)) {
|
|
1705
1709
|
try {
|
|
1706
|
-
if (!r.withGameTime(t.gameTime, () => (a = n || r.shouldRun(), !this.nodes.has(t) || !this.dispatchAllowed(e) ? !1 : (a ? (t.state = "running", this.running.set(r, t), o = r.update(n ? 0 : t.elapsedTime), i === this.generation && !r.isCurrentlyRunning() && this.complete(t)) : this.complete(t), !0)))) return;
|
|
1710
|
+
if (!r.withGameTime(t.gameTime, () => (a = n || r.shouldRun(), !this.nodes.has(t) || !this.dispatchAllowed(e) ? !1 : (a ? (t.state = "running", this.running.set(r, t), o = r.update(n ? 0 : t.elapsedTime), i === this.generation && !r.isCurrentlyRunning() && this.complete(t)) : (this.complete(t), e.systemSkipped?.(r)), !0)))) return;
|
|
1707
1711
|
} catch (n) {
|
|
1708
1712
|
let a = n;
|
|
1709
1713
|
console.error(a.message, a), s = !0, c = a, i === this.generation && (r.isCurrentlyRunning() ? (t.state = "running", this.running.set(r, t)) : this.complete(t)), e.emit("system-error", {
|
|
@@ -1769,7 +1773,7 @@ function $(e) {
|
|
|
1769
1773
|
samples: e.length
|
|
1770
1774
|
};
|
|
1771
1775
|
}
|
|
1772
|
-
var _e = class extends
|
|
1776
|
+
var _e = class extends S.default {
|
|
1773
1777
|
world;
|
|
1774
1778
|
ticksBetweenUpdates;
|
|
1775
1779
|
stats = {
|
|
@@ -1854,7 +1858,7 @@ var _e = class extends C.default {
|
|
|
1854
1858
|
e.run = [], e.events = [];
|
|
1855
1859
|
}), this.emit("stats-updated", this.stats), this.stats;
|
|
1856
1860
|
}
|
|
1857
|
-
}, ve = class extends
|
|
1861
|
+
}, ve = class extends A {
|
|
1858
1862
|
constructor(e, t) {
|
|
1859
1863
|
super(e, {
|
|
1860
1864
|
...t,
|
|
@@ -1870,6 +1874,6 @@ var _e = class extends C.default {
|
|
|
1870
1874
|
}
|
|
1871
1875
|
};
|
|
1872
1876
|
//#endregion
|
|
1873
|
-
export {
|
|
1877
|
+
export { j as BaseEntity, de as BaseWorld, n as CLASS_INDEX, f as Component, pe as ConflictScheduler, g as ConstantStringCache, c as DEAD_INDEX, ge as DEFAULT_TICKS_BETWEEN_UPDATES, Y as DefaultScheduler, G as EntityCompressor, M as EntityFactory, E as EntitySystem, O as EntitySystemWebWorker, A as EntityWorkerSystem, T as IterableSystem, _ as MemoryComponent, _e as PerformanceTiming, ee as STATIC_INDEX, C as System, r as TYPE_INDEX, D as WebWorker, ve as WorkerSystem, t as addComponentWorker, ce as compressEntities, p as createEntitySystemWorker, d as createEntityWorker, h as createSystemWorker, J as decompressEntities, q as decompressEntity, me as defineEntityClasses, Z as defineEntityConfigs, i as entityDefinition, he as killEntity, m as killEntityWorker, s as removeComponentWorker };
|
|
1874
1878
|
|
|
1875
1879
|
//# sourceMappingURL=index.js.map
|