@daneren2005/shared-memory-ecs 1.4.0 → 1.5.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/dist/index.js CHANGED
@@ -1,18 +1,17 @@
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";
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./create-component-worker-CaB32Dgn.js";
2
+ import f from "@daneren2005/shared-memory-objects/memory-heap";
3
+ import { MAX_BYTE_OFFSET_LENGTH as p } from "@daneren2005/shared-memory-objects/utils/pointer";
5
4
  //#region \0rolldown/runtime.js
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, {
5
+ var m = Object.create, h = Object.defineProperty, g = Object.getOwnPropertyDescriptor, _ = Object.getOwnPropertyNames, v = Object.getPrototypeOf, y = Object.prototype.hasOwnProperty, b = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), x = (e, t, n, r) => {
6
+ if (t && typeof t == "object" || typeof t == "function") for (var i = _(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !y.call(e, s) && s !== n && h(e, s, {
8
7
  get: ((e) => t[e]).bind(null, s),
9
- enumerable: !(r = f(t, s)) || r.enumerable
8
+ enumerable: !(r = g(t, s)) || r.enumerable
10
9
  });
11
10
  return e;
12
- }, v = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : u(m(e)), _(t || !e || !e.__esModule ? d(n, "default", {
11
+ }, S = /* @__PURE__ */ ((e, t, n) => (n = e == null ? {} : m(v(e)), x(t || !e || !e.__esModule ? h(n, "default", {
13
12
  value: e,
14
13
  enumerable: !0
15
- }) : n, e)))((/* @__PURE__ */ g(((e, t) => {
14
+ }) : n, e)))((/* @__PURE__ */ b(((e, t) => {
16
15
  var n = Object.prototype.hasOwnProperty, r = "~";
17
16
  function i() {}
18
17
  Object.create && (i.prototype = Object.create(null), new i().__proto__ || (r = !1));
@@ -99,41 +98,76 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
99
98
  var t;
100
99
  return e ? (t = r ? r + e : e, this._events[t] && s(this, t)) : (this._events = new i(), this._eventsCount = 0), this;
101
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);
102
- })))(), 1), y = class {
103
- heap;
104
- pool;
101
+ })))(), 1), C = class extends S.default {
102
+ eid;
103
+ config;
104
+ world;
105
+ components = {};
105
106
  constructor(e, t, n) {
106
- this.heap = e, this.pool = new l(e, {
107
- type: t,
108
- dataLength: n
109
- });
107
+ super(), this.world = e, this.eid = n ?? e.allocateEid(), n === void 0 && (this.loadComponent("entity", t ?? {}, !1), t && this.load(t));
110
108
  }
111
- get length() {
112
- return this.pool.length;
109
+ loadComponent(e, t, n = !0) {
110
+ let r = this.world.registry[e], i = r.memoryComponent, a = i.create(r.toBlock(t, this)), o = r.attach(this, i, a);
111
+ return o.block ??= i.getBlock(a), this.components[e] = o, n && this.emit("component-added", e, o), o;
113
112
  }
114
- get rawLength() {
115
- return this.pool.bufferLength;
113
+ attachComponent(e, t) {
114
+ let n = this.world.registry[e], r = n.attach(this, n.memoryComponent, t);
115
+ return r.block ??= n.memoryComponent.getBlock(t), this.components[e] = r, r;
116
116
  }
117
- create(e) {
118
- return this.pool.push(e);
117
+ removeComponent(e) {
118
+ let t = this.components[e];
119
+ if (t) {
120
+ let n = this.world.registry[e];
121
+ this.world.deferComponentMemoryFree(n.memoryComponent, t.index, n.free ? () => n.free(t) : void 0), delete this.components[e], this.emit("component-removed", e);
122
+ }
119
123
  }
120
- getBlock(e) {
121
- return this.pool.at(e);
124
+ setComponent(e, t, n) {
125
+ let r = this.components[e];
126
+ r && (r[t] = n, this.emit("component-property-updated", e, t, n));
122
127
  }
123
- get(e, t) {
124
- return this.pool.get(e, t);
128
+ setComponentBulk(e, t) {
129
+ let n = this.components[e];
130
+ n && Object.assign(n, t);
125
131
  }
126
- set(e, t, n) {
127
- let r = this.pool.at(e);
128
- r[t] = n;
132
+ deleteComponent(e, t) {
133
+ let n = this.components[e];
134
+ n && (delete n[t], this.emit("component-property-deleted", e, t));
129
135
  }
130
- delete(e) {
131
- this.pool.deleteIndex(e);
136
+ deleteAllComponentMemory() {
137
+ let e = this.world.registry, t = this.components;
138
+ for (let n of Object.keys(t)) {
139
+ let r = e[n], i = t[n];
140
+ i && this.world.deferComponentMemoryFree(r.memoryComponent, i.index, r.free ? () => r.free(i) : void 0);
141
+ }
132
142
  }
133
- clear() {
134
- this.pool.clear();
143
+ load(e) {
144
+ let t = e, n = this.world.registry;
145
+ for (let r of Object.keys(n)) {
146
+ if (r === "entity") continue;
147
+ let i = n[r];
148
+ i.loadInFinishLoading || i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
149
+ }
150
+ this.config = e;
135
151
  }
136
- }, b = class extends v.default {
152
+ save() {
153
+ let e = {}, t = this.world.registry, n = this.components;
154
+ for (let r of Object.keys(n)) {
155
+ let i = t[r], a = n[r];
156
+ i.save && a && Object.assign(e, i.save(a));
157
+ }
158
+ return e;
159
+ }
160
+ finishLoading() {
161
+ let e = this.config;
162
+ if (!e) return;
163
+ let t = e, n = this.world.registry;
164
+ for (let r of Object.keys(n)) {
165
+ if (r === "entity") continue;
166
+ let i = n[r];
167
+ i.loadInFinishLoading && i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
168
+ }
169
+ }
170
+ }, w = class extends S.default {
137
171
  world;
138
172
  name;
139
173
  currentDelta = 0;
@@ -166,7 +200,7 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
166
200
  destroy() {
167
201
  this.removeAllListeners();
168
202
  }
169
- }, x = class extends b {
203
+ }, T = class extends w {
170
204
  remainingInstancesToRun = [];
171
205
  remainingInstancesStartTime = null;
172
206
  iterationsPerCheck;
@@ -200,7 +234,7 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
200
234
  this.remainingInstancesToRun = [], this.remainingInstancesStartTime = null;
201
235
  }
202
236
  beforeRunIterables() {}
203
- }, S = class extends x {
237
+ }, E = class extends T {
204
238
  entities = /* @__PURE__ */ new Map();
205
239
  options;
206
240
  constructor(e, t = { name: "EntitySystem" }) {
@@ -236,27 +270,38 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
236
270
  shouldRun() {
237
271
  return this.entities.size > 0;
238
272
  }
239
- }, C = class {
273
+ }, D = class {
240
274
  onmessage(e, t = []) {}
241
- }, w = class extends C {
275
+ }, O = class extends D {
242
276
  updateFunction;
243
277
  entities = [];
244
278
  queryEntities = {};
245
279
  worldExtension;
246
- constructor(e) {
247
- super(), this.updateFunction = e;
280
+ world;
281
+ allocator;
282
+ createsEntities;
283
+ constructor(e, t, n = !1) {
284
+ super(), this.updateFunction = e, this.world = t, this.createsEntities = n;
285
+ let r = t.registry;
286
+ this.allocator = {
287
+ allocateEid: () => t.allocateEid(),
288
+ allocateComponentBlock: (e, t) => r[e].memoryComponent.create(t)
289
+ };
248
290
  }
249
291
  postMessage(e) {
250
292
  if (e.type === "init") this.onMessageTyped({ type: "init-complete" });
251
293
  else if (e.type === "load") this.worldExtension = this.updateFunction.init?.(e.data) ?? void 0, this.onMessageTyped({ type: "loaded" });
252
294
  else if (e.type === "reset") this.entities = [], this.queryEntities = {};
253
295
  else if (e.type === "run") {
254
- this.worldExtension && Object.assign(e.world, this.worldExtension);
296
+ if (this.worldExtension && Object.assign(e.world, this.worldExtension), e.world.getString = (e) => this.world.constantStrings.getString(e) ?? "", e.world.allocate = this.allocator, this.createsEntities) {
297
+ let t = this.world.registry;
298
+ e.world.buildEntityDescriptor = (e) => a(e, this.world.factory.configs, t, this.allocator);
299
+ }
255
300
  let t = performance.now(), n = [], r = {}, i = [];
256
- this.entities = a(this.entities, e.entities);
301
+ this.entities = d(this.entities, e.entities);
257
302
  let o = {};
258
303
  Object.entries(e.queries).forEach(([e, t]) => {
259
- let n = a(this.queryEntities[e] ?? [], t);
304
+ let n = d(this.queryEntities[e] ?? [], t);
260
305
  this.queryEntities[e] = n, o[e] = n;
261
306
  });
262
307
  let s = {
@@ -309,7 +354,7 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
309
354
  onMessageTyped(e) {
310
355
  this.onmessage({ data: e });
311
356
  }
312
- }, T = "___main", E = class extends b {
357
+ }, k = "___main", A = class extends w {
313
358
  entities = /* @__PURE__ */ new Map();
314
359
  options;
315
360
  worker;
@@ -331,13 +376,19 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
331
376
  this.removeEntity(e);
332
377
  }), e.entities.forEach((e) => {
333
378
  this.checkAddEntity(e);
334
- }), !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();
379
+ }), !t.forceMainThread && globalThis.Worker !== void 0 && globalThis.SharedArrayBuffer !== void 0 ? (this.worker = t.getWorker(), this.isWorkerThread = !0, e.on("grow-buffer", (e) => {
380
+ this.worker.postMessage({
381
+ type: "grow-buffer",
382
+ buffer: e
383
+ });
384
+ })) : (this.worker = new O(t.updateFunction, e, !!t.createsEntities), this.isWorkerThread = !1), this.initWorker();
335
385
  }
336
386
  initWorker() {
337
387
  this.worker.onmessage = (e) => {
338
388
  let t = e.data;
339
389
  if (t.type === "init-complete") this.initialized = !0, this.initPromise &&= (this.initPromise.resolve(), null);
340
390
  else if (t.type === "loaded") this.loadingPromise &&= (this.loadingPromise.resolve(), null);
391
+ else if (t.type === "grow-buffer-from-worker") this.world.addGrownBuffer(t.buffer);
341
392
  else if (t.type === "run-complete") {
342
393
  if (t.generation !== this.generation) return;
343
394
  this.isRunning = !1, this.world.emit(`system-${this.name}-worker-finished`, t.runTime);
@@ -350,7 +401,7 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
350
401
  }
351
402
  t.emit(e.event, ...e.args);
352
403
  }), t.created.forEach((e) => {
353
- this.world.loadEntity(e);
404
+ this.world.adoptEntity(e);
354
405
  }), this.world.emit(`system-${this.name}-worker-events-finished`, t.runTime), this.world.notifySystemRunCompleted(this), this.runCompletePromise &&= (this.runCompletePromise.resolve(), null);
355
406
  }
356
407
  }, this.worker.postMessage({ type: "init" });
@@ -372,7 +423,10 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
372
423
  };
373
424
  let n = {
374
425
  type: "load",
375
- data: this.options.getInitData?.()
426
+ data: this.options.getInitData?.(),
427
+ heap: this.isWorkerThread ? this.world.heap.getSharedMemory() : void 0,
428
+ sharedMemory: this.isWorkerThread ? this.world.getSharedComponentMemory() : void 0,
429
+ factoryConfigs: this.isWorkerThread && this.options.createsEntities ? this.world.factory.configs : void 0
376
430
  };
377
431
  return this.worker.postMessage(n), e;
378
432
  }
@@ -411,7 +465,7 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
411
465
  elapsedTime: e
412
466
  };
413
467
  this.addDataToWorld?.(t), this.isRunning = !0;
414
- let n = this.buildQueryDelta(T, this.options), r = {};
468
+ let n = this.buildQueryDelta(k, this.options), r = {};
415
469
  Object.entries(this.options.queries ?? {}).forEach(([e, t]) => {
416
470
  r[e] = this.buildQueryDelta(e, t);
417
471
  });
@@ -442,10 +496,10 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
442
496
  };
443
497
  }
444
498
  buildComponents(e, t) {
445
- let n = {}, r = this.world.registry;
499
+ let n = {};
446
500
  return [...t.required, ...t.optional ?? []].forEach((t) => {
447
- let i = e.components[t], a = r[t].memoryComponent;
448
- i && a && (n[t] = a.getBlock(i.index));
501
+ let r = e.components[t]?.block;
502
+ r && (n[t] = r);
449
503
  }), n;
450
504
  }
451
505
  isEntityInSystem(e) {
@@ -473,89 +527,28 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
473
527
  }
474
528
  checkAddEntity(e) {
475
529
  let t = this.matchesQuery(e, this.options);
476
- return this.updateEntityList(T, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
530
+ return this.updateEntityList(k, this.entities, e, t), Object.entries(this.options.queries ?? {}).forEach(([t, n]) => {
477
531
  let r = this.queryEntities[t] ?? (this.queryEntities[t] = /* @__PURE__ */ new Map());
478
532
  this.updateEntityList(t, r, e, this.matchesQuery(e, n));
479
533
  }), t;
480
534
  }
481
535
  removeEntity(e) {
482
- this.updateEntityList(T, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
536
+ this.updateEntityList(k, this.entities, e, !1), Object.entries(this.queryEntities).forEach(([t, n]) => {
483
537
  this.updateEntityList(t, n, e, !1);
484
538
  });
485
539
  }
540
+ recheckMembership() {
541
+ this.world.entities.forEach((e) => {
542
+ this.checkAddEntity(e);
543
+ });
544
+ }
486
545
  shouldRun() {
487
546
  return this.entities.size > 0;
488
547
  }
489
548
  destroy() {
490
549
  super.destroy(), "terminate" in this.worker && this.worker.terminate();
491
550
  }
492
- }, D = class e extends v.default {
493
- static eidCounter = 1;
494
- eid;
495
- config;
496
- world;
497
- components = {};
498
- constructor(t, n) {
499
- super(), this.world = t, this.eid = e.eidCounter++, this.loadComponent("entity", n ?? {}, !1), n && this.load(n);
500
- }
501
- loadComponent(e, t, n = !0) {
502
- let r = this.world.registry[e], i = r.memoryComponent, a = r.load(this, i, t);
503
- return this.components[e] = a, n && this.emit("component-added", e, a), a;
504
- }
505
- removeComponent(e) {
506
- let t = this.components[e];
507
- if (t) {
508
- let n = this.world.registry[e];
509
- this.world.deferComponentMemoryFree(n.memoryComponent, t.index, n.free ? () => n.free(t) : void 0), delete this.components[e], this.emit("component-removed", e);
510
- }
511
- }
512
- setComponent(e, t, n) {
513
- let r = this.components[e];
514
- r && (r[t] = n, this.emit("component-property-updated", e, t, n));
515
- }
516
- setComponentBulk(e, t) {
517
- let n = this.components[e];
518
- n && Object.assign(n, t);
519
- }
520
- deleteComponent(e, t) {
521
- let n = this.components[e];
522
- n && (delete n[t], this.emit("component-property-deleted", e, t));
523
- }
524
- deleteAllComponentMemory() {
525
- let e = this.world.registry, t = this.components;
526
- for (let n of Object.keys(t)) {
527
- let r = e[n], i = t[n];
528
- i && this.world.deferComponentMemoryFree(r.memoryComponent, i.index, r.free ? () => r.free(i) : void 0);
529
- }
530
- }
531
- load(e) {
532
- let t = e, n = this.world.registry;
533
- for (let r of Object.keys(n)) {
534
- if (r === "entity") continue;
535
- let i = n[r];
536
- i.loadInFinishLoading || i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
537
- }
538
- this.config = e;
539
- }
540
- save() {
541
- let e = {}, t = this.world.registry, n = this.components;
542
- for (let r of Object.keys(n)) {
543
- let i = t[r], a = n[r];
544
- i.save && a && Object.assign(e, i.save(a));
545
- }
546
- return e;
547
- }
548
- finishLoading() {
549
- let e = this.config;
550
- if (!e) return;
551
- let t = e, n = this.world.registry;
552
- for (let r of Object.keys(n)) {
553
- if (r === "entity") continue;
554
- let i = n[r];
555
- i.loadInFinishLoading && i.loadProperties.some((e) => e in t) && this.loadComponent(r, e, !1);
556
- }
557
- }
558
- }, O = class {
551
+ }, j = class {
559
552
  world;
560
553
  configs;
561
554
  constructor(e = {}) {
@@ -576,10 +569,12 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
576
569
  return this.world.addEntity(n, t);
577
570
  }
578
571
  createEntity(e) {
579
- return new D(this.world, e);
572
+ return new C(this.world, e);
580
573
  }
581
- }, k = c, A = 1e4, j = class extends v.default {
574
+ }, M = p, N = 1e4, P = class extends S.default {
582
575
  heap;
576
+ constantStrings;
577
+ eidCounter;
583
578
  registry;
584
579
  factory;
585
580
  entities = /* @__PURE__ */ new Map();
@@ -601,19 +596,33 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
601
596
  waitElapsed: 0
602
597
  };
603
598
  constructor(e, t = {}) {
604
- super(), this.heap = new s({ bufferSize: t.heapSize ?? k });
605
- let n = {
599
+ super(), this.heap = new f({ bufferSize: t.heapSize ?? M }), this.constantStrings = new n(this.heap), this.eidCounter = this.heap.allocUI32(1), this.heap.addOnGrowBufferHandlers((e) => this.emit("grow-buffer", e));
600
+ let i = {
606
601
  ...e,
607
- entity: r
608
- }, i = {};
609
- for (let e of Object.keys(n)) {
610
- let t = n[e];
611
- i[e] = {
602
+ entity: l
603
+ }, a = {};
604
+ for (let e of Object.keys(i)) {
605
+ let t = i[e];
606
+ a[e] = {
612
607
  ...t,
613
- memoryComponent: new y(this.heap, t.type, t.size)
608
+ memoryComponent: new r(this.heap, t.type, t.size)
614
609
  };
615
610
  }
616
- this.registry = i, this.factory = t.factory ?? new O(), this.factory.world = this;
611
+ this.registry = a, this.factory = t.factory ?? new j(), this.factory.world = this;
612
+ }
613
+ allocateEid() {
614
+ return Atomics.add(this.eidCounter.data, 0, 1) + 1;
615
+ }
616
+ getSharedComponentMemory() {
617
+ let e = {};
618
+ for (let t of Object.keys(this.registry)) e[t] = this.registry[t].memoryComponent.getSharedMemory();
619
+ return {
620
+ components: e,
621
+ eidCounter: this.eidCounter.getSharedMemory()
622
+ };
623
+ }
624
+ addGrownBuffer(e) {
625
+ this.heap.buffers[e.bufferPosition] === void 0 && this.heap.addSharedBuffer(e), this.emit("grow-buffer", e);
617
626
  }
618
627
  async init() {
619
628
  await Promise.all(this.systems.map((e) => e.init()).filter((e) => e instanceof Promise));
@@ -633,11 +642,21 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
633
642
  loadEntity(e, t = !0) {
634
643
  return this.factory.loadEntity(e, t);
635
644
  }
645
+ adoptEntity(e) {
646
+ let t = new C(this, void 0, e.eid);
647
+ t.loadComponent("entity", {
648
+ type: e.type,
649
+ isStatic: e.isStatic
650
+ }, !1);
651
+ for (let n of Object.keys(e.components)) t.attachComponent(n, e.components[n]);
652
+ return this.addEntity(t, !0);
653
+ }
636
654
  load(e) {
637
655
  if (!this.pristine) {
638
656
  for (let e of Array.from(this.entities.values())) this.removeEntity(e);
639
657
  this.systems.forEach((e) => e.clear()), this.consolidateFreeBuffersForReload();
640
658
  }
659
+ for (let e of Object.keys(this.factory.configs)) this.constantStrings.getOrCreate(e);
641
660
  let t = e.entities.map((e) => this.loadEntity(e, !1));
642
661
  for (let e of t) e.finishLoading(), this.emit("entity-added", e), e.on("death", () => {
643
662
  this.onEntityDied(e);
@@ -691,9 +710,9 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
691
710
  }
692
711
  checkFreeBufferTimeout(e) {
693
712
  let t = this.activeFreeBuffer;
694
- if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >= A)) {
713
+ if (t.waitingSystems.size !== 0 && (t.waitElapsed += e, t.waitElapsed >= N)) {
695
714
  let e = Array.from(t.waitingSystems).map((e) => e.name).join(", ");
696
- console.warn(`shared-memory-ecs: deferred component free waited over ${A}ms on system(s): ${e}; freeing anyway`), t.waitingSystems.clear(), this.processFreeBuffers();
715
+ console.warn(`shared-memory-ecs: deferred component free waited over ${N}ms on system(s): ${e}; freeing anyway`), t.waitingSystems.clear(), this.processFreeBuffers();
697
716
  }
698
717
  }
699
718
  addSystem(e) {
@@ -743,12 +762,12 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
743
762
  }
744
763
  addEntityToComponentSystem(e, t) {
745
764
  this.systems.forEach((n) => {
746
- (n instanceof S && n.options.components?.includes(t) || n instanceof E && this.componentAffectsComponentSystem(n, t)) && n.checkAddEntity(e);
765
+ (n instanceof E && n.options.components?.includes(t) || n instanceof A && this.componentAffectsComponentSystem(n, t)) && n.checkAddEntity(e);
747
766
  });
748
767
  }
749
768
  removeEntityFromComponentSystem(e, t) {
750
769
  this.systems.forEach((n) => {
751
- n instanceof S && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof E && this.componentAffectsComponentSystem(n, t) && n.checkAddEntity(e);
770
+ n instanceof E && n.options.components?.includes(t) ? n.removeEntity(e) : n instanceof A && this.componentAffectsComponentSystem(n, t) && n.checkAddEntity(e);
752
771
  });
753
772
  }
754
773
  componentAffectsComponentSystem(e, t) {
@@ -763,19 +782,19 @@ var u = Object.create, d = Object.defineProperty, f = Object.getOwnPropertyDescr
763
782
  };
764
783
  //#endregion
765
784
  //#region src/actions/kill-entity.ts
766
- function M(e) {
785
+ function F(e) {
767
786
  e.components.entity.dead = !0, e.emit("death");
768
787
  }
769
788
  //#endregion
770
789
  //#region src/performance-timing.ts
771
- var N = 1e3, P = {
790
+ var I = 1e3, L = {
772
791
  avg: 0,
773
792
  min: 0,
774
793
  max: 0,
775
794
  samples: 0
776
795
  };
777
- function F(e) {
778
- if (!e.length) return { ...P };
796
+ function R(e) {
797
+ if (!e.length) return { ...L };
779
798
  let t = 0, n = Infinity, r = 0;
780
799
  for (let i of e) t += i, i < n && (n = i), i > r && (r = i);
781
800
  return {
@@ -785,13 +804,13 @@ function F(e) {
785
804
  samples: e.length
786
805
  };
787
806
  }
788
- var I = class extends v.default {
807
+ var z = class extends S.default {
789
808
  world;
790
809
  ticksBetweenUpdates;
791
810
  stats = {
792
- update: { ...P },
811
+ update: { ...L },
793
812
  systems: [],
794
- events: { ...P }
813
+ events: { ...L }
795
814
  };
796
815
  ticks = 0;
797
816
  updateStart = 0;
@@ -808,9 +827,9 @@ var I = class extends v.default {
808
827
  this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
809
828
  e.run = [], e.events = [], e.eventStart = -1;
810
829
  }), this.stats = {
811
- update: { ...P },
830
+ update: { ...L },
812
831
  systems: [],
813
- events: { ...P }
832
+ events: { ...L }
814
833
  };
815
834
  }
816
835
  destroy() {
@@ -852,14 +871,14 @@ var I = class extends v.default {
852
871
  let t = this.systemTimings.get(e.name);
853
872
  return {
854
873
  name: e.name,
855
- run: F(t?.run ?? []),
856
- events: F(t?.events ?? [])
874
+ run: R(t?.run ?? []),
875
+ events: R(t?.events ?? [])
857
876
  };
858
- }), t = { ...P };
877
+ }), t = { ...L };
859
878
  e.forEach((e) => {
860
879
  t.avg += e.events.avg, t.min += e.events.min, t.max += e.events.max, t.samples += e.events.samples;
861
880
  }), this.stats = {
862
- update: F(this.updateTimes),
881
+ update: R(this.updateTimes),
863
882
  systems: e,
864
883
  events: t
865
884
  }, this.ticks = 0, this.updateTimes = [], this.systemTimings.forEach((e) => {
@@ -868,6 +887,6 @@ var I = class extends v.default {
868
887
  }
869
888
  };
870
889
  //#endregion
871
- export { D as BaseEntity, j as BaseWorld, E as ComponentSystem, w as ComponentWebWorker, t as DEAD_INDEX, N as DEFAULT_TICKS_BETWEEN_UPDATES, O as EntityFactory, S as EntitySystem, x as IterableSystem, y as MemoryComponent, I as PerformanceTiming, e as STATIC_INDEX, b as System, C as WebWorker, o as createComponentWorker, n as createEntityWorker, r as entityDefinition, M as killEntity, i as killEntityWorker };
890
+ export { C as BaseEntity, P as BaseWorld, t as Component, A as ComponentSystem, O as ComponentWebWorker, n as ConstantStringCache, i as DEAD_INDEX, I as DEFAULT_TICKS_BETWEEN_UPDATES, j as EntityFactory, E as EntitySystem, T as IterableSystem, r as MemoryComponent, z as PerformanceTiming, e as STATIC_INDEX, w as System, s as TYPE_INDEX, D as WebWorker, u as createComponentWorker, o as createEntityWorker, l as entityDefinition, F as killEntity, c as killEntityWorker };
872
891
 
873
892
  //# sourceMappingURL=index.js.map