@daneren2005/shared-memory-ecs 1.10.0 → 1.10.1

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