@daneren2005/shared-memory-ecs 1.2.1 → 1.3.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 +86 -1
- package/dist/component-definition.d.ts +1 -1
- package/dist/create-component-worker-vbX3vEia.js +135 -0
- package/dist/create-component-worker-vbX3vEia.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -190
- package/dist/index.js.map +1 -1
- package/dist/memory-component.d.ts +3 -1
- package/dist/systems/component-system.d.ts +15 -8
- package/dist/systems/system.d.ts +1 -1
- package/dist/systems/workers/component-web-worker.d.ts +5 -4
- package/dist/systems/workers/component-worker-message.d.ts +13 -1
- package/dist/systems/workers/create-component-worker.d.ts +1 -1
- package/dist/worker.d.ts +8 -0
- package/dist/worker.js +2 -0
- package/dist/world.d.ts +2 -1
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./create-component-worker-vbX3vEia.js";
|
|
2
|
+
import s from "@daneren2005/shared-memory-objects/memory-heap";
|
|
3
|
+
import { MAX_BYTE_OFFSET_LENGTH as c } from "@daneren2005/shared-memory-objects/utils/pointer";
|
|
4
|
+
import l from "@daneren2005/shared-memory-objects/local-pool";
|
|
2
5
|
//#region \0rolldown/runtime.js
|
|
3
|
-
var
|
|
4
|
-
if (t && typeof t == "object" || typeof t == "function") for (var
|
|
5
|
-
get: ((e) => t[e]).bind(null,
|
|
6
|
-
enumerable: !(r =
|
|
6
|
+
var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescriptor, p = Object.getOwnPropertyNames, m = Object.getPrototypeOf, h = Object.prototype.hasOwnProperty, g = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), _ = (e, t, n, r) => {
|
|
7
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = p(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !h.call(e, s) && s !== n && d(e, s, {
|
|
8
|
+
get: ((e) => t[e]).bind(null, s),
|
|
9
|
+
enumerable: !(r = f(t, s)) || r.enumerable
|
|
7
10
|
});
|
|
8
11
|
return e;
|
|
9
|
-
},
|
|
12
|
+
}, v = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : u(m(e)), _(t || !e || !e.__esModule ? d(n, "default", {
|
|
10
13
|
value: e,
|
|
11
14
|
enumerable: !0
|
|
12
|
-
}) : n, e)))((/* @__PURE__ */
|
|
15
|
+
}) : n, e)))((/* @__PURE__ */ g(((e, t) => {
|
|
13
16
|
var n = Object.prototype.hasOwnProperty, r = "~";
|
|
14
17
|
function i() {}
|
|
15
18
|
Object.create && (i.prototype = Object.create(null), new i().__proto__ || (r = !1));
|
|
@@ -96,13 +99,13 @@ var r = Object.create, i = Object.defineProperty, a = Object.getOwnPropertyDescr
|
|
|
96
99
|
var t;
|
|
97
100
|
return e ? (t = r ? r + e : e, this._events[t] && s(this, t)) : (this._events = new i(), this._eventsCount = 0), this;
|
|
98
101
|
}, c.prototype.off = c.prototype.removeListener, c.prototype.addListener = c.prototype.on, c.prefixed = r, c.EventEmitter = c, t !== void 0 && (t.exports = c);
|
|
99
|
-
})))(), 1),
|
|
102
|
+
})))(), 1), y = class {
|
|
100
103
|
heap;
|
|
101
104
|
pool;
|
|
102
|
-
constructor(t, n
|
|
103
|
-
this.heap =
|
|
104
|
-
type:
|
|
105
|
-
dataLength:
|
|
105
|
+
constructor(e, t, n) {
|
|
106
|
+
this.heap = e, this.pool = new l(e, {
|
|
107
|
+
type: t,
|
|
108
|
+
dataLength: n
|
|
106
109
|
});
|
|
107
110
|
}
|
|
108
111
|
get length() {
|
|
@@ -130,7 +133,7 @@ var r = Object.create, i = Object.defineProperty, a = Object.getOwnPropertyDescr
|
|
|
130
133
|
clear() {
|
|
131
134
|
this.pool.clear();
|
|
132
135
|
}
|
|
133
|
-
},
|
|
136
|
+
}, b = class extends v.default {
|
|
134
137
|
world;
|
|
135
138
|
name;
|
|
136
139
|
currentDelta = 0;
|
|
@@ -156,7 +159,7 @@ var r = Object.create, i = Object.defineProperty, a = Object.getOwnPropertyDescr
|
|
|
156
159
|
destroy() {
|
|
157
160
|
this.removeAllListeners();
|
|
158
161
|
}
|
|
159
|
-
},
|
|
162
|
+
}, x = class extends b {
|
|
160
163
|
remainingInstancesToRun = [];
|
|
161
164
|
remainingInstancesStartTime = null;
|
|
162
165
|
iterationsPerCheck;
|
|
@@ -184,7 +187,7 @@ var r = Object.create, i = Object.defineProperty, a = Object.getOwnPropertyDescr
|
|
|
184
187
|
this.remainingInstancesToRun = [], this.remainingInstancesStartTime = null;
|
|
185
188
|
}
|
|
186
189
|
beforeRunIterables() {}
|
|
187
|
-
},
|
|
190
|
+
}, S = class extends x {
|
|
188
191
|
entities = /* @__PURE__ */ new Map();
|
|
189
192
|
options;
|
|
190
193
|
constructor(e, t = { name: "EntitySystem" }) {
|
|
@@ -220,46 +223,30 @@ var r = Object.create, i = Object.defineProperty, a = Object.getOwnPropertyDescr
|
|
|
220
223
|
shouldRun() {
|
|
221
224
|
return this.entities.size > 0;
|
|
222
225
|
}
|
|
223
|
-
},
|
|
226
|
+
}, C = class {
|
|
224
227
|
onmessage(e, t = []) {}
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/systems/workers/apply-query-delta.ts
|
|
228
|
-
function _(e, t) {
|
|
229
|
-
if (t.removed.length) {
|
|
230
|
-
let n = new Set(t.removed);
|
|
231
|
-
e = e.filter((e) => !n.has(e.entityId));
|
|
232
|
-
}
|
|
233
|
-
if (t.added.length) {
|
|
234
|
-
let n = /* @__PURE__ */ new Map();
|
|
235
|
-
e.forEach((e, t) => n.set(e.entityId, t));
|
|
236
|
-
for (let r of t.added) {
|
|
237
|
-
let t = n.get(r.entityId);
|
|
238
|
-
t === void 0 ? (n.set(r.entityId, e.length), e.push(r)) : e[t] = r;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return e;
|
|
242
|
-
}
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/systems/workers/component-web-worker.ts
|
|
245
|
-
var v = class extends g {
|
|
228
|
+
}, w = class extends C {
|
|
246
229
|
updateFunction;
|
|
247
230
|
entities = [];
|
|
248
231
|
queryEntities = {};
|
|
232
|
+
worldExtension;
|
|
249
233
|
constructor(e) {
|
|
250
234
|
super(), this.updateFunction = e;
|
|
251
235
|
}
|
|
252
236
|
postMessage(e) {
|
|
253
|
-
if (e.type === "init") this.onMessageTyped({ type: "
|
|
237
|
+
if (e.type === "init") this.onMessageTyped({ type: "init-complete" });
|
|
238
|
+
else if (e.type === "load") this.worldExtension = this.updateFunction.init?.(e.data) ?? void 0, this.onMessageTyped({ type: "loaded" });
|
|
239
|
+
else if (e.type === "reset") this.entities = [], this.queryEntities = {};
|
|
254
240
|
else if (e.type === "run") {
|
|
241
|
+
this.worldExtension && Object.assign(e.world, this.worldExtension);
|
|
255
242
|
let t = performance.now(), n = [], r = {}, i = [];
|
|
256
|
-
this.entities =
|
|
257
|
-
let
|
|
243
|
+
this.entities = a(this.entities, e.entities);
|
|
244
|
+
let o = {};
|
|
258
245
|
Object.entries(e.queries).forEach(([e, t]) => {
|
|
259
|
-
let n =
|
|
260
|
-
this.queryEntities[e] = n,
|
|
246
|
+
let n = a(this.queryEntities[e] ?? [], t);
|
|
247
|
+
this.queryEntities[e] = n, o[e] = n;
|
|
261
248
|
});
|
|
262
|
-
let
|
|
249
|
+
let s = {
|
|
263
250
|
entityComponentChanged(e, t, r, i) {
|
|
264
251
|
n.push({
|
|
265
252
|
entityId: e,
|
|
@@ -292,13 +279,14 @@ var v = class extends g {
|
|
|
292
279
|
i.push(e);
|
|
293
280
|
}
|
|
294
281
|
};
|
|
295
|
-
if (this.updateFunction.preRun && this.updateFunction.preRun(e.world, this.entities,
|
|
296
|
-
this.updateFunction(e.world, t.entityId, t.components,
|
|
297
|
-
}), this.updateFunction.entityRemoved) for (let t of e.entities.removed) this.updateFunction.entityRemoved(e.world, t,
|
|
298
|
-
let
|
|
282
|
+
if (this.updateFunction.preRun && this.updateFunction.preRun(e.world, this.entities, o, s), this.entities.forEach((t) => {
|
|
283
|
+
this.updateFunction(e.world, t.entityId, t.components, o, s);
|
|
284
|
+
}), this.updateFunction.entityRemoved) for (let t of e.entities.removed) this.updateFunction.entityRemoved(e.world, t, s);
|
|
285
|
+
let c = performance.now() - t;
|
|
299
286
|
this.onMessageTyped({
|
|
300
287
|
type: "run-complete",
|
|
301
|
-
|
|
288
|
+
generation: e.generation,
|
|
289
|
+
runTime: c,
|
|
302
290
|
events: n,
|
|
303
291
|
systemEvents: r,
|
|
304
292
|
created: i
|
|
@@ -308,14 +296,16 @@ var v = class extends g {
|
|
|
308
296
|
onMessageTyped(e) {
|
|
309
297
|
this.onmessage({ data: e });
|
|
310
298
|
}
|
|
311
|
-
},
|
|
299
|
+
}, T = "___main", E = class extends b {
|
|
312
300
|
entities = /* @__PURE__ */ new Map();
|
|
313
301
|
options;
|
|
314
302
|
worker;
|
|
315
303
|
isWorkerThread;
|
|
316
|
-
|
|
304
|
+
initialized = !1;
|
|
305
|
+
initPromise = null;
|
|
317
306
|
loadingPromise = null;
|
|
318
307
|
isRunning = !1;
|
|
308
|
+
generation = 0;
|
|
319
309
|
queryEntities = {};
|
|
320
310
|
queryDeltas = {};
|
|
321
311
|
constructor(e, t) {
|
|
@@ -327,19 +317,21 @@ var v = class extends g {
|
|
|
327
317
|
this.removeEntity(e);
|
|
328
318
|
}), e.entities.forEach((e) => {
|
|
329
319
|
this.checkAddEntity(e);
|
|
330
|
-
}), !t.forceMainThread && globalThis.Worker !== void 0 && globalThis.SharedArrayBuffer !== void 0 ? (this.worker = t.getWorker(), this.isWorkerThread = !0) : (this.worker = new
|
|
320
|
+
}), !t.forceMainThread && globalThis.Worker !== void 0 && globalThis.SharedArrayBuffer !== void 0 ? (this.worker = t.getWorker(), this.isWorkerThread = !0) : (this.worker = new w(t.updateFunction), this.isWorkerThread = !1), this.initWorker();
|
|
331
321
|
}
|
|
332
322
|
initWorker() {
|
|
333
323
|
this.worker.onmessage = (e) => {
|
|
334
324
|
let t = e.data;
|
|
335
|
-
if (t.type === "
|
|
325
|
+
if (t.type === "init-complete") this.initialized = !0, this.initPromise &&= (this.initPromise.resolve(), null);
|
|
326
|
+
else if (t.type === "loaded") this.loadingPromise &&= (this.loadingPromise.resolve(), null);
|
|
336
327
|
else if (t.type === "run-complete") {
|
|
328
|
+
if (t.generation !== this.generation) return;
|
|
337
329
|
this.isRunning = !1, this.world.emit(`system-${this.name}-worker-finished`, t.runTime);
|
|
338
330
|
for (let e of Object.keys(t.systemEvents)) this.emit(e, t.systemEvents[e]);
|
|
339
331
|
t.events.forEach((e) => {
|
|
340
332
|
let t = this.world.getEntityByEid(e.entityId);
|
|
341
333
|
if (!t) {
|
|
342
|
-
console.warn(
|
|
334
|
+
console.warn(`${this.name}-event ${e.event}: Could not find entity with id ${e.entityId}`);
|
|
343
335
|
return;
|
|
344
336
|
}
|
|
345
337
|
t.emit(e.event, ...e.args);
|
|
@@ -350,14 +342,29 @@ var v = class extends g {
|
|
|
350
342
|
}, this.worker.postMessage({ type: "init" });
|
|
351
343
|
}
|
|
352
344
|
init() {
|
|
353
|
-
if (this.
|
|
354
|
-
if (this.
|
|
345
|
+
if (this.initialized) return;
|
|
346
|
+
if (this.initPromise) return this.initPromise.promise;
|
|
355
347
|
let { promise: e, resolve: t } = Promise.withResolvers();
|
|
356
|
-
return this.
|
|
348
|
+
return this.initPromise = {
|
|
357
349
|
promise: e,
|
|
358
350
|
resolve: t
|
|
359
351
|
}, e;
|
|
360
352
|
}
|
|
353
|
+
finishLoading() {
|
|
354
|
+
let { promise: e, resolve: t } = Promise.withResolvers();
|
|
355
|
+
this.loadingPromise = {
|
|
356
|
+
promise: e,
|
|
357
|
+
resolve: t
|
|
358
|
+
};
|
|
359
|
+
let n = {
|
|
360
|
+
type: "load",
|
|
361
|
+
data: this.options.getInitData?.()
|
|
362
|
+
};
|
|
363
|
+
return this.worker.postMessage(n), e;
|
|
364
|
+
}
|
|
365
|
+
clear() {
|
|
366
|
+
super.clear(), this.isRunning = !1, this.generation++, this.entities.clear(), Object.values(this.queryEntities).forEach((e) => e.clear()), this.queryDeltas = {}, this.worker.postMessage({ type: "reset" });
|
|
367
|
+
}
|
|
361
368
|
update(e) {
|
|
362
369
|
return this.isRunning ? (this.currentDelta += e, !1) : super.update(e);
|
|
363
370
|
}
|
|
@@ -367,12 +374,13 @@ var v = class extends g {
|
|
|
367
374
|
elapsedTime: e
|
|
368
375
|
};
|
|
369
376
|
this.addDataToWorld?.(t), this.isRunning = !0;
|
|
370
|
-
let n = this.buildQueryDelta(
|
|
377
|
+
let n = this.buildQueryDelta(T, this.options), r = {};
|
|
371
378
|
Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
|
|
372
379
|
r[e] = this.buildQueryDelta(e, t);
|
|
373
380
|
});
|
|
374
381
|
let i = {
|
|
375
382
|
type: "run",
|
|
383
|
+
generation: this.generation,
|
|
376
384
|
world: t,
|
|
377
385
|
entities: n,
|
|
378
386
|
queries: r
|
|
@@ -428,13 +436,13 @@ var v = class extends g {
|
|
|
428
436
|
}
|
|
429
437
|
checkAddEntity(e) {
|
|
430
438
|
let t = this.matchesQuery(e, this.options);
|
|
431
|
-
return this.updateEntityList(
|
|
439
|
+
return this.updateEntityList(T, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
|
|
432
440
|
let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
|
|
433
441
|
this.updateEntityList(t, r, e, this.matchesQuery(e, n));
|
|
434
442
|
}), t;
|
|
435
443
|
}
|
|
436
444
|
removeEntity(e) {
|
|
437
|
-
this.updateEntityList(
|
|
445
|
+
this.updateEntityList(T, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
|
|
438
446
|
this.updateEntityList(t, n, e, !1);
|
|
439
447
|
});
|
|
440
448
|
}
|
|
@@ -444,34 +452,7 @@ var v = class extends g {
|
|
|
444
452
|
destroy() {
|
|
445
453
|
super.destroy(), "terminate" in this.worker && this.worker.terminate();
|
|
446
454
|
}
|
|
447
|
-
},
|
|
448
|
-
type: Uint32Array,
|
|
449
|
-
size: 2,
|
|
450
|
-
loadProperties: ["type", "isStatic"],
|
|
451
|
-
load(e, t, n) {
|
|
452
|
-
let r = t.create([+!!n.dead, +!!n.isStatic]), i = t.getBlock(r);
|
|
453
|
-
return {
|
|
454
|
-
index: r,
|
|
455
|
-
type: n.type,
|
|
456
|
-
get dead() {
|
|
457
|
-
return i[0] === 1;
|
|
458
|
-
},
|
|
459
|
-
set dead(e) {
|
|
460
|
-
i[0] = +!!e;
|
|
461
|
-
},
|
|
462
|
-
get isStatic() {
|
|
463
|
-
return i[1] === 1;
|
|
464
|
-
},
|
|
465
|
-
set isStatic(e) {
|
|
466
|
-
i[1] = +!!e;
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
},
|
|
470
|
-
save(e) {
|
|
471
|
-
let t = {};
|
|
472
|
-
return e.type && (t.type = e.type), e.dead && (t.dead = !0), t;
|
|
473
|
-
}
|
|
474
|
-
}, w = class e extends d.default {
|
|
455
|
+
}, D = class e extends v.default {
|
|
475
456
|
static eidCounter = 1;
|
|
476
457
|
eid;
|
|
477
458
|
config;
|
|
@@ -534,7 +515,7 @@ var v = class extends g {
|
|
|
534
515
|
i.loadInFinishLoading && i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
|
|
535
516
|
}
|
|
536
517
|
}
|
|
537
|
-
},
|
|
518
|
+
}, O = class {
|
|
538
519
|
world;
|
|
539
520
|
configs;
|
|
540
521
|
constructor(e = {}) {
|
|
@@ -555,9 +536,9 @@ var v = class extends g {
|
|
|
555
536
|
return this.world.addEntity(n, t);
|
|
556
537
|
}
|
|
557
538
|
createEntity(e) {
|
|
558
|
-
return new
|
|
539
|
+
return new D(this.world, e);
|
|
559
540
|
}
|
|
560
|
-
},
|
|
541
|
+
}, k = c, A = class extends v.default {
|
|
561
542
|
heap;
|
|
562
543
|
registry;
|
|
563
544
|
factory;
|
|
@@ -569,23 +550,26 @@ var v = class extends g {
|
|
|
569
550
|
paused = !1;
|
|
570
551
|
destroyed = !1;
|
|
571
552
|
constructor(e, t = {}) {
|
|
572
|
-
super(), this.heap = new
|
|
573
|
-
let
|
|
553
|
+
super(), this.heap = new s({ bufferSize: t.heapSize ?? k });
|
|
554
|
+
let n = {
|
|
574
555
|
...e,
|
|
575
|
-
entity:
|
|
556
|
+
entity: r
|
|
576
557
|
}, i = {};
|
|
577
|
-
for (let e of Object.keys(
|
|
578
|
-
let t =
|
|
558
|
+
for (let e of Object.keys(n)) {
|
|
559
|
+
let t = n[e];
|
|
579
560
|
i[e] = {
|
|
580
561
|
...t,
|
|
581
|
-
memoryComponent: new
|
|
562
|
+
memoryComponent: new y(this.heap, t.type, t.size)
|
|
582
563
|
};
|
|
583
564
|
}
|
|
584
|
-
this.registry = i, this.factory = t.factory ?? new
|
|
565
|
+
this.registry = i, this.factory = t.factory ?? new O(), this.factory.world = this;
|
|
585
566
|
}
|
|
586
567
|
async init() {
|
|
587
568
|
await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
|
|
588
569
|
}
|
|
570
|
+
finishLoadingSystems() {
|
|
571
|
+
return Promise.all(this.systems.map((e) => e.finishLoading()).filter((e) => e instanceof Promise));
|
|
572
|
+
}
|
|
589
573
|
addEntity(e, t = !0) {
|
|
590
574
|
return this.entities.set(e.eid, e), e.world = this, e.on("component-added", (t) => {
|
|
591
575
|
this.addEntityToComponentSystem(e, t);
|
|
@@ -605,7 +589,7 @@ var v = class extends g {
|
|
|
605
589
|
for (let e of t) e.finishLoading(), this.emit("entity-added", e), e.on("death", () => {
|
|
606
590
|
this.onEntityDied(e);
|
|
607
591
|
});
|
|
608
|
-
this.gameTime = e.gameTime ?? 0, this.playerTime = e.playerTime ?? 0, this.timeScale = e.timeScale ?? 1;
|
|
592
|
+
this.gameTime = e.gameTime ?? 0, this.playerTime = e.playerTime ?? 0, this.timeScale = e.timeScale ?? 1, this.finishLoadingSystems();
|
|
609
593
|
}
|
|
610
594
|
removeEntity(e) {
|
|
611
595
|
this.entities.delete(e.eid) && this.emit("entity-removed", e), e.deleteAllComponentMemory();
|
|
@@ -662,12 +646,12 @@ var v = class extends g {
|
|
|
662
646
|
}
|
|
663
647
|
addEntityToComponentSystem(e, t) {
|
|
664
648
|
this.systems.forEach((n) => {
|
|
665
|
-
(n instanceof
|
|
649
|
+
(n instanceof S && n.options.components?.includes(t) || n instanceof E && this.componentAffectsComponentSystem(n, t)) && n.checkAddEntity(e);
|
|
666
650
|
});
|
|
667
651
|
}
|
|
668
652
|
removeEntityFromComponentSystem(e, t) {
|
|
669
653
|
this.systems.forEach((n) => {
|
|
670
|
-
n instanceof
|
|
654
|
+
n instanceof S && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof E && this.componentAffectsComponentSystem(n, t) && n.checkAddEntity(e);
|
|
671
655
|
});
|
|
672
656
|
}
|
|
673
657
|
componentAffectsComponentSystem(e, t) {
|
|
@@ -682,30 +666,19 @@ var v = class extends g {
|
|
|
682
666
|
};
|
|
683
667
|
//#endregion
|
|
684
668
|
//#region src/actions/kill-entity.ts
|
|
685
|
-
function
|
|
669
|
+
function j(e) {
|
|
686
670
|
e.components.entity.dead = !0, e.emit("death");
|
|
687
671
|
}
|
|
688
672
|
//#endregion
|
|
689
|
-
//#region src/actions/kill-entity-worker.ts
|
|
690
|
-
function k(e, t, n) {
|
|
691
|
-
let r = t.entity;
|
|
692
|
-
r && (r[0] = 1), n.entityDied(e);
|
|
693
|
-
}
|
|
694
|
-
//#endregion
|
|
695
|
-
//#region src/actions/create-entity-worker.ts
|
|
696
|
-
function A(e, t) {
|
|
697
|
-
t.createEntity(e);
|
|
698
|
-
}
|
|
699
|
-
//#endregion
|
|
700
673
|
//#region src/performance-timing.ts
|
|
701
|
-
var
|
|
674
|
+
var M = 1e3, N = {
|
|
702
675
|
avg: 0,
|
|
703
676
|
min: 0,
|
|
704
677
|
max: 0,
|
|
705
678
|
samples: 0
|
|
706
679
|
};
|
|
707
|
-
function
|
|
708
|
-
if (!e.length) return { ...
|
|
680
|
+
function P(e) {
|
|
681
|
+
if (!e.length) return { ...N };
|
|
709
682
|
let t = 0, n = Infinity, r = 0;
|
|
710
683
|
for (let i of e) t += i, i < n && (n = i), i > r && (r = i);
|
|
711
684
|
return {
|
|
@@ -715,13 +688,13 @@ function N(e) {
|
|
|
715
688
|
samples: e.length
|
|
716
689
|
};
|
|
717
690
|
}
|
|
718
|
-
var
|
|
691
|
+
var F = class extends v.default {
|
|
719
692
|
world;
|
|
720
693
|
ticksBetweenUpdates;
|
|
721
694
|
stats = {
|
|
722
|
-
update: { ...
|
|
695
|
+
update: { ...N },
|
|
723
696
|
systems: [],
|
|
724
|
-
events: { ...
|
|
697
|
+
events: { ...N }
|
|
725
698
|
};
|
|
726
699
|
ticks = 0;
|
|
727
700
|
updateStart = 0;
|
|
@@ -738,9 +711,9 @@ var P = class extends d.default {
|
|
|
738
711
|
this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
739
712
|
e.run = [], e.events = [], e.eventStart = -1;
|
|
740
713
|
}), this.stats = {
|
|
741
|
-
update: { ...
|
|
714
|
+
update: { ...N },
|
|
742
715
|
systems: [],
|
|
743
|
-
events: { ...
|
|
716
|
+
events: { ...N }
|
|
744
717
|
};
|
|
745
718
|
}
|
|
746
719
|
destroy() {
|
|
@@ -782,14 +755,14 @@ var P = class extends d.default {
|
|
|
782
755
|
let t = this.systemTimings.get(e.name);
|
|
783
756
|
return {
|
|
784
757
|
name: e.name,
|
|
785
|
-
run:
|
|
786
|
-
events:
|
|
758
|
+
run: P(t?.run ?? []),
|
|
759
|
+
events: P(t?.events ?? [])
|
|
787
760
|
};
|
|
788
|
-
}), t = { ...
|
|
761
|
+
}), t = { ...N };
|
|
789
762
|
e.forEach((e) => {
|
|
790
763
|
t.avg += e.events.avg, t.min += e.events.min, t.max += e.events.max, t.samples += e.events.samples;
|
|
791
764
|
}), this.stats = {
|
|
792
|
-
update:
|
|
765
|
+
update: P(this.updateTimes),
|
|
793
766
|
systems: e,
|
|
794
767
|
events: t
|
|
795
768
|
}, this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
|
|
@@ -798,71 +771,6 @@ var P = class extends d.default {
|
|
|
798
771
|
}
|
|
799
772
|
};
|
|
800
773
|
//#endregion
|
|
801
|
-
|
|
802
|
-
function F(e, t) {
|
|
803
|
-
let n = [], r = {};
|
|
804
|
-
e.onmessage = function(i) {
|
|
805
|
-
let a = i.data;
|
|
806
|
-
if (a.type === "init") I(e, { type: "loaded" });
|
|
807
|
-
else if (a.type === "run") {
|
|
808
|
-
let i = performance.now(), o = [], s = {}, c = [];
|
|
809
|
-
n = _(n, a.entities);
|
|
810
|
-
let l = {};
|
|
811
|
-
Object.entries(a.queries).forEach(([e, t]) => {
|
|
812
|
-
let n = _(r[e] ?? [], t);
|
|
813
|
-
r[e] = n, l[e] = n;
|
|
814
|
-
});
|
|
815
|
-
let u = {
|
|
816
|
-
entityComponentChanged(e, t, n, r) {
|
|
817
|
-
o.push({
|
|
818
|
-
entityId: e,
|
|
819
|
-
event: "component-property-updated",
|
|
820
|
-
args: [
|
|
821
|
-
t,
|
|
822
|
-
n,
|
|
823
|
-
r
|
|
824
|
-
]
|
|
825
|
-
});
|
|
826
|
-
},
|
|
827
|
-
emitEntityEvent(e, t, ...n) {
|
|
828
|
-
o.push({
|
|
829
|
-
entityId: e,
|
|
830
|
-
event: t,
|
|
831
|
-
args: n
|
|
832
|
-
});
|
|
833
|
-
},
|
|
834
|
-
emitSystemEvent(e, t) {
|
|
835
|
-
(s[e] ?? (s[e] = [])).push(t);
|
|
836
|
-
},
|
|
837
|
-
entityDied(e) {
|
|
838
|
-
o.push({
|
|
839
|
-
entityId: e,
|
|
840
|
-
event: "death",
|
|
841
|
-
args: []
|
|
842
|
-
});
|
|
843
|
-
},
|
|
844
|
-
createEntity(e) {
|
|
845
|
-
c.push(e);
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
t.preRun && t.preRun(a.world, n, l, u), n.forEach((e) => {
|
|
849
|
-
t(a.world, e.entityId, e.components, l, u);
|
|
850
|
-
}), t.entityRemoved && a.entities.removed.forEach((e) => {
|
|
851
|
-
t.entityRemoved(a.world, e, u);
|
|
852
|
-
}), I(e, {
|
|
853
|
-
type: "run-complete",
|
|
854
|
-
runTime: performance.now() - i,
|
|
855
|
-
events: o,
|
|
856
|
-
systemEvents: s,
|
|
857
|
-
created: c
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
function I(e, t) {
|
|
863
|
-
e.postMessage(t);
|
|
864
|
-
}
|
|
865
|
-
//#endregion
|
|
866
|
-
export { w as BaseEntity, D as BaseWorld, b as ComponentSystem, v as ComponentWebWorker, x as DEAD_INDEX, j as DEFAULT_TICKS_BETWEEN_UPDATES, T as EntityFactory, h as EntitySystem, m as IterableSystem, f as MemoryComponent, P as PerformanceTiming, S as STATIC_INDEX, p as System, g as WebWorker, F as createComponentWorker, A as createEntityWorker, C as entityDefinition, O as killEntity, k as killEntityWorker };
|
|
774
|
+
export { D as BaseEntity, A as BaseWorld, E as ComponentSystem, w as ComponentWebWorker, t as DEAD_INDEX, M as DEFAULT_TICKS_BETWEEN_UPDATES, O as EntityFactory, S as EntitySystem, x as IterableSystem, y as MemoryComponent, F as PerformanceTiming, e as STATIC_INDEX, b as System, C as WebWorker, o as createComponentWorker, n as createEntityWorker, r as entityDefinition, j as killEntity, i as killEntityWorker };
|
|
867
775
|
|
|
868
776
|
//# sourceMappingURL=index.js.map
|