@daneren2005/shared-memory-ecs 1.10.4 → 1.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component-trigger-index.d.ts +17 -0
- package/dist/{create-system-worker-BU5CnyVh.js → create-system-worker-CkPwxmmr.js} +102 -70
- package/dist/create-system-worker-CkPwxmmr.js.map +1 -0
- package/dist/index.js +250 -248
- package/dist/index.js.map +1 -1
- package/dist/node/node-worker-adapter.d.ts +1 -1
- package/dist/node-worker-self.js +1 -2
- package/dist/node-worker-self.js.map +1 -1
- package/dist/node.js +3 -4
- package/dist/node.js.map +1 -1
- package/dist/systems/entity-worker-system.d.ts +2 -0
- package/dist/systems/workers/entity-system-worker-message.d.ts +12 -3
- package/dist/systems/workers/packed-membership.d.ts +16 -0
- package/dist/worker.js +1 -2
- package/dist/world.d.ts +2 -0
- package/package.json +9 -9
- package/dist/create-system-worker-BU5CnyVh.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { _ as e, a as t,
|
|
2
|
-
import
|
|
3
|
-
import { MAX_BYTE_OFFSET_LENGTH as
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
if (t && typeof t == "object" || typeof t == "function") for (var i =
|
|
1
|
+
import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as ee, s as te, t as ne, u as re, v as ie, x as m, y as h } from "./create-system-worker-CkPwxmmr.js";
|
|
2
|
+
import ae from "@daneren2005/shared-memory-objects/memory-heap";
|
|
3
|
+
import { MAX_BYTE_OFFSET_LENGTH as g } from "@daneren2005/shared-memory-objects/utils/pointer";
|
|
4
|
+
// \0rolldown/runtime.js
|
|
5
|
+
var oe = Object.create, _ = Object.defineProperty, v = Object.getOwnPropertyDescriptor, y = Object.getOwnPropertyNames, se = Object.getPrototypeOf, ce = Object.prototype.hasOwnProperty, le = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), ue = (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], !ce.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
|
+
}, b = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : oe(se(e)), ue(_(n, "default", {
|
|
12
12
|
value: e,
|
|
13
13
|
enumerable: !0
|
|
14
|
-
})
|
|
14
|
+
}), e)))((/* @__PURE__ */ le(((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));
|
|
@@ -88,7 +88,7 @@ var ae = Object.create, g = Object.defineProperty, _ = Object.getOwnPropertyDesc
|
|
|
88
88
|
if (!this._events[a]) return this;
|
|
89
89
|
if (!t) return s(this, a), this;
|
|
90
90
|
var o = this._events[a];
|
|
91
|
-
if (o.fn) o.fn
|
|
91
|
+
if (o.fn) o.fn !== t || i && !o.once || n && o.context !== n || s(this, a);
|
|
92
92
|
else {
|
|
93
93
|
for (var c = 0, l = [], u = o.length; c < u; c++) (o[c].fn !== t || i && !o[c].once || n && o[c].context !== n) && l.push(o[c]);
|
|
94
94
|
l.length ? this._events[a] = l.length === 1 ? l[0] : l : s(this, a);
|
|
@@ -98,7 +98,38 @@ var ae = Object.create, g = Object.defineProperty, _ = 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), de = [], fe = (e, t) => e.order - t.order, pe = class {
|
|
102
|
+
immediate = /* @__PURE__ */ new Map();
|
|
103
|
+
deferred = /* @__PURE__ */ new Map();
|
|
104
|
+
constructor(e) {
|
|
105
|
+
Object.keys(e).forEach((t, n) => {
|
|
106
|
+
if (t === "entity") return;
|
|
107
|
+
let r = e[t], i = r.loadInFinishLoading ? this.deferred : this.immediate, a = {
|
|
108
|
+
name: t,
|
|
109
|
+
order: n
|
|
110
|
+
};
|
|
111
|
+
for (let e of r.loadProperties) {
|
|
112
|
+
let t = i.get(e);
|
|
113
|
+
t ? t.push(a) : i.set(e, [a]);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
forLoad(e) {
|
|
118
|
+
return this.find(this.immediate, e);
|
|
119
|
+
}
|
|
120
|
+
forFinishLoading(e) {
|
|
121
|
+
return this.find(this.deferred, e);
|
|
122
|
+
}
|
|
123
|
+
find(e, t) {
|
|
124
|
+
if (e.size === 0) return de;
|
|
125
|
+
let n = [];
|
|
126
|
+
for (let r in t) {
|
|
127
|
+
let t = e.get(r);
|
|
128
|
+
if (t) for (let e of t) n.includes(e) || n.push(e);
|
|
129
|
+
}
|
|
130
|
+
return n.sort(fe);
|
|
131
|
+
}
|
|
132
|
+
}, x = class extends b.default {
|
|
102
133
|
world;
|
|
103
134
|
name;
|
|
104
135
|
currentDelta = 0;
|
|
@@ -174,13 +205,12 @@ var ae = Object.create, g = Object.defineProperty, _ = Object.getOwnPropertyDesc
|
|
|
174
205
|
this.removeAllListeners();
|
|
175
206
|
}
|
|
176
207
|
};
|
|
177
|
-
function
|
|
208
|
+
function S(e, t, n) {
|
|
178
209
|
let r = e.groups.map(t);
|
|
179
210
|
for (let t = 0; t < e.entities.length; t++) r[e.groupIndexes[t]] && n(e.entities[t]);
|
|
180
211
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var w = class extends S {
|
|
212
|
+
// src/systems/iterable-system.ts
|
|
213
|
+
var C = class extends x {
|
|
184
214
|
remainingInstancesToRun = [];
|
|
185
215
|
remainingInstancesStartTime = null;
|
|
186
216
|
iterationsPerCheck;
|
|
@@ -230,7 +260,7 @@ var w = class extends S {
|
|
|
230
260
|
}
|
|
231
261
|
beforeRunIterables() {}
|
|
232
262
|
getIterableEntityId(e) {}
|
|
233
|
-
},
|
|
263
|
+
}, w = class e extends C {
|
|
234
264
|
entities = /* @__PURE__ */ new Map();
|
|
235
265
|
options;
|
|
236
266
|
constructor(e, t = { name: "EntitySystem" }) {
|
|
@@ -264,13 +294,9 @@ var w = class extends S {
|
|
|
264
294
|
this.checkAddEntity(e) && this.options.updateEntityOnAdd && this.updateEntity(e, 0);
|
|
265
295
|
}
|
|
266
296
|
addEntities(t) {
|
|
267
|
-
|
|
268
|
-
t.entities.forEach((e) => this.onEntityAdded(e));
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
C(t, (e) => this.hasComponents(e), (e) => {
|
|
297
|
+
this.checkAddEntity === e.prototype.checkAddEntity ? S(t, (e) => this.hasComponents(e), (e) => {
|
|
272
298
|
this.filterEntity(e) && (this.entities.set(e.eid, e), this.options.updateEntityOnAdd && this.updateEntity(e, 0));
|
|
273
|
-
});
|
|
299
|
+
}) : t.entities.forEach((e) => this.onEntityAdded(e));
|
|
274
300
|
}
|
|
275
301
|
hasComponents(e) {
|
|
276
302
|
return !this.options.components || this.options.components.every((t) => !!e.components[t]);
|
|
@@ -300,12 +326,12 @@ var w = class extends S {
|
|
|
300
326
|
...this.reads ?? []
|
|
301
327
|
] : void 0;
|
|
302
328
|
}
|
|
303
|
-
},
|
|
329
|
+
}, T = class {
|
|
304
330
|
onmessage(e, t = []) {}
|
|
305
|
-
},
|
|
331
|
+
}, E = class extends T {
|
|
306
332
|
updateFunction;
|
|
307
|
-
entities = new
|
|
308
|
-
workState = new
|
|
333
|
+
entities = new h();
|
|
334
|
+
workState = new ie();
|
|
309
335
|
queryEntities = {};
|
|
310
336
|
worldExtension;
|
|
311
337
|
world;
|
|
@@ -321,69 +347,69 @@ var w = class extends S {
|
|
|
321
347
|
};
|
|
322
348
|
}
|
|
323
349
|
getString = (e) => this.world.constantStrings.getString(e) ?? "";
|
|
324
|
-
postMessage(
|
|
325
|
-
if (
|
|
326
|
-
else if (
|
|
327
|
-
this.entities.apply(
|
|
328
|
-
let
|
|
329
|
-
gameTime:
|
|
350
|
+
postMessage(t) {
|
|
351
|
+
if (t.type === "init") this.onMessageTyped({ type: "init-complete" });
|
|
352
|
+
else if (t.type === "load") {
|
|
353
|
+
this.entities.apply(t.entities);
|
|
354
|
+
let e = this.applyQueryDeltas(t.queries), n = {
|
|
355
|
+
gameTime: t.gameTime,
|
|
330
356
|
getString: this.getString,
|
|
331
357
|
heap: this.world.heap
|
|
332
358
|
};
|
|
333
|
-
this.worldExtension = this.updateFunction.init?.(n,
|
|
334
|
-
} else if (
|
|
335
|
-
else if (
|
|
336
|
-
if (
|
|
337
|
-
let
|
|
338
|
-
|
|
359
|
+
this.worldExtension = this.updateFunction.init?.(n, t.data, this.entities.entries, e) ?? void 0, this.onMessageTyped({ type: "loaded" });
|
|
360
|
+
} else if (t.type === "reset") this.workState.clear(), this.entities.clear(), this.queryEntities = {};
|
|
361
|
+
else if (t.type === "run") {
|
|
362
|
+
if (t.world = this.workState.getWorld(t.world, t.workBatch), this.worldExtension && Object.assign(t.world, this.worldExtension), t.world.getString = this.getString, t.world.heap = this.world.heap, t.world.allocate = this.allocator, this.createsEntities) {
|
|
363
|
+
let n = this.world.registry;
|
|
364
|
+
t.world.buildEntityDescriptor = (t) => e(t, this.world.factory.configs, n, this.allocator, this.world.factory.getWorkerClasses());
|
|
339
365
|
}
|
|
340
366
|
if (this.addsComponents) {
|
|
341
|
-
let
|
|
342
|
-
|
|
367
|
+
let e = this.world.registry;
|
|
368
|
+
t.world.buildComponentDescriptor = (t, n) => o(t, n, e, this.allocator);
|
|
343
369
|
}
|
|
344
|
-
let
|
|
345
|
-
this.entities.apply(
|
|
346
|
-
let
|
|
347
|
-
entityComponentChanged(e, t,
|
|
348
|
-
|
|
370
|
+
let n = performance.now(), r = [], i = {}, a = [], s = [], c = [];
|
|
371
|
+
this.entities.apply(t.entities);
|
|
372
|
+
let l = this.workState.getEntities(this.entities.entries, t.entities, t.workBatch), u = this.applyQueryDeltas(t.queries), d = {
|
|
373
|
+
entityComponentChanged(e, t, n, i) {
|
|
374
|
+
r.push({
|
|
349
375
|
entityId: e,
|
|
350
376
|
event: "component-property-updated",
|
|
351
377
|
args: [
|
|
352
378
|
t,
|
|
353
|
-
|
|
379
|
+
n,
|
|
354
380
|
i
|
|
355
381
|
]
|
|
356
382
|
});
|
|
357
383
|
},
|
|
358
|
-
emitEntityEvent(e, t, ...
|
|
359
|
-
|
|
384
|
+
emitEntityEvent(e, t, ...n) {
|
|
385
|
+
r.push({
|
|
360
386
|
entityId: e,
|
|
361
387
|
event: t,
|
|
362
|
-
args:
|
|
388
|
+
args: n
|
|
363
389
|
});
|
|
364
390
|
},
|
|
365
391
|
emitSystemEvent(e, t) {
|
|
366
|
-
(
|
|
392
|
+
(i[e] ?? (i[e] = [])).push(t);
|
|
367
393
|
},
|
|
368
394
|
entityDied(e) {
|
|
369
|
-
|
|
395
|
+
r.push({
|
|
370
396
|
entityId: e,
|
|
371
397
|
event: "death",
|
|
372
398
|
args: []
|
|
373
399
|
});
|
|
374
400
|
},
|
|
375
401
|
createEntity(e) {
|
|
376
|
-
|
|
402
|
+
a.push(e);
|
|
377
403
|
},
|
|
378
404
|
addComponent(e, t) {
|
|
379
|
-
|
|
405
|
+
s.push({
|
|
380
406
|
type: "add",
|
|
381
407
|
entityId: e,
|
|
382
408
|
component: t
|
|
383
409
|
});
|
|
384
410
|
},
|
|
385
411
|
removeComponent(e, t) {
|
|
386
|
-
|
|
412
|
+
s.push({
|
|
387
413
|
type: "remove",
|
|
388
414
|
entityId: e,
|
|
389
415
|
componentName: String(t)
|
|
@@ -391,77 +417,77 @@ var w = class extends S {
|
|
|
391
417
|
}
|
|
392
418
|
};
|
|
393
419
|
if (this.updateFunction.queryChanged) {
|
|
394
|
-
for (let [
|
|
395
|
-
this.updateFunction.queryChanged(
|
|
420
|
+
for (let [e, n] of Object.entries(t.queries)) if (n.added.length || n.removed.length) try {
|
|
421
|
+
this.updateFunction.queryChanged(t.world, e, n, d);
|
|
396
422
|
} catch (e) {
|
|
397
|
-
|
|
423
|
+
c.push({
|
|
398
424
|
error: e,
|
|
399
425
|
phase: "queryChanged"
|
|
400
426
|
});
|
|
401
427
|
}
|
|
402
428
|
}
|
|
403
429
|
let f = !1;
|
|
404
|
-
if (this.updateFunction.preRun && (!
|
|
405
|
-
this.updateFunction.preRun(
|
|
430
|
+
if (this.updateFunction.preRun && (!t.workBatch || t.workBatch.first)) try {
|
|
431
|
+
this.updateFunction.preRun(t.world, this.entities.entries, u, d);
|
|
406
432
|
} catch (e) {
|
|
407
|
-
f = !0,
|
|
433
|
+
f = !0, c.push({
|
|
408
434
|
error: e,
|
|
409
435
|
phase: "preRun"
|
|
410
436
|
});
|
|
411
437
|
}
|
|
412
438
|
if (!f && this.updateFunction.preBatch) try {
|
|
413
|
-
this.updateFunction.preBatch(
|
|
439
|
+
this.updateFunction.preBatch(t.world, l, u, d);
|
|
414
440
|
} catch (e) {
|
|
415
|
-
f = !0,
|
|
441
|
+
f = !0, c.push({
|
|
416
442
|
error: e,
|
|
417
443
|
phase: "preBatch"
|
|
418
444
|
});
|
|
419
445
|
}
|
|
420
|
-
if (f ||
|
|
446
|
+
if (f || l.forEach((e) => {
|
|
421
447
|
try {
|
|
422
|
-
this.updateFunction(
|
|
423
|
-
} catch (
|
|
424
|
-
|
|
425
|
-
error:
|
|
448
|
+
this.updateFunction(t.world, e.entityId, e.components, u, d);
|
|
449
|
+
} catch (t) {
|
|
450
|
+
c.push({
|
|
451
|
+
error: t,
|
|
426
452
|
phase: "update",
|
|
427
|
-
entityId:
|
|
453
|
+
entityId: e.entityId
|
|
428
454
|
});
|
|
429
455
|
}
|
|
430
|
-
}), this.updateFunction.entityRemoved) for (let
|
|
431
|
-
this.updateFunction.entityRemoved(
|
|
432
|
-
} catch (
|
|
433
|
-
|
|
434
|
-
error:
|
|
456
|
+
}), this.updateFunction.entityRemoved) for (let e of t.entities.removed) try {
|
|
457
|
+
this.updateFunction.entityRemoved(t.world, e, d);
|
|
458
|
+
} catch (t) {
|
|
459
|
+
c.push({
|
|
460
|
+
error: t,
|
|
435
461
|
phase: "entityRemoved",
|
|
436
|
-
entityId:
|
|
462
|
+
entityId: e
|
|
437
463
|
});
|
|
438
464
|
}
|
|
439
|
-
let p = performance.now() -
|
|
440
|
-
this.workState.finish(
|
|
465
|
+
let p = performance.now() - n;
|
|
466
|
+
this.workState.finish(t.workBatch, f), this.onMessageTyped({
|
|
441
467
|
type: "run-complete",
|
|
442
|
-
generation:
|
|
468
|
+
generation: t.generation,
|
|
443
469
|
runTime: p,
|
|
444
|
-
events:
|
|
445
|
-
systemEvents:
|
|
446
|
-
created:
|
|
447
|
-
componentChanges:
|
|
448
|
-
errors:
|
|
470
|
+
events: r,
|
|
471
|
+
systemEvents: i,
|
|
472
|
+
created: a,
|
|
473
|
+
componentChanges: s,
|
|
474
|
+
errors: c,
|
|
449
475
|
workFailed: f
|
|
450
476
|
});
|
|
451
477
|
}
|
|
452
478
|
}
|
|
453
|
-
applyQueryDeltas(
|
|
454
|
-
let
|
|
455
|
-
for (let [
|
|
456
|
-
let
|
|
457
|
-
|
|
479
|
+
applyQueryDeltas(e) {
|
|
480
|
+
let t = {};
|
|
481
|
+
for (let [n, r] of Object.entries(e)) {
|
|
482
|
+
let e = this.queryEntities[n] ??= new h();
|
|
483
|
+
e.apply(r), t[n] = e.entries;
|
|
458
484
|
}
|
|
459
|
-
return
|
|
485
|
+
return t;
|
|
460
486
|
}
|
|
461
487
|
onMessageTyped(e) {
|
|
462
488
|
this.onmessage({ data: e });
|
|
463
489
|
}
|
|
464
|
-
},
|
|
490
|
+
}, D = "___main", O = class e extends x {
|
|
465
491
|
entities = /* @__PURE__ */ new Map();
|
|
466
492
|
options;
|
|
467
493
|
worker;
|
|
@@ -479,6 +505,7 @@ var w = class extends S {
|
|
|
479
505
|
generation = 0;
|
|
480
506
|
queryEntities = {};
|
|
481
507
|
queryDeltas = {};
|
|
508
|
+
bulkMembershipPending = !1;
|
|
482
509
|
constructor(e, t) {
|
|
483
510
|
if (super(e, t), t.workBatchSize !== void 0 && (!Number.isSafeInteger(t.workBatchSize) || t.workBatchSize <= 0)) throw Error("workBatchSize must be a positive safe integer");
|
|
484
511
|
this.options = t, Object.keys(this.options.queries ?? {}).forEach((e) => {
|
|
@@ -494,13 +521,13 @@ var w = class extends S {
|
|
|
494
521
|
type: "grow-buffer",
|
|
495
522
|
buffer: e
|
|
496
523
|
});
|
|
497
|
-
})) : (this.worker = new
|
|
524
|
+
})) : (this.worker = new E(t.updateFunction, e, !!t.createsEntities, !!t.addsComponents), this.isWorkerThread = !1), this.initWorker();
|
|
498
525
|
}
|
|
499
526
|
initWorker() {
|
|
500
527
|
let e = (e) => {
|
|
501
528
|
console.error(e, e.cause), this.initialized || (this.initError = e, this.initPromise?.reject(e));
|
|
502
529
|
};
|
|
503
|
-
if (!(this.worker instanceof
|
|
530
|
+
if (!(this.worker instanceof E)) {
|
|
504
531
|
let t = (t) => {
|
|
505
532
|
e(Error(`Worker ${this.name} failed to load`, { cause: t }));
|
|
506
533
|
};
|
|
@@ -531,17 +558,16 @@ var w = class extends S {
|
|
|
531
558
|
}, a = {
|
|
532
559
|
apply: () => {
|
|
533
560
|
if (!r) {
|
|
534
|
-
if (t !== this.generation)
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
i();
|
|
561
|
+
if (t !== this.generation) a.discard();
|
|
562
|
+
else {
|
|
563
|
+
r = !0, this.pendingEffects = void 0;
|
|
564
|
+
try {
|
|
565
|
+
this.applyWorkerEffects(n, !1, e);
|
|
566
|
+
} catch (e) {
|
|
567
|
+
this.onError(e, { phase: "run" }), this.world.notifySystemRunCompleted(this);
|
|
568
|
+
} finally {
|
|
569
|
+
i();
|
|
570
|
+
}
|
|
545
571
|
}
|
|
546
572
|
}
|
|
547
573
|
},
|
|
@@ -574,11 +600,7 @@ var w = class extends S {
|
|
|
574
600
|
for (let t of Object.keys(e.systemEvents)) this.emit(t, e.systemEvents[t]);
|
|
575
601
|
e.events.forEach((e) => {
|
|
576
602
|
let t = this.world.getEntityByEid(e.entityId);
|
|
577
|
-
|
|
578
|
-
console.warn(`${this.name}-event ${e.event}: Could not find entity with id ${e.entityId}`);
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
t.emit(e.event, ...e.args);
|
|
603
|
+
t ? t.emit(e.event, ...e.args) : console.warn(`${this.name}-event ${e.event}: Could not find entity with id ${e.entityId}`);
|
|
582
604
|
}), e.created.forEach((e) => {
|
|
583
605
|
this.world.adoptEntity(e);
|
|
584
606
|
}), this.world.emit(`system-${this.name}-worker-events-finished`, e.runTime, n), this.world.notifySystemRunCompleted(this), this.runCompletePromise &&= (this.runCompletePromise.resolve(), null);
|
|
@@ -597,23 +619,25 @@ var w = class extends S {
|
|
|
597
619
|
promise: e,
|
|
598
620
|
resolve: t
|
|
599
621
|
};
|
|
600
|
-
let n = {};
|
|
622
|
+
let n = [], r = {};
|
|
601
623
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
602
|
-
|
|
624
|
+
r[e] = this.buildLoadDelta(e, t, this.queryEntities[e], n);
|
|
603
625
|
});
|
|
604
|
-
let
|
|
626
|
+
let i = this.buildLoadDelta(D, this.options, this.entities, n);
|
|
627
|
+
this.bulkMembershipPending = !1;
|
|
628
|
+
let a = {
|
|
605
629
|
type: "load",
|
|
606
630
|
data: this.options.getInitData?.(),
|
|
607
631
|
gameTime: this.gameTime,
|
|
608
|
-
entities:
|
|
609
|
-
queries:
|
|
632
|
+
entities: i,
|
|
633
|
+
queries: r,
|
|
610
634
|
heap: this.isWorkerThread ? this.world.heap.getSharedMemory() : void 0,
|
|
611
635
|
sharedMemory: this.isWorkerThread ? this.world.getSharedComponentMemory() : void 0,
|
|
612
636
|
factoryConfigs: this.isWorkerThread && this.options.createsEntities ? this.world.factory.configs : void 0,
|
|
613
637
|
factoryClasses: this.isWorkerThread && this.options.createsEntities ? this.world.factory.getWorkerClasses() : void 0,
|
|
614
638
|
addsComponents: !!this.options.addsComponents
|
|
615
639
|
};
|
|
616
|
-
return this.worker.postMessage(
|
|
640
|
+
return this.worker instanceof E ? this.worker.postMessage(a) : this.worker.postMessage(a, n), e;
|
|
617
641
|
}
|
|
618
642
|
clear() {
|
|
619
643
|
if (super.clear(), this.pendingEffects?.discard(), this.isRunning && !this.runCompletePromise) {
|
|
@@ -623,7 +647,7 @@ var w = class extends S {
|
|
|
623
647
|
resolve: t
|
|
624
648
|
};
|
|
625
649
|
}
|
|
626
|
-
this.isRunning = !1, this.generation++, this.entities.clear(), Object.values(this.queryEntities).forEach((e) => e.clear()), this.queryDeltas = {}, this.workPass = void 0, this.timingBatch = void 0, this.worker.postMessage({ type: "reset" });
|
|
650
|
+
this.isRunning = !1, this.generation++, this.entities.clear(), Object.values(this.queryEntities).forEach((e) => e.clear()), this.queryDeltas = {}, this.bulkMembershipPending = !1, this.workPass = void 0, this.timingBatch = void 0, this.worker.postMessage({ type: "reset" });
|
|
627
651
|
}
|
|
628
652
|
update(e) {
|
|
629
653
|
return this.isRunning ? (this.currentDelta += e, !1) : this.workPass ? (this.currentDelta += e, this.run(this.workPass.elapsedTime), !0) : super.update(e);
|
|
@@ -705,7 +729,7 @@ var w = class extends S {
|
|
|
705
729
|
first: t.first,
|
|
706
730
|
last: t.last
|
|
707
731
|
}, this.isRunning = !0, this.completeEffects = this.world.scheduler.prepareEffects?.(this.world, this);
|
|
708
|
-
let i = this.buildQueryDelta(
|
|
732
|
+
let i = this.buildQueryDelta(D, this.options), a = {};
|
|
709
733
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
710
734
|
a[e] = this.buildQueryDelta(e, t);
|
|
711
735
|
});
|
|
@@ -719,21 +743,28 @@ var w = class extends S {
|
|
|
719
743
|
};
|
|
720
744
|
this.worker.postMessage(o);
|
|
721
745
|
}
|
|
722
|
-
buildQueryDelta(e, t) {
|
|
723
|
-
let
|
|
724
|
-
n.added.
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
components: this.buildComponents(e, t)
|
|
728
|
-
});
|
|
746
|
+
buildQueryDelta(e, t, n) {
|
|
747
|
+
let r = this.getQueryDelta(e), i = [];
|
|
748
|
+
for (let e of (n ?? r.added).values()) i.push({
|
|
749
|
+
entityId: e.eid,
|
|
750
|
+
components: this.buildComponents(e, t)
|
|
729
751
|
});
|
|
730
|
-
let
|
|
752
|
+
let a = Array.from(r.removed);
|
|
731
753
|
return this.queryDeltas[e] = {
|
|
732
754
|
added: /* @__PURE__ */ new Set(),
|
|
733
755
|
removed: /* @__PURE__ */ new Set()
|
|
734
756
|
}, {
|
|
735
|
-
added:
|
|
736
|
-
removed:
|
|
757
|
+
added: i,
|
|
758
|
+
removed: a
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
buildLoadDelta(e, t, n, r) {
|
|
762
|
+
let i = this.bulkMembershipPending ? n : this.getQueryDelta(e).added;
|
|
763
|
+
if (!this.isWorkerThread) return this.buildQueryDelta(e, t, i);
|
|
764
|
+
let a = s(i, [...t.required, ...t.optional ?? []]);
|
|
765
|
+
return r.push(...u(a)), {
|
|
766
|
+
...this.buildQueryDelta(e, t, /* @__PURE__ */ new Set()),
|
|
767
|
+
packedAdded: a
|
|
737
768
|
};
|
|
738
769
|
}
|
|
739
770
|
buildComponents(e, t) {
|
|
@@ -774,29 +805,24 @@ var w = class extends S {
|
|
|
774
805
|
}
|
|
775
806
|
checkAddEntity(e) {
|
|
776
807
|
let t = this.tracksMainQuery && this.matchesQuery(e, this.options);
|
|
777
|
-
return this.updateEntityList(
|
|
808
|
+
return this.updateEntityList(D, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
778
809
|
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
779
810
|
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
780
811
|
}), t;
|
|
781
812
|
}
|
|
782
813
|
addEntities(t) {
|
|
783
|
-
|
|
784
|
-
t.entities.forEach((e) => this.checkAddEntity(e));
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
this.tracksMainQuery && this.addBatchToQuery(O, this.entities, this.options, t), Object.entries(this.options.queries ?? {}).forEach(([e, n]) => {
|
|
814
|
+
this.checkAddEntity !== e.prototype.checkAddEntity || this.matchesQuery !== e.prototype.matchesQuery ? t.entities.forEach((e) => this.checkAddEntity(e)) : (this.bulkMembershipPending = !0, this.tracksMainQuery && this.addBatchToQuery(this.entities, this.options, t), Object.entries(this.options.queries ?? {}).forEach(([e, n]) => {
|
|
788
815
|
let r = this.queryEntities[e] ?? (this.queryEntities[e] = /* @__PURE__ */ new Map());
|
|
789
|
-
this.addBatchToQuery(
|
|
790
|
-
});
|
|
816
|
+
this.addBatchToQuery(r, n, t);
|
|
817
|
+
}));
|
|
791
818
|
}
|
|
792
|
-
addBatchToQuery(e, t, n
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
e.components.entity.dead || n.filter && !n.filter(e) || (t.set(e.eid, e), this.markAdded(i, e));
|
|
819
|
+
addBatchToQuery(e, t, n) {
|
|
820
|
+
S(n, (e) => this.matchesComponents(e, t), (n) => {
|
|
821
|
+
n.components.entity.dead || t.filter && !t.filter(n) || e.set(n.eid, n);
|
|
796
822
|
});
|
|
797
823
|
}
|
|
798
824
|
removeEntity(e) {
|
|
799
|
-
this.updateEntityList(
|
|
825
|
+
this.updateEntityList(D, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
|
|
800
826
|
this.updateEntityList(t, n, e, !1);
|
|
801
827
|
});
|
|
802
828
|
}
|
|
@@ -811,7 +837,7 @@ var w = class extends S {
|
|
|
811
837
|
destroy() {
|
|
812
838
|
super.destroy(), this.pendingEffects?.discard(), "terminate" in this.worker && this.worker.terminate();
|
|
813
839
|
}
|
|
814
|
-
},
|
|
840
|
+
}, k = class extends b.default {
|
|
815
841
|
eid;
|
|
816
842
|
config;
|
|
817
843
|
world;
|
|
@@ -873,12 +899,7 @@ var w = class extends S {
|
|
|
873
899
|
}
|
|
874
900
|
}
|
|
875
901
|
load(e) {
|
|
876
|
-
let t
|
|
877
|
-
for (let r of Object.keys(n)) {
|
|
878
|
-
if (r === "entity" || !this.isComponentAllowed(r)) continue;
|
|
879
|
-
let i = n[r];
|
|
880
|
-
i.loadInFinishLoading || i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
|
|
881
|
-
}
|
|
902
|
+
for (let { name: t } of this.world.componentTriggers.forLoad(e)) this.isComponentAllowed(t) && this.loadComponent(t, e, !1);
|
|
882
903
|
this.config = e;
|
|
883
904
|
}
|
|
884
905
|
save() {
|
|
@@ -891,13 +912,7 @@ var w = class extends S {
|
|
|
891
912
|
}
|
|
892
913
|
finishLoading() {
|
|
893
914
|
let e = this.config;
|
|
894
|
-
if (
|
|
895
|
-
let t = e, n = this.world.registry;
|
|
896
|
-
for (let r of Object.keys(n)) {
|
|
897
|
-
if (r === "entity" || !this.isComponentAllowed(r)) continue;
|
|
898
|
-
let i = n[r];
|
|
899
|
-
i.loadInFinishLoading && i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
|
|
900
|
-
}
|
|
915
|
+
if (e) for (let { name: t } of this.world.componentTriggers.forFinishLoading(e)) this.isComponentAllowed(t) && this.loadComponent(t, e, !1);
|
|
901
916
|
}
|
|
902
917
|
isComponentAllowed(e) {
|
|
903
918
|
return e === "entity" || !this.allowedComponents || this.allowedComponents.has(String(e));
|
|
@@ -912,7 +927,7 @@ var w = class extends S {
|
|
|
912
927
|
assertComponentPropertyMutable(e, t) {
|
|
913
928
|
if (e === "entity" && (t === "type" || t === "class")) throw Error(`Entity ${t} is immutable`);
|
|
914
929
|
}
|
|
915
|
-
},
|
|
930
|
+
}, A = class e {
|
|
916
931
|
world;
|
|
917
932
|
configs;
|
|
918
933
|
classes;
|
|
@@ -929,7 +944,7 @@ var w = class extends S {
|
|
|
929
944
|
this.world = e, this.forbiddenProperties.clear();
|
|
930
945
|
for (let t of Object.keys(this.classes)) {
|
|
931
946
|
let n = this.classes[t].entity;
|
|
932
|
-
if (n !==
|
|
947
|
+
if (n !== k && !(n.prototype instanceof k)) throw Error(`Entity class ${t} must extend BaseEntity`);
|
|
933
948
|
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}`);
|
|
934
949
|
}
|
|
935
950
|
for (let e of Object.keys(this.configs)) this.validateTemplate(e, this.configs[e]);
|
|
@@ -955,7 +970,7 @@ var w = class extends S {
|
|
|
955
970
|
createAdoptedEntity(e, t, n) {
|
|
956
971
|
if (!t) {
|
|
957
972
|
if (this.hasClasses) throw Error(`Entity type ${e} has no class`);
|
|
958
|
-
return new
|
|
973
|
+
return new k(this.world, void 0, n);
|
|
959
974
|
}
|
|
960
975
|
let r = this.classes[t];
|
|
961
976
|
if (!r) throw Error(`Unknown entity class: ${t}`);
|
|
@@ -981,7 +996,7 @@ var w = class extends S {
|
|
|
981
996
|
return e ? this.getAllowedComponents(e) : void 0;
|
|
982
997
|
}
|
|
983
998
|
createEntity(e) {
|
|
984
|
-
return new
|
|
999
|
+
return new k(this.world, e);
|
|
985
1000
|
}
|
|
986
1001
|
get hasClasses() {
|
|
987
1002
|
return this.allowedComponents.size > 0;
|
|
@@ -1046,42 +1061,42 @@ var w = class extends S {
|
|
|
1046
1061
|
}
|
|
1047
1062
|
throw Error(`Entity type ${e} class ${t} loads a component outside its class`);
|
|
1048
1063
|
}
|
|
1049
|
-
},
|
|
1050
|
-
for (let e = 0; e <
|
|
1051
|
-
function
|
|
1064
|
+
}, j = 45, M = "!", N = "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO", P = "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}", F = (/* @__PURE__ */ new Int8Array(128)).fill(-1);
|
|
1065
|
+
for (let e = 0; e < j; e++) F[N.charCodeAt(e)] = e, F[P.charCodeAt(e)] = e + j;
|
|
1066
|
+
function I(e) {
|
|
1052
1067
|
let t = "";
|
|
1053
|
-
for (; e >=
|
|
1054
|
-
return t +
|
|
1068
|
+
for (; e >= j;) t += P[e % j], e = Math.floor(e / j);
|
|
1069
|
+
return t + N[e];
|
|
1055
1070
|
}
|
|
1056
|
-
var
|
|
1057
|
-
function
|
|
1071
|
+
var L = /* @__PURE__ */ new Float32Array(1), R = new Uint32Array(L.buffer);
|
|
1072
|
+
function z(e, t) {
|
|
1058
1073
|
switch (e.type) {
|
|
1059
|
-
case "boolean": return typeof t == "boolean" ?
|
|
1060
|
-
case "string": return t === null ?
|
|
1061
|
-
case "float32": return typeof t != "number" || !Number.isFinite(t) || Math.fround(t) !== t ? void 0 : (
|
|
1074
|
+
case "boolean": return typeof t == "boolean" ? N[Number(t)] : void 0;
|
|
1075
|
+
case "string": return t === null ? N[0] : typeof t == "string" && t.length ? I(t.length) + t : void 0;
|
|
1076
|
+
case "float32": return typeof t != "number" || !Number.isFinite(t) || Math.fround(t) !== t ? void 0 : (L[0] = t, I(R[0]));
|
|
1062
1077
|
default: {
|
|
1063
|
-
let n =
|
|
1064
|
-
return n === void 0 ? void 0 :
|
|
1078
|
+
let n = B(e, t);
|
|
1079
|
+
return n === void 0 ? void 0 : I(n);
|
|
1065
1080
|
}
|
|
1066
1081
|
}
|
|
1067
1082
|
}
|
|
1068
|
-
function
|
|
1083
|
+
function B(e, t) {
|
|
1069
1084
|
if (typeof t != "number") return;
|
|
1070
1085
|
let n = Math.round((t - (e.offset ?? 0)) * 10 ** (e.decimals ?? 0) / (e.step ?? 1));
|
|
1071
|
-
if (!Number.isSafeInteger(n) ||
|
|
1086
|
+
if (!Number.isSafeInteger(n) || V(e, n) !== t) return;
|
|
1072
1087
|
if (e.type === "uint") return n >= 0 ? n : void 0;
|
|
1073
1088
|
let r = n >= 0 ? n * 2 : -n * 2 - 1;
|
|
1074
1089
|
return Number.isSafeInteger(r) ? r : void 0;
|
|
1075
1090
|
}
|
|
1076
|
-
function
|
|
1091
|
+
function V(e, t) {
|
|
1077
1092
|
return t * (e.step ?? 1) / 10 ** (e.decimals ?? 0) + (e.offset ?? 0);
|
|
1078
1093
|
}
|
|
1079
|
-
function
|
|
1094
|
+
function me(e, t) {
|
|
1080
1095
|
switch (e.type) {
|
|
1081
1096
|
case "boolean": return t !== 0;
|
|
1082
|
-
case "float32": return
|
|
1083
|
-
case "uint": return
|
|
1084
|
-
default: return
|
|
1097
|
+
case "float32": return R[0] = t, L[0];
|
|
1098
|
+
case "uint": return V(e, t);
|
|
1099
|
+
default: return V(e, t % 2 == 0 ? t / 2 : -(t + 1) / 2);
|
|
1085
1100
|
}
|
|
1086
1101
|
}
|
|
1087
1102
|
function H(e) {
|
|
@@ -1101,7 +1116,7 @@ var U = class {
|
|
|
1101
1116
|
for (let r of H(n)) {
|
|
1102
1117
|
if (this.encoders.has(r)) throw Error(`Duplicate compressed entity definition for ${r}`);
|
|
1103
1118
|
this.encoders.set(r, {
|
|
1104
|
-
prefix:
|
|
1119
|
+
prefix: I(t++),
|
|
1105
1120
|
group: e
|
|
1106
1121
|
});
|
|
1107
1122
|
}
|
|
@@ -1129,20 +1144,20 @@ var U = class {
|
|
|
1129
1144
|
if (r === "type" || i === void 0) continue;
|
|
1130
1145
|
let t = e.group.indices.get(r);
|
|
1131
1146
|
if (t === void 0) return;
|
|
1132
|
-
let a =
|
|
1147
|
+
let a = z(e.group.definition.properties[t], i);
|
|
1133
1148
|
if (a === void 0) return;
|
|
1134
1149
|
n[t] = a;
|
|
1135
1150
|
}
|
|
1136
1151
|
let r = e.prefix;
|
|
1137
|
-
for (let e = 0; e < n.length; e++) r += n[e] ??
|
|
1152
|
+
for (let e = 0; e < n.length; e++) r += n[e] ?? M;
|
|
1138
1153
|
return r;
|
|
1139
1154
|
}
|
|
1140
1155
|
};
|
|
1141
|
-
function
|
|
1156
|
+
function he(e, t) {
|
|
1142
1157
|
return new U(t).compressAll(e);
|
|
1143
1158
|
}
|
|
1144
1159
|
var W = /* @__PURE__ */ new WeakMap();
|
|
1145
|
-
function
|
|
1160
|
+
function ge(e) {
|
|
1146
1161
|
let t = W.get(e);
|
|
1147
1162
|
if (t) return t;
|
|
1148
1163
|
t = /* @__PURE__ */ new Map();
|
|
@@ -1160,19 +1175,19 @@ function de(e) {
|
|
|
1160
1175
|
}
|
|
1161
1176
|
function G(e, t) {
|
|
1162
1177
|
let n = 0, r = () => {
|
|
1163
|
-
if (e[n] ===
|
|
1178
|
+
if (e[n] === M) {
|
|
1164
1179
|
n++;
|
|
1165
1180
|
return;
|
|
1166
1181
|
}
|
|
1167
1182
|
let t = 0, r = 1;
|
|
1168
1183
|
for (; n < e.length;) {
|
|
1169
|
-
let i = e.charCodeAt(n++), a = i < 128 ?
|
|
1184
|
+
let i = e.charCodeAt(n++), a = i < 128 ? F[i] : -1;
|
|
1170
1185
|
if (a < 0) throw Error(`Invalid compressed entity ${e}`);
|
|
1171
|
-
if (a <
|
|
1172
|
-
t += (a -
|
|
1186
|
+
if (a < j) return t + a * r;
|
|
1187
|
+
t += (a - j) * r, r *= j;
|
|
1173
1188
|
}
|
|
1174
1189
|
throw Error(`Truncated compressed entity ${e}`);
|
|
1175
|
-
}, i = r(), a = i === void 0 ? void 0 :
|
|
1190
|
+
}, i = r(), a = i === void 0 ? void 0 : ge(t).get(i);
|
|
1176
1191
|
if (!a) throw Error(`No compressed entity definition for ${e}`);
|
|
1177
1192
|
let o = { type: a.type };
|
|
1178
1193
|
for (let t = 0; n < e.length; t++) {
|
|
@@ -1180,7 +1195,7 @@ function G(e, t) {
|
|
|
1180
1195
|
if (!i) throw Error(`Compressed entity ${e} has more values than ${a.type} defines`);
|
|
1181
1196
|
let s = r();
|
|
1182
1197
|
if (s !== void 0) {
|
|
1183
|
-
if (i.type !== "string") o[i.name] =
|
|
1198
|
+
if (i.type !== "string") o[i.name] = me(i, s);
|
|
1184
1199
|
else if (s === 0) o[i.name] = null;
|
|
1185
1200
|
else {
|
|
1186
1201
|
if (n + s > e.length) throw Error(`Truncated compressed entity ${e}`);
|
|
@@ -1190,7 +1205,7 @@ function G(e, t) {
|
|
|
1190
1205
|
}
|
|
1191
1206
|
return o;
|
|
1192
1207
|
}
|
|
1193
|
-
function
|
|
1208
|
+
function _e(e, t) {
|
|
1194
1209
|
return e.map((e) => K(e, t));
|
|
1195
1210
|
}
|
|
1196
1211
|
function K(e, t) {
|
|
@@ -1198,8 +1213,7 @@ function K(e, t) {
|
|
|
1198
1213
|
if (!t) throw Error("Compressed entities need entityDefinitions to load");
|
|
1199
1214
|
return G(e, t);
|
|
1200
1215
|
}
|
|
1201
|
-
|
|
1202
|
-
//#region src/scheduling/default-scheduler.ts
|
|
1216
|
+
// src/scheduling/default-scheduler.ts
|
|
1203
1217
|
var q = class {
|
|
1204
1218
|
update(e, t) {
|
|
1205
1219
|
let n = null;
|
|
@@ -1223,7 +1237,7 @@ var q = class {
|
|
|
1223
1237
|
});
|
|
1224
1238
|
}), { lastSystemError: n };
|
|
1225
1239
|
}
|
|
1226
|
-
},
|
|
1240
|
+
}, ve = g, J = 1e4, ye = {
|
|
1227
1241
|
entities: {
|
|
1228
1242
|
start: 0,
|
|
1229
1243
|
weight: .6
|
|
@@ -1240,11 +1254,12 @@ var q = class {
|
|
|
1240
1254
|
start: .8,
|
|
1241
1255
|
weight: .2
|
|
1242
1256
|
}
|
|
1243
|
-
}, Y = 256,
|
|
1257
|
+
}, Y = 256, be = class extends b.default {
|
|
1244
1258
|
heap;
|
|
1245
1259
|
constantStrings;
|
|
1246
1260
|
eidCounter;
|
|
1247
1261
|
registry;
|
|
1262
|
+
componentTriggers;
|
|
1248
1263
|
factory;
|
|
1249
1264
|
entities = /* @__PURE__ */ new Map();
|
|
1250
1265
|
systems = [];
|
|
@@ -1270,19 +1285,19 @@ var q = class {
|
|
|
1270
1285
|
};
|
|
1271
1286
|
clearing = !1;
|
|
1272
1287
|
constructor(e, t = {}) {
|
|
1273
|
-
super(), this.scheduler = t.scheduler ?? new q(), this.heap = new
|
|
1274
|
-
let
|
|
1288
|
+
super(), this.scheduler = t.scheduler ?? new q(), this.heap = new ae({ bufferSize: t.heapSize ?? ve }), this.constantStrings = new n(this.heap), this.eidCounter = this.heap.allocUI32(1), this.heap.addOnGrowBufferHandlers((e) => this.emit("grow-buffer", e));
|
|
1289
|
+
let r = {
|
|
1275
1290
|
...e,
|
|
1276
|
-
entity:
|
|
1277
|
-
},
|
|
1278
|
-
for (let e of Object.keys(
|
|
1279
|
-
let t =
|
|
1280
|
-
|
|
1291
|
+
entity: a
|
|
1292
|
+
}, i = {};
|
|
1293
|
+
for (let e of Object.keys(r)) {
|
|
1294
|
+
let t = r[e];
|
|
1295
|
+
i[e] = {
|
|
1281
1296
|
...t,
|
|
1282
|
-
memoryComponent: new
|
|
1297
|
+
memoryComponent: new m(this.heap, t.type, t.size)
|
|
1283
1298
|
};
|
|
1284
1299
|
}
|
|
1285
|
-
this.registry =
|
|
1300
|
+
this.registry = i, this.componentTriggers = new pe(this.registry), this.factory = t.factory ?? new A(), this.factory.setWorld(this);
|
|
1286
1301
|
}
|
|
1287
1302
|
allocateEid() {
|
|
1288
1303
|
return Atomics.add(this.eidCounter.data, 0, 1) + 1;
|
|
@@ -1299,7 +1314,7 @@ var q = class {
|
|
|
1299
1314
|
this.heap.buffers[e.bufferPosition] === void 0 && this.heap.addSharedBuffer(e), this.emit("grow-buffer", e);
|
|
1300
1315
|
}
|
|
1301
1316
|
get needsSpareBuffer() {
|
|
1302
|
-
return this.systems.some((e) => e instanceof
|
|
1317
|
+
return this.systems.some((e) => e instanceof O && e.isWorkerThread && (!!e.options.createsEntities || !!e.options.addsComponents));
|
|
1303
1318
|
}
|
|
1304
1319
|
async init() {
|
|
1305
1320
|
await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
|
|
@@ -1361,7 +1376,7 @@ var q = class {
|
|
|
1361
1376
|
return this.loadSliced(n, t.sliceMs, r, i, t);
|
|
1362
1377
|
}
|
|
1363
1378
|
async loadSliced(e, t, n, r, i) {
|
|
1364
|
-
let a = i.yieldTo ??
|
|
1379
|
+
let a = i.yieldTo ?? xe;
|
|
1365
1380
|
try {
|
|
1366
1381
|
r.throwIfAborted();
|
|
1367
1382
|
let n = performance.now(), o = e.next();
|
|
@@ -1388,7 +1403,7 @@ var q = class {
|
|
|
1388
1403
|
} finally {
|
|
1389
1404
|
this.isBulkLoading = !1;
|
|
1390
1405
|
}
|
|
1391
|
-
let i =
|
|
1406
|
+
let i = Ce(this.entities.values()), a = this.systems.slice(), o = a.length * 2;
|
|
1392
1407
|
for (let e = 0; e < a.length; e++) a[e].addEntities(i), yield X("systems", e + 1, o);
|
|
1393
1408
|
this.gameTime = e.gameTime ?? 0, this.playerTime = e.playerTime ?? 0, this.timeScale = e.timeScale ?? 1;
|
|
1394
1409
|
let s = [];
|
|
@@ -1404,7 +1419,7 @@ var q = class {
|
|
|
1404
1419
|
let i = Promise.all(e.map(async (n) => {
|
|
1405
1420
|
await n, t?.(X("workers", ++r, e.length));
|
|
1406
1421
|
}));
|
|
1407
|
-
n ? await Promise.race([i,
|
|
1422
|
+
n ? await Promise.race([i, Se(n)]) : await i;
|
|
1408
1423
|
}
|
|
1409
1424
|
abortActiveLoad() {
|
|
1410
1425
|
this.activeLoad && (this.activeLoad.abort(), this.activeLoad = void 0, this.isBulkLoading = !1, this.isLoading = !1);
|
|
@@ -1533,12 +1548,12 @@ var q = class {
|
|
|
1533
1548
|
}
|
|
1534
1549
|
addEntityToEntityWorkerSystem(e, t) {
|
|
1535
1550
|
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1536
|
-
(n instanceof
|
|
1551
|
+
(n instanceof w && n.options.components?.includes(t) || n instanceof O && this.queriesReferenceComponent(n.options, t)) && n.checkAddEntity(e);
|
|
1537
1552
|
});
|
|
1538
1553
|
}
|
|
1539
1554
|
removeEntityFromEntityWorkerSystem(e, t) {
|
|
1540
1555
|
this.isBulkLoading || this.systems.forEach((n) => {
|
|
1541
|
-
n instanceof
|
|
1556
|
+
n instanceof w && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof O && this.queriesReferenceComponent(n.options, t) && n.checkAddEntity(e);
|
|
1542
1557
|
});
|
|
1543
1558
|
}
|
|
1544
1559
|
queriesReferenceComponent(e, t) {
|
|
@@ -1552,7 +1567,7 @@ var q = class {
|
|
|
1552
1567
|
}
|
|
1553
1568
|
};
|
|
1554
1569
|
function X(e, t, n) {
|
|
1555
|
-
let { start: r, weight: i } =
|
|
1570
|
+
let { start: r, weight: i } = ye[e];
|
|
1556
1571
|
return {
|
|
1557
1572
|
phase: e,
|
|
1558
1573
|
done: t,
|
|
@@ -1560,16 +1575,16 @@ function X(e, t, n) {
|
|
|
1560
1575
|
fraction: r + i * (n === 0 ? 1 : t / n)
|
|
1561
1576
|
};
|
|
1562
1577
|
}
|
|
1563
|
-
function
|
|
1578
|
+
function xe() {
|
|
1564
1579
|
let e = globalThis.scheduler;
|
|
1565
1580
|
return e?.yield ? e.yield() : new Promise((e) => setTimeout(e, 0));
|
|
1566
1581
|
}
|
|
1567
|
-
function
|
|
1582
|
+
function Se(e) {
|
|
1568
1583
|
return new Promise((t, n) => {
|
|
1569
1584
|
e.aborted ? n(e.reason) : e.addEventListener("abort", () => n(e.reason), { once: !0 });
|
|
1570
1585
|
});
|
|
1571
1586
|
}
|
|
1572
|
-
function
|
|
1587
|
+
function Ce(e) {
|
|
1573
1588
|
let t = {
|
|
1574
1589
|
entities: [],
|
|
1575
1590
|
groupIndexes: [],
|
|
@@ -1581,9 +1596,8 @@ function _e(e) {
|
|
|
1581
1596
|
}
|
|
1582
1597
|
return t;
|
|
1583
1598
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
var ve = class {
|
|
1599
|
+
// src/scheduling/conflict-scheduler.ts
|
|
1600
|
+
var we = class {
|
|
1587
1601
|
compiled = Object.freeze({
|
|
1588
1602
|
order: Object.freeze([]),
|
|
1589
1603
|
batches: Object.freeze([])
|
|
@@ -1666,7 +1680,7 @@ var ve = class {
|
|
|
1666
1680
|
}, 0);
|
|
1667
1681
|
}
|
|
1668
1682
|
isSliced(e) {
|
|
1669
|
-
return e.system instanceof
|
|
1683
|
+
return e.system instanceof C && e.system.remainingInstancesToRun.length > 0;
|
|
1670
1684
|
}
|
|
1671
1685
|
reset() {
|
|
1672
1686
|
this.continuationTimer !== void 0 && (clearTimeout(this.continuationTimer), this.continuationTimer = void 0);
|
|
@@ -1679,15 +1693,7 @@ var ve = class {
|
|
|
1679
1693
|
prepareEffects(e, t) {
|
|
1680
1694
|
let n = this.running.get(t), r = this.generation;
|
|
1681
1695
|
return (e) => {
|
|
1682
|
-
|
|
1683
|
-
e.discard();
|
|
1684
|
-
return;
|
|
1685
|
-
}
|
|
1686
|
-
if (!n) {
|
|
1687
|
-
e.apply();
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
n.effects = e, this.publications.add(n), n.publicationDependencies === 0 && this.publicationReady.push(n), this.publish();
|
|
1696
|
+
r !== this.generation || n && !this.nodes.has(n) ? e.discard() : n ? (n.effects = e, this.publications.add(n), n.publicationDependencies === 0 && this.publicationReady.push(n), this.publish()) : e.apply();
|
|
1691
1697
|
};
|
|
1692
1698
|
}
|
|
1693
1699
|
publish() {
|
|
@@ -1836,29 +1842,26 @@ var ve = class {
|
|
|
1836
1842
|
return e.creates.size > 0 && this.observesCreation(e, t);
|
|
1837
1843
|
}
|
|
1838
1844
|
};
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
function ye(e, t) {
|
|
1845
|
+
// src/entity-class.ts
|
|
1846
|
+
function Te(e, t) {
|
|
1842
1847
|
return t;
|
|
1843
1848
|
}
|
|
1844
|
-
function
|
|
1849
|
+
function Ee(e, t) {
|
|
1845
1850
|
return t;
|
|
1846
1851
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
function xe(e) {
|
|
1852
|
+
// src/actions/kill-entity.ts
|
|
1853
|
+
function De(e) {
|
|
1850
1854
|
e.components.entity.dead = !0, e.emit("death");
|
|
1851
1855
|
}
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
var Se = 1e3, Q = {
|
|
1856
|
+
// src/performance-timing.ts
|
|
1857
|
+
var Oe = 1e3, Z = {
|
|
1855
1858
|
avg: 0,
|
|
1856
1859
|
min: 0,
|
|
1857
1860
|
max: 0,
|
|
1858
1861
|
samples: 0
|
|
1859
1862
|
};
|
|
1860
|
-
function
|
|
1861
|
-
if (!e.length) return { ...
|
|
1863
|
+
function Q(e) {
|
|
1864
|
+
if (!e.length) return { ...Z };
|
|
1862
1865
|
let t = 0, n = Infinity, r = 0;
|
|
1863
1866
|
for (let i of e) t += i, i < n && (n = i), i > r && (r = i);
|
|
1864
1867
|
return {
|
|
@@ -1868,13 +1871,13 @@ function $(e) {
|
|
|
1868
1871
|
samples: e.length
|
|
1869
1872
|
};
|
|
1870
1873
|
}
|
|
1871
|
-
var
|
|
1874
|
+
var ke = class extends b.default {
|
|
1872
1875
|
world;
|
|
1873
1876
|
ticksBetweenUpdates;
|
|
1874
1877
|
stats = {
|
|
1875
|
-
update: { ...
|
|
1878
|
+
update: { ...Z },
|
|
1876
1879
|
systems: [],
|
|
1877
|
-
events: { ...
|
|
1880
|
+
events: { ...Z }
|
|
1878
1881
|
};
|
|
1879
1882
|
autoUpdate;
|
|
1880
1883
|
ticks = 0;
|
|
@@ -1892,9 +1895,9 @@ var Ce = class extends x.default {
|
|
|
1892
1895
|
this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
1893
1896
|
e.run = [], e.events = [], e.eventStart = -1, e.pendingRun = 0, e.pendingEvents = 0;
|
|
1894
1897
|
}), this.stats = {
|
|
1895
|
-
update: { ...
|
|
1898
|
+
update: { ...Z },
|
|
1896
1899
|
systems: [],
|
|
1897
|
-
events: { ...
|
|
1900
|
+
events: { ...Z }
|
|
1898
1901
|
};
|
|
1899
1902
|
}
|
|
1900
1903
|
destroy() {
|
|
@@ -1939,26 +1942,26 @@ var Ce = class extends x.default {
|
|
|
1939
1942
|
let t = this.systemTimings.get(e.name);
|
|
1940
1943
|
return {
|
|
1941
1944
|
name: e.name,
|
|
1942
|
-
run:
|
|
1943
|
-
events:
|
|
1945
|
+
run: Q(t?.run ?? []),
|
|
1946
|
+
events: Q(t?.events ?? [])
|
|
1944
1947
|
};
|
|
1945
|
-
}), t = { ...
|
|
1948
|
+
}), t = { ...Z };
|
|
1946
1949
|
return e.forEach((e) => {
|
|
1947
1950
|
t.avg += e.events.avg, t.min += e.events.min, t.max += e.events.max, t.samples += e.events.samples;
|
|
1948
1951
|
}), this.stats = {
|
|
1949
|
-
update:
|
|
1952
|
+
update: Q(this.updateTimes),
|
|
1950
1953
|
systems: e,
|
|
1951
1954
|
events: t
|
|
1952
1955
|
}, this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
1953
1956
|
e.run = [], e.events = [];
|
|
1954
1957
|
}), this.emit("stats-updated", this.stats), this.stats;
|
|
1955
1958
|
}
|
|
1956
|
-
},
|
|
1959
|
+
}, $ = class extends O {
|
|
1957
1960
|
constructor(e, t) {
|
|
1958
1961
|
super(e, {
|
|
1959
1962
|
...t,
|
|
1960
1963
|
required: [],
|
|
1961
|
-
updateFunction:
|
|
1964
|
+
updateFunction: d(t.updateFunction)
|
|
1962
1965
|
});
|
|
1963
1966
|
}
|
|
1964
1967
|
get tracksMainQuery() {
|
|
@@ -1968,7 +1971,6 @@ var Ce = class extends x.default {
|
|
|
1968
1971
|
return !0;
|
|
1969
1972
|
}
|
|
1970
1973
|
};
|
|
1971
|
-
|
|
1972
|
-
export { A as BaseEntity, he as BaseWorld, n as CLASS_INDEX, f as Component, ve as ConflictScheduler, m as ConstantStringCache, c as DEAD_INDEX, Se as DEFAULT_TICKS_BETWEEN_UPDATES, q as DefaultScheduler, U as EntityCompressor, j as EntityFactory, T as EntitySystem, D as EntitySystemWebWorker, k as EntityWorkerSystem, w as IterableSystem, h as MemoryComponent, Ce as PerformanceTiming, ne as STATIC_INDEX, S as System, r as TYPE_INDEX, E as WebWorker, we as WorkerSystem, t as addComponentWorker, ue as compressEntities, p as createEntitySystemWorker, d as createEntityWorker, te as createSystemWorker, fe as decompressEntities, G as decompressEntity, ye as defineEntityClasses, be as defineEntityConfigs, i as entityDefinition, xe as killEntity, ee as killEntityWorker, s as removeComponentWorker };
|
|
1974
|
+
export { k as BaseEntity, be as BaseWorld, r as CLASS_INDEX, p as Component, we as ConflictScheduler, n as ConstantStringCache, l as DEAD_INDEX, Oe as DEFAULT_TICKS_BETWEEN_UPDATES, q as DefaultScheduler, U as EntityCompressor, A as EntityFactory, w as EntitySystem, E as EntitySystemWebWorker, O as EntityWorkerSystem, C as IterableSystem, m as MemoryComponent, ke as PerformanceTiming, re as STATIC_INDEX, x as System, i as TYPE_INDEX, T as WebWorker, $ as WorkerSystem, t as addComponentWorker, he as compressEntities, ee as createEntitySystemWorker, f as createEntityWorker, ne as createSystemWorker, _e as decompressEntities, G as decompressEntity, Te as defineEntityClasses, Ee as defineEntityConfigs, a as entityDefinition, De as killEntity, te as killEntityWorker, c as removeComponentWorker };
|
|
1973
1975
|
|
|
1974
1976
|
//# sourceMappingURL=index.js.map
|