@oasys/oecs 0.3.0 → 0.3.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,10 +1,10 @@
1
- class J extends Error {
1
+ class Z extends Error {
2
2
  constructor(t, e, s) {
3
3
  super(t), this.is_operational = e, this.context = s, this.name = this.constructor.name, Error.captureStackTrace(this, this.constructor);
4
4
  }
5
5
  }
6
6
  var D = /* @__PURE__ */ ((a) => (a.EID_MAX_INDEX_OVERFLOW = "EID_MAX_INDEX_OVERFLOW", a.EID_MAX_GEN_OVERFLOW = "EID_MAX_GEN_OVERFLOW", a.COMPONENT_NOT_REGISTERED = "COMPONENT_NOT_REGISTERED", a.ENTITY_NOT_ALIVE = "ENTITY_NOT_ALIVE", a.CIRCULAR_SYSTEM_DEPENDENCY = "CIRCULAR_SYSTEM_DEPENDENCY", a.DUPLICATE_SYSTEM = "DUPLICATE_SYSTEM", a.ARCHETYPE_NOT_FOUND = "ARCHETYPE_NOT_FOUND", a.RESOURCE_NOT_REGISTERED = "RESOURCE_NOT_REGISTERED", a.RESOURCE_ALREADY_REGISTERED = "RESOURCE_ALREADY_REGISTERED", a.EVENT_ALREADY_REGISTERED = "EVENT_ALREADY_REGISTERED", a.EVENT_NOT_REGISTERED = "EVENT_NOT_REGISTERED", a))(D || {});
7
- class O extends J {
7
+ class O extends Z {
8
8
  constructor(t, e, s) {
9
9
  super(e ?? t, !0, s), this.category = t;
10
10
  }
@@ -12,11 +12,11 @@ class O extends J {
12
12
  function F(a, t, e) {
13
13
  return a;
14
14
  }
15
- const I = 5, S = 31, Z = 2166136261, tt = 16777619, et = 4;
16
- class k {
15
+ const I = 5, S = 31, tt = 2166136261, et = 16777619, st = 4;
16
+ class p {
17
17
  _words;
18
18
  constructor(t) {
19
- this._words = t ?? new Array(et).fill(0);
19
+ this._words = t ?? new Array(st).fill(0);
20
20
  }
21
21
  has(t) {
22
22
  const e = t >>> I;
@@ -33,48 +33,48 @@ class k {
33
33
  /** True if any bit is set in both this and other (non-empty intersection). */
34
34
  overlaps(t) {
35
35
  const e = this._words, s = t._words, n = e.length < s.length ? e.length : s.length;
36
- for (let r = 0; r < n; r++)
37
- if ((e[r] & s[r]) !== 0) return !0;
36
+ for (let i = 0; i < n; i++)
37
+ if ((e[i] & s[i]) !== 0) return !0;
38
38
  return !1;
39
39
  }
40
40
  /** True if this is a superset of other (all bits in other are set in this). */
41
41
  contains(t) {
42
42
  const e = t._words, s = this._words, n = s.length;
43
- for (let r = 0; r < e.length; r++) {
44
- const i = e[r];
45
- if (i !== 0 && (r >= n || (s[r] & i) !== i))
43
+ for (let i = 0; i < e.length; i++) {
44
+ const r = e[i];
45
+ if (r !== 0 && (i >= n || (s[i] & r) !== r))
46
46
  return !1;
47
47
  }
48
48
  return !0;
49
49
  }
50
50
  equals(t) {
51
51
  const e = this._words, s = t._words, n = e.length > s.length ? e.length : s.length;
52
- for (let r = 0; r < n; r++) {
53
- const i = r < e.length ? e[r] : 0, c = r < s.length ? s[r] : 0;
54
- if (i !== c) return !1;
52
+ for (let i = 0; i < n; i++) {
53
+ const r = i < e.length ? e[i] : 0, c = i < s.length ? s[i] : 0;
54
+ if (r !== c) return !1;
55
55
  }
56
56
  return !0;
57
57
  }
58
58
  copy() {
59
- return new k(this._words.slice());
59
+ return new p(this._words.slice());
60
60
  }
61
61
  copy_with_set(t) {
62
- const e = t >>> I, s = e + 1, n = this._words.length > s ? this._words.length : s, r = new Array(n).fill(0);
63
- for (let i = 0; i < this._words.length; i++) r[i] = this._words[i];
64
- return r[e] |= 1 << (t & S), new k(r);
62
+ const e = t >>> I, s = e + 1, n = this._words.length > s ? this._words.length : s, i = new Array(n).fill(0);
63
+ for (let r = 0; r < this._words.length; r++) i[r] = this._words[r];
64
+ return i[e] |= 1 << (t & S), new p(i);
65
65
  }
66
66
  copy_with_clear(t) {
67
67
  const e = this._words.slice(), s = t >>> I;
68
- return s < e.length && (e[s] &= ~(1 << (t & S))), new k(e);
68
+ return s < e.length && (e[s] &= ~(1 << (t & S))), new p(e);
69
69
  }
70
70
  /** FNV-1a hash. Skips trailing zero words so differently-sized arrays with the same bits hash equally. */
71
71
  hash() {
72
- let t = Z;
72
+ let t = tt;
73
73
  const e = this._words;
74
74
  let s = e.length - 1;
75
75
  for (; s >= 0 && e[s] === 0; ) s--;
76
76
  for (let n = 0; n <= s; n++)
77
- t ^= e[n], t = Math.imul(t, tt);
77
+ t ^= e[n], t = Math.imul(t, et);
78
78
  return t;
79
79
  }
80
80
  /** Iterate all set bits via lowest-set-bit extraction. */
@@ -83,10 +83,10 @@ class k {
83
83
  for (let s = 0; s < e.length; s++) {
84
84
  let n = e[s];
85
85
  if (n === 0) continue;
86
- const r = s << I;
86
+ const i = s << I;
87
87
  for (; n !== 0; ) {
88
- const i = n & -n >>> 0, c = S - Math.clz32(i);
89
- t(r + c), n ^= i;
88
+ const r = n & -n >>> 0, c = S - Math.clz32(r);
89
+ t(i + c), n ^= r;
90
90
  }
91
91
  }
92
92
  }
@@ -179,12 +179,12 @@ class A {
179
179
  t.set(this._buf), this._buf = t;
180
180
  }
181
181
  }
182
- class st extends A {
182
+ class nt extends A {
183
183
  constructor(t = b) {
184
184
  super(Float32Array, t);
185
185
  }
186
186
  }
187
- class nt extends A {
187
+ class it extends A {
188
188
  constructor(t = b) {
189
189
  super(Float64Array, t);
190
190
  }
@@ -194,42 +194,42 @@ class rt extends A {
194
194
  super(Int8Array, t);
195
195
  }
196
196
  }
197
- class it extends A {
197
+ class _t extends A {
198
198
  constructor(t = b) {
199
199
  super(Int16Array, t);
200
200
  }
201
201
  }
202
- class _t extends A {
202
+ class ot extends A {
203
203
  constructor(t = b) {
204
204
  super(Int32Array, t);
205
205
  }
206
206
  }
207
- class ot extends A {
207
+ class ct extends A {
208
208
  constructor(t = b) {
209
209
  super(Uint8Array, t);
210
210
  }
211
211
  }
212
- class ct extends A {
212
+ class ht extends A {
213
213
  constructor(t = b) {
214
214
  super(Uint16Array, t);
215
215
  }
216
216
  }
217
- class $ extends A {
217
+ class H extends A {
218
218
  constructor(t = b) {
219
219
  super(Uint32Array, t);
220
220
  }
221
221
  }
222
- const ht = {
223
- f32: st,
224
- f64: nt,
222
+ const at = {
223
+ f32: nt,
224
+ f64: it,
225
225
  i8: rt,
226
- i16: it,
227
- i32: _t,
228
- u8: ot,
229
- u16: ct,
230
- u32: $
226
+ i16: _t,
227
+ i32: ot,
228
+ u8: ct,
229
+ u16: ht,
230
+ u32: H
231
231
  };
232
- class at {
232
+ class lt {
233
233
  _compare;
234
234
  _data = [];
235
235
  constructor(t) {
@@ -261,52 +261,52 @@ class at {
261
261
  _sift_up(t) {
262
262
  const e = this._data, s = this._compare, n = e[t];
263
263
  for (; t > 0; ) {
264
- const r = t - 1 >> 1;
265
- if (s(n, e[r]) >= 0) break;
266
- e[t] = e[r], t = r;
264
+ const i = t - 1 >> 1;
265
+ if (s(n, e[i]) >= 0) break;
266
+ e[t] = e[i], t = i;
267
267
  }
268
268
  e[t] = n;
269
269
  }
270
270
  /** Moves a node down away from the root until heap order is restored. */
271
271
  _sift_down(t) {
272
- const e = this._data, s = this._compare, n = e.length, r = n >> 1, i = e[t];
273
- for (; t < r; ) {
272
+ const e = this._data, s = this._compare, n = e.length, i = n >> 1, r = e[t];
273
+ for (; t < i; ) {
274
274
  let c = (t << 1) + 1;
275
275
  const o = c + 1;
276
- if (o < n && s(e[o], e[c]) < 0 && (c = o), s(e[c], i) >= 0) break;
276
+ if (o < n && s(e[o], e[c]) < 0 && (c = o), s(e[c], r) >= 0) break;
277
277
  e[t] = e[c], t = c;
278
278
  }
279
- e[t] = i;
279
+ e[t] = r;
280
280
  }
281
281
  }
282
- function lt(a, t, e, s) {
283
- const n = s ?? ((o) => String(o)), r = /* @__PURE__ */ new Map();
282
+ function dt(a, t, e, s) {
283
+ const n = s ?? ((o) => String(o)), i = /* @__PURE__ */ new Map();
284
284
  for (let o = 0; o < a.length; o++)
285
- r.set(a[o], 0);
285
+ i.set(a[o], 0);
286
286
  for (const [, o] of t)
287
287
  for (let _ = 0; _ < o.length; _++) {
288
288
  const h = o[_];
289
- r.has(h) && r.set(h, r.get(h) + 1);
289
+ i.has(h) && i.set(h, i.get(h) + 1);
290
290
  }
291
- const i = new at(e);
291
+ const r = new lt(e);
292
292
  for (let o = 0; o < a.length; o++)
293
- r.get(a[o]) === 0 && i.push(a[o]);
293
+ i.get(a[o]) === 0 && r.push(a[o]);
294
294
  const c = [];
295
- for (; i.size > 0; ) {
296
- const o = i.pop();
295
+ for (; r.size > 0; ) {
296
+ const o = r.pop();
297
297
  c.push(o);
298
298
  const _ = t.get(o);
299
299
  if (_ !== void 0)
300
300
  for (let h = 0; h < _.length; h++) {
301
301
  const l = _[h];
302
- if (!r.has(l)) continue;
303
- const d = r.get(l) - 1;
304
- r.set(l, d), d === 0 && i.push(l);
302
+ if (!i.has(l)) continue;
303
+ const d = i.get(l) - 1;
304
+ i.set(l, d), d === 0 && r.push(l);
305
305
  }
306
306
  }
307
307
  if (c.length !== a.length) {
308
308
  const o = [];
309
- for (const [_, h] of r)
309
+ for (const [_, h] of i)
310
310
  h > 0 && o.push(n(_));
311
311
  throw new globalThis.TypeError(
312
312
  `Cycle detected in topological sort. Nodes still pending: ${o.join(", ")}`
@@ -314,12 +314,12 @@ function lt(a, t, e, s) {
314
314
  }
315
315
  return c;
316
316
  }
317
- const E = -1, m = -1, U = Object.freeze(/* @__PURE__ */ Object.create(null)), dt = 2654435769, ut = 1367130551, H = 1024, j = 0, ft = 31, gt = 1 / 60, yt = 4, mt = 0, R = 20, G = (1 << R) - 1, pt = ft - R, V = (1 << pt) - 1, wt = (a, t) => t << R | a, y = (a) => a & G, z = (a) => a >> R, vt = (a) => F(
317
+ const k = -1, m = -1, q = Object.freeze(/* @__PURE__ */ Object.create(null)), ut = 2654435769, ft = 1367130551, K = 1024, j = 0, gt = 31, yt = 1 / 60, mt = 4, pt = 0, R = 20, M = (1 << R) - 1, wt = gt - R, V = (1 << wt) - 1, vt = (a, t) => t << R | a, y = (a) => a & M, z = (a) => a >> R, Et = (a) => F(
318
318
  a
319
- ), Et = (a) => F(
319
+ ), kt = (a) => F(
320
320
  a
321
321
  );
322
- class kt {
322
+ class Tt {
323
323
  field_names;
324
324
  columns;
325
325
  // any: type-erased storage — channel is stored in Map<number, EventChannel>, F is lost
@@ -353,19 +353,23 @@ class kt {
353
353
  function Ot(a) {
354
354
  return Symbol(a);
355
355
  }
356
- function Ut(a) {
356
+ function qt(a) {
357
357
  return Symbol(a);
358
358
  }
359
- const Tt = (a) => F(
359
+ const bt = (a) => F(
360
360
  a
361
361
  );
362
- class bt {
362
+ class At {
363
363
  id;
364
364
  mask;
365
365
  has_columns;
366
366
  _entity_ids;
367
367
  length = 0;
368
368
  edges = [];
369
+ // Cache for multi-component transition maps (from this archetype to another).
370
+ // Covers add_components / remove_components where the (src, dst) pair is not
371
+ // a single-component edge and therefore not covered by `edges[].add_map/remove_map`.
372
+ batch_transition_maps = /* @__PURE__ */ new Map();
369
373
  // --- Flat column storage ---
370
374
  // Dense array of ALL columns across all components in this archetype.
371
375
  _flat_columns = [];
@@ -383,15 +387,15 @@ class bt {
383
387
  _column_ids = [];
384
388
  // Sparse by ComponentID → last tick that modified this component's columns.
385
389
  _changed_tick = [];
386
- constructor(t, e, s, n = H) {
387
- if (this.id = t, this.mask = e, this._entity_ids = new $(n), s) {
388
- let r = 0;
389
- for (let i = 0; i < s.length; i++) {
390
- const c = s[i], o = c.component_id, _ = new Array(c.field_names.length);
391
- this._col_offset[o] = r, this._field_count[o] = c.field_names.length, this._field_index[o] = c.field_index, this._field_names[o] = c.field_names;
390
+ constructor(t, e, s, n = K) {
391
+ if (this.id = t, this.mask = e, this._entity_ids = new H(n), s) {
392
+ let i = 0;
393
+ for (let r = 0; r < s.length; r++) {
394
+ const c = s[r], o = c.component_id, _ = new Array(c.field_names.length);
395
+ this._col_offset[o] = i, this._field_count[o] = c.field_names.length, this._field_index[o] = c.field_index, this._field_names[o] = c.field_names;
392
396
  for (let h = 0; h < c.field_names.length; h++) {
393
- const l = new ht[c.field_types[h]](n);
394
- _[h] = l, this._flat_columns[r++] = l;
397
+ const l = new at[c.field_types[h]](n);
398
+ _[h] = l, this._flat_columns[i++] = l;
395
399
  }
396
400
  this.column_groups[o] = { layout: c, columns: _ }, this._column_ids.push(o), this._changed_tick[o] = 0;
397
401
  }
@@ -423,42 +427,42 @@ class bt {
423
427
  get_column_mut(t, e, s) {
424
428
  const n = t;
425
429
  this._changed_tick[n] = s;
426
- const r = this._field_index[n][e];
427
- return this._flat_columns[this._col_offset[n] + r].buf;
430
+ const i = this._field_index[n][e];
431
+ return this._flat_columns[this._col_offset[n] + i].buf;
428
432
  }
429
433
  write_fields(t, e, s, n) {
430
- const r = e, i = this._col_offset[r];
431
- if (i === void 0) return;
432
- this._changed_tick[r] = n;
433
- const c = this._field_names[r], o = this._flat_columns;
434
+ const i = e, r = this._col_offset[i];
435
+ if (r === void 0) return;
436
+ this._changed_tick[i] = n;
437
+ const c = this._field_names[i], o = this._flat_columns;
434
438
  for (let _ = 0; _ < c.length; _++)
435
- o[i + _].buf[t] = s[c[_]];
439
+ o[r + _].buf[t] = s[c[_]];
436
440
  }
437
441
  /** Fast positional write: values[i] → field[i] in declaration order. No string lookup. */
438
442
  write_fields_positional(t, e, s, n) {
439
- const r = e, i = this._col_offset[r];
440
- if (i === void 0) return;
441
- this._changed_tick[r] = n;
443
+ const i = e, r = this._col_offset[i];
444
+ if (r === void 0) return;
445
+ this._changed_tick[i] = n;
442
446
  const c = this._flat_columns;
443
447
  for (let o = 0; o < s.length; o++)
444
- c[i + o].buf[t] = s[o];
448
+ c[r + o].buf[t] = s[o];
445
449
  }
446
450
  read_field(t, e, s) {
447
- const n = e, r = this._col_offset[n];
448
- if (r === void 0) return NaN;
449
- const i = this._field_index[n][s];
450
- return i === void 0 ? NaN : this._flat_columns[r + i].buf[t];
451
+ const n = e, i = this._col_offset[n];
452
+ if (i === void 0) return NaN;
453
+ const r = this._field_index[n][s];
454
+ return r === void 0 ? NaN : this._flat_columns[i + r].buf[t];
451
455
  }
452
456
  /** Copy all shared component columns from source archetype at src_row into dst_row. */
453
457
  copy_shared_from(t, e, s, n) {
454
- const r = t._col_offset, i = t._field_count, c = t._flat_columns, o = this._flat_columns, _ = this._column_ids;
458
+ const i = t._col_offset, r = t._field_count, c = t._flat_columns, o = this._flat_columns, _ = this._column_ids;
455
459
  for (let h = 0; h < _.length; h++) {
456
- const l = _[h], d = r[l];
460
+ const l = _[h], d = i[l];
457
461
  if (d === void 0) continue;
458
462
  this._changed_tick[l] = n;
459
- const u = this._col_offset[l], g = i[l];
460
- for (let p = 0; p < g; p++)
461
- o[u + p].buf[s] = c[d + p].buf[e];
463
+ const u = this._col_offset[l], g = r[l];
464
+ for (let w = 0; w < g; w++)
465
+ o[u + w].buf[s] = c[d + w].buf[e];
462
466
  }
463
467
  }
464
468
  /**
@@ -481,14 +485,14 @@ class bt {
481
485
  remove_entity(t) {
482
486
  const e = this.length - 1;
483
487
  let s = m;
484
- const n = this._flat_columns, r = this._entity_ids.buf;
488
+ const n = this._flat_columns, i = this._entity_ids.buf;
485
489
  if (t !== e) {
486
- r[t] = r[e], s = y(r[t]);
487
- for (let i = 0; i < n.length; i++)
488
- n[i].swap_remove(t);
490
+ i[t] = i[e], s = y(i[t]);
491
+ for (let r = 0; r < n.length; r++)
492
+ n[r].swap_remove(t);
489
493
  } else
490
- for (let i = 0; i < n.length; i++)
491
- n[i].pop();
494
+ for (let r = 0; r < n.length; r++)
495
+ n[r].pop();
492
496
  return this._entity_ids.pop(), this.length--, s;
493
497
  }
494
498
  /** Tag-optimized add: skip column push entirely (no data to store). */
@@ -509,8 +513,8 @@ class bt {
509
513
  * Uses a pre-computed transition map for branchless column copy.
510
514
  * Writes dst_row to _move_result[0], swapped entity index to _move_result[1].
511
515
  */
512
- move_entity_from(t, e, s, n, r) {
513
- const i = this.length;
516
+ move_entity_from(t, e, s, n, i) {
517
+ const r = this.length;
514
518
  this._entity_ids.push(s);
515
519
  const c = this._flat_columns, o = t._flat_columns;
516
520
  for (let l = 0; l < c.length; l++) {
@@ -519,10 +523,10 @@ class bt {
519
523
  }
520
524
  const _ = this._column_ids;
521
525
  for (let l = 0; l < _.length; l++)
522
- this._changed_tick[_[l]] = r;
526
+ this._changed_tick[_[l]] = i;
523
527
  this.length++;
524
528
  const h = t.has_columns ? t.remove_entity(e) : t.remove_entity_tag(e);
525
- f[0] = i, f[1] = h;
529
+ f[0] = r, f[1] = h;
526
530
  }
527
531
  /**
528
532
  * Move an entity from src into this archetype (tag-only: no columns to copy).
@@ -531,8 +535,8 @@ class bt {
531
535
  move_entity_from_tag(t, e, s) {
532
536
  const n = this.length;
533
537
  this._entity_ids.push(s), this.length++;
534
- const r = t.remove_entity_tag(e);
535
- f[0] = n, f[1] = r;
538
+ const i = t.remove_entity_tag(e);
539
+ f[0] = n, f[1] = i;
536
540
  }
537
541
  /**
538
542
  * Bulk-move ALL entities from src into this archetype using TypedArray.set().
@@ -542,11 +546,11 @@ class bt {
542
546
  bulk_move_all_from(t, e, s) {
543
547
  const n = t.length;
544
548
  if (n === 0) return this.length;
545
- const r = this.length, i = this._flat_columns, c = t._flat_columns;
549
+ const i = this.length, r = this._flat_columns, c = t._flat_columns;
546
550
  this._entity_ids.bulk_append(t._entity_ids.buf, 0, n);
547
- for (let _ = 0; _ < i.length; _++) {
551
+ for (let _ = 0; _ < r.length; _++) {
548
552
  const h = e[_];
549
- h >= 0 ? i[_].bulk_append(c[h].buf, 0, n) : i[_].bulk_append_zeroes(n);
553
+ h >= 0 ? r[_].bulk_append(c[h].buf, 0, n) : r[_].bulk_append_zeroes(n);
550
554
  }
551
555
  const o = this._column_ids;
552
556
  for (let _ = 0; _ < o.length; _++)
@@ -554,7 +558,7 @@ class bt {
554
558
  this.length += n, t.length = 0, t._entity_ids.clear();
555
559
  for (let _ = 0; _ < c.length; _++)
556
560
  c[_].clear();
557
- return r;
561
+ return i;
558
562
  }
559
563
  get_edge(t) {
560
564
  return this.edges[t];
@@ -562,12 +566,21 @@ class bt {
562
566
  set_edge(t, e) {
563
567
  this.edges[t] = e;
564
568
  }
569
+ /**
570
+ * Get the cached transition map from this archetype to `target`, building
571
+ * and caching it on miss. Archetypes live for the lifetime of the Store,
572
+ * so entries never need invalidation.
573
+ */
574
+ get_batch_transition_map(t) {
575
+ let e = this.batch_transition_maps.get(t.id);
576
+ return e === void 0 && (e = G(this, t), this.batch_transition_maps.set(t.id, e)), e;
577
+ }
565
578
  }
566
579
  const f = [0, m];
567
- function M(a, t) {
568
- const e = t._flat_columns, s = new Int16Array(e.length), n = t._column_ids, r = a._col_offset, i = t._col_offset, c = t._field_count;
580
+ function G(a, t) {
581
+ const e = t._flat_columns, s = new Int16Array(e.length), n = t._column_ids, i = a._col_offset, r = t._col_offset, c = t._field_count;
569
582
  for (let o = 0; o < n.length; o++) {
570
- const _ = n[o], h = i[_], l = c[_], d = r[_];
583
+ const _ = n[o], h = r[_], l = c[_], d = i[_];
571
584
  if (d !== void 0)
572
585
  for (let u = 0; u < l; u++)
573
586
  s[h + u] = d + u;
@@ -577,11 +590,11 @@ function M(a, t) {
577
590
  }
578
591
  return s;
579
592
  }
580
- function K(a, t, e) {
593
+ function Q(a, t, e) {
581
594
  const s = a.get(t);
582
595
  s !== void 0 ? s.push(e) : a.set(t, [e]);
583
596
  }
584
- class At {
597
+ class xt {
585
598
  // --- Entity ID management ---
586
599
  // Generational slot allocator: entity_generations[index] holds the current
587
600
  // generation for that slot. Free indices are recycled via a stack.
@@ -626,7 +639,7 @@ class At {
626
639
  _tick = 0;
627
640
  initial_capacity;
628
641
  constructor(t) {
629
- this.initial_capacity = t ?? H, this.empty_archetype_id = this.arch_get_or_create_from_mask(new k());
642
+ this.initial_capacity = t ?? K, this.empty_archetype_id = this.arch_get_or_create_from_mask(new p());
630
643
  }
631
644
  // =======================================================
632
645
  // Archetype graph
@@ -645,18 +658,18 @@ class At {
645
658
  if (this.archetypes[s[o]].mask.equals(t))
646
659
  return s[o];
647
660
  }
648
- const n = Tt(this.next_archetype_id++), r = [];
661
+ const n = bt(this.next_archetype_id++), i = [];
649
662
  t.for_each((o) => {
650
663
  const _ = o, h = this.component_metas[_];
651
- h && h.field_names.length > 0 && r.push({
664
+ h && h.field_names.length > 0 && i.push({
652
665
  component_id: _,
653
666
  field_names: h.field_names,
654
667
  field_index: h.field_index,
655
668
  field_types: h.field_types
656
669
  });
657
670
  });
658
- const i = new bt(n, t, r, this.initial_capacity);
659
- this.archetypes.push(i), K(this.archetype_map, e, n), t.for_each((o) => {
671
+ const r = new At(n, t, i, this.initial_capacity);
672
+ this.archetypes.push(r), Q(this.archetype_map, e, n), t.for_each((o) => {
660
673
  const _ = o;
661
674
  let h = this.component_index.get(_);
662
675
  h || (h = /* @__PURE__ */ new Set(), this.component_index.set(_, h)), h.add(n);
@@ -664,7 +677,7 @@ class At {
664
677
  const c = this.registered_queries;
665
678
  for (let o = 0; o < c.length; o++) {
666
679
  const _ = c[o];
667
- i.matches(_.include_mask) && (!_.exclude_mask || !i.mask.overlaps(_.exclude_mask)) && (!_.any_of_mask || i.mask.overlaps(_.any_of_mask)) && (_.result.push(i), _.query?.mark_non_empty_dirty());
680
+ r.matches(_.include_mask) && (!_.exclude_mask || !r.mask.overlaps(_.exclude_mask)) && (!_.any_of_mask || r.mask.overlaps(_.any_of_mask)) && (_.result.push(r), _.query?.mark_non_empty_dirty());
668
681
  }
669
682
  return n;
670
683
  }
@@ -674,10 +687,10 @@ class At {
674
687
  if (s.mask.has(e)) return t;
675
688
  const n = s.get_edge(e);
676
689
  if (n?.add != null) return n.add;
677
- const r = this.arch_get_or_create_from_mask(
690
+ const i = this.arch_get_or_create_from_mask(
678
691
  s.mask.copy_with_set(e)
679
692
  );
680
- return this.arch_cache_edge(s, this.arch_get(r), e), r;
693
+ return this.arch_cache_edge(s, this.arch_get(i), e), i;
681
694
  }
682
695
  /** Resolve "remove component_id from archetype_id" → target ArchetypeID. Caches the edge. */
683
696
  arch_resolve_remove(t, e) {
@@ -685,10 +698,10 @@ class At {
685
698
  if (!s.mask.has(e)) return t;
686
699
  const n = s.get_edge(e);
687
700
  if (n?.remove != null) return n.remove;
688
- const r = this.arch_get_or_create_from_mask(
701
+ const i = this.arch_get_or_create_from_mask(
689
702
  s.mask.copy_with_clear(e)
690
703
  );
691
- return this.arch_cache_edge(this.arch_get(r), s, e), r;
704
+ return this.arch_cache_edge(this.arch_get(i), s, e), i;
692
705
  }
693
706
  /** Cache a bidirectional add/remove edge between two archetypes. */
694
707
  arch_cache_edge(t, e, s) {
@@ -698,14 +711,14 @@ class At {
698
711
  add_map: null,
699
712
  remove_map: null
700
713
  };
701
- n.add = e.id, n.add_map = M(t, e), t.set_edge(s, n);
702
- const r = e.get_edge(s) ?? {
714
+ n.add = e.id, n.add_map = G(t, e), t.set_edge(s, n);
715
+ const i = e.get_edge(s) ?? {
703
716
  add: null,
704
717
  remove: null,
705
718
  add_map: null,
706
719
  remove_map: null
707
720
  };
708
- r.remove = t.id, r.remove_map = M(e, t), e.set_edge(s, r);
721
+ i.remove = t.id, i.remove_map = G(e, t), e.set_edge(s, i);
709
722
  }
710
723
  // =======================================================
711
724
  // Entity lifecycle
@@ -713,19 +726,19 @@ class At {
713
726
  create_entity() {
714
727
  let t, e;
715
728
  this.entity_free_indices.length > 0 ? (t = this.entity_free_indices.pop(), e = this.entity_generations[t]) : (t = this.entity_high_water++, this.entity_generations[t] = j, e = j), this.entity_alive_count++;
716
- const s = wt(t, e);
717
- return this.entity_archetype[t] = this.empty_archetype_id, this.entity_row[t] = E, s;
729
+ const s = vt(t, e);
730
+ return this.entity_archetype[t] = this.empty_archetype_id, this.entity_row[t] = k, s;
718
731
  }
719
732
  /** Immediately destroy an entity, removing it from its archetype. */
720
733
  destroy_entity(t) {
721
734
  if (!this.is_alive(t))
722
735
  return;
723
736
  const e = y(t), s = this.entity_row[e];
724
- if (s !== E) {
725
- const i = this.arch_get(this.entity_archetype[e]).remove_entity(s);
726
- i !== m && (this.entity_row[i] = s);
737
+ if (s !== k) {
738
+ const r = this.arch_get(this.entity_archetype[e]).remove_entity(s);
739
+ r !== m && (this.entity_row[r] = s);
727
740
  }
728
- this.entity_archetype[e] = E, this.entity_row[e] = E;
741
+ this.entity_archetype[e] = k, this.entity_row[e] = k;
729
742
  const n = z(t);
730
743
  this.entity_generations[e] = n + 1 & V, this.entity_free_indices.push(e), this.entity_alive_count--;
731
744
  }
@@ -751,16 +764,16 @@ class At {
751
764
  flush_destroyed() {
752
765
  const t = this.pending_destroy;
753
766
  if (t.length === 0) return;
754
- const e = this.entity_archetype, s = this.entity_row, n = this.entity_generations, r = this.archetypes, i = this.entity_high_water;
767
+ const e = this.entity_archetype, s = this.entity_row, n = this.entity_generations, i = this.archetypes, r = this.entity_high_water;
755
768
  for (let c = 0; c < t.length; c++) {
756
- const o = t[c], _ = o & G, h = o >> R;
757
- if (_ >= i || n[_] !== h) continue;
769
+ const o = t[c], _ = o & M, h = o >> R;
770
+ if (_ >= r || n[_] !== h) continue;
758
771
  const l = s[_];
759
- if (l !== E) {
760
- const d = r[e[_]], u = d.has_columns ? d.remove_entity(l) : d.remove_entity_tag(l);
772
+ if (l !== k) {
773
+ const d = i[e[_]], u = d.has_columns ? d.remove_entity(l) : d.remove_entity_tag(l);
761
774
  u !== m && (s[u] = l);
762
775
  }
763
- e[_] = E, s[_] = E, n[_] = h + 1 & V, this.entity_free_indices.push(_), this.entity_alive_count--;
776
+ e[_] = k, s[_] = k, n[_] = h + 1 & V, this.entity_free_indices.push(_), this.entity_alive_count--;
764
777
  }
765
778
  t.length = 0, this._mark_queries_dirty();
766
779
  }
@@ -768,7 +781,7 @@ class At {
768
781
  return this.pending_destroy.length;
769
782
  }
770
783
  add_component_deferred(t, e, s) {
771
- this.pending_add_ids.push(t), this.pending_add_defs.push(e), this.pending_add_values.push(s ?? U);
784
+ this.pending_add_ids.push(t), this.pending_add_defs.push(e), this.pending_add_values.push(s ?? q);
772
785
  }
773
786
  remove_component_deferred(t, e) {
774
787
  this.pending_remove_ids.push(t), this.pending_remove_defs.push(e);
@@ -779,47 +792,47 @@ class At {
779
792
  }
780
793
  /** Batch-apply all deferred component additions. */
781
794
  _flush_adds() {
782
- const t = this.pending_add_ids, e = this.pending_add_defs, s = this.pending_add_values, n = t.length, r = this.entity_archetype, i = this.entity_row, c = this.entity_generations, o = this.archetypes, _ = this.component_metas, h = this.entity_high_water, l = this._tick;
795
+ const t = this.pending_add_ids, e = this.pending_add_defs, s = this.pending_add_values, n = t.length, i = this.entity_archetype, r = this.entity_row, c = this.entity_generations, o = this.archetypes, _ = this.component_metas, h = this.entity_high_water, l = this._tick;
783
796
  for (let d = 0; d < n; d++) {
784
- const u = t[d], g = u & G, p = u >> R;
785
- if (g >= h || c[g] !== p) continue;
786
- const T = r[g], w = e[d], v = o[T];
787
- if (v.mask.has(w)) {
788
- _[w].field_names.length > 0 && v.write_fields(i[g], w, s[d], l);
797
+ const u = t[d], g = u & M, w = u >> R;
798
+ if (g >= h || c[g] !== w) continue;
799
+ const T = i[g], v = e[d], E = o[T];
800
+ if (E.mask.has(v)) {
801
+ _[v].field_names.length > 0 && E.write_fields(r[g], v, s[d], l);
789
802
  continue;
790
803
  }
791
- const N = this.arch_resolve_add(T, w), x = o[N], P = i[g], Y = !x.has_columns && !v.has_columns;
792
- let q;
793
- if (P !== E) {
804
+ const N = this.arch_resolve_add(T, v), x = o[N], P = r[g], Y = !x.has_columns && !E.has_columns;
805
+ let U;
806
+ if (P !== k) {
794
807
  if (Y)
795
- x.move_entity_from_tag(v, P, u);
808
+ x.move_entity_from_tag(E, P, u);
796
809
  else {
797
- const Q = v.get_edge(w);
798
- x.move_entity_from(v, P, u, Q.add_map, l);
810
+ const J = E.get_edge(v);
811
+ x.move_entity_from(E, P, u, J.add_map, l);
799
812
  }
800
- q = f[0], f[1] !== m && (i[f[1]] = P);
813
+ U = f[0], f[1] !== m && (r[f[1]] = P);
801
814
  } else
802
- q = Y ? x.add_entity_tag(u) : x.add_entity(u);
803
- _[w].field_names.length > 0 && x.write_fields(q, w, s[d], l), r[g] = N, i[g] = q;
815
+ U = Y ? x.add_entity_tag(u) : x.add_entity(u);
816
+ _[v].field_names.length > 0 && x.write_fields(U, v, s[d], l), i[g] = N, r[g] = U;
804
817
  }
805
818
  t.length = 0, e.length = 0, s.length = 0;
806
819
  }
807
820
  /** Batch-apply all deferred component removals. */
808
821
  _flush_removes() {
809
- const t = this.pending_remove_ids, e = this.pending_remove_defs, s = t.length, n = this.entity_archetype, r = this.entity_row, i = this.entity_generations, c = this.archetypes, o = this.entity_high_water, _ = this._tick;
822
+ const t = this.pending_remove_ids, e = this.pending_remove_defs, s = t.length, n = this.entity_archetype, i = this.entity_row, r = this.entity_generations, c = this.archetypes, o = this.entity_high_water, _ = this._tick;
810
823
  for (let h = 0; h < s; h++) {
811
- const l = t[h], d = l & G, u = l >> R;
812
- if (d >= o || i[d] !== u) continue;
813
- const g = n[d], p = e[h], T = c[g];
814
- if (!T.mask.has(p)) continue;
815
- const w = this.arch_resolve_remove(g, p), v = c[w], N = r[d];
816
- if (!v.has_columns && !T.has_columns)
817
- v.move_entity_from_tag(T, N, l);
824
+ const l = t[h], d = l & M, u = l >> R;
825
+ if (d >= o || r[d] !== u) continue;
826
+ const g = n[d], w = e[h], T = c[g];
827
+ if (!T.mask.has(w)) continue;
828
+ const v = this.arch_resolve_remove(g, w), E = c[v], N = i[d];
829
+ if (!E.has_columns && !T.has_columns)
830
+ E.move_entity_from_tag(T, N, l);
818
831
  else {
819
- const P = T.get_edge(p);
820
- v.move_entity_from(T, N, l, P.remove_map, _);
832
+ const P = T.get_edge(w);
833
+ E.move_entity_from(T, N, l, P.remove_map, _);
821
834
  }
822
- f[1] !== m && (r[f[1]] = N), n[d] = w, r[d] = f[0];
835
+ f[1] !== m && (i[f[1]] = N), n[d] = v, i[d] = f[0];
823
836
  }
824
837
  t.length = 0, e.length = 0;
825
838
  }
@@ -830,17 +843,17 @@ class At {
830
843
  // Component registration
831
844
  // =======================================================
832
845
  register_component(t) {
833
- const e = vt(this.component_count++), s = Object.keys(t), n = new Array(s.length), r = /* @__PURE__ */ Object.create(null);
834
- for (let i = 0; i < s.length; i++)
835
- r[s[i]] = i, n[i] = t[s[i]];
836
- return this.component_metas.push({ field_names: s, field_index: r, field_types: n }), e;
846
+ const e = Et(this.component_count++), s = Object.keys(t), n = new Array(s.length), i = /* @__PURE__ */ Object.create(null);
847
+ for (let r = 0; r < s.length; r++)
848
+ i[s[r]] = r, n[r] = t[s[r]];
849
+ return this.component_metas.push({ field_names: s, field_index: i, field_types: n }), e;
837
850
  }
838
851
  add_component(t, e, s) {
839
852
  if (!this.is_alive(t))
840
853
  return;
841
- const n = y(t), r = this.entity_archetype[n], i = this.arch_get(r);
842
- if (i.has_component(e)) {
843
- i.write_fields(
854
+ const n = y(t), i = this.entity_archetype[n], r = this.arch_get(i);
855
+ if (r.has_component(e)) {
856
+ r.write_fields(
844
857
  this.entity_row[n],
845
858
  e,
846
859
  s,
@@ -848,11 +861,11 @@ class At {
848
861
  );
849
862
  return;
850
863
  }
851
- const c = this.arch_resolve_add(r, e), o = this.arch_get(c), _ = this.entity_row[n];
864
+ const c = this.arch_resolve_add(i, e), o = this.arch_get(c), _ = this.entity_row[n];
852
865
  let h;
853
- if (_ !== E) {
854
- const l = i.get_edge(e);
855
- !o.has_columns && !i.has_columns ? o.move_entity_from_tag(i, _, t) : o.move_entity_from(i, _, t, l.add_map, this._tick), h = f[0], f[1] !== m && (this.entity_row[f[1]] = _);
866
+ if (_ !== k) {
867
+ const l = r.get_edge(e);
868
+ !o.has_columns && !r.has_columns ? o.move_entity_from_tag(r, _, t) : o.move_entity_from(r, _, t, l.add_map, this._tick), h = f[0], f[1] !== m && (this.entity_row[f[1]] = _);
856
869
  } else
857
870
  h = o.has_columns ? o.add_entity(t) : o.add_entity_tag(t);
858
871
  o.write_fields(
@@ -867,32 +880,32 @@ class At {
867
880
  if (!this.is_alive(t))
868
881
  return;
869
882
  const s = y(t), n = this.entity_archetype[s];
870
- let r = n;
871
- for (let i = 0; i < e.length; i++)
872
- r = this.arch_resolve_add(r, e[i].def);
873
- if (r !== n) {
874
- const i = this.arch_get(n), c = this.arch_get(r), o = this.entity_row[s];
883
+ let i = n;
884
+ for (let r = 0; r < e.length; r++)
885
+ i = this.arch_resolve_add(i, e[r].def);
886
+ if (i !== n) {
887
+ const r = this.arch_get(n), c = this.arch_get(i), o = this.entity_row[s];
875
888
  let _;
876
- if (o !== E) {
877
- const h = M(i, c);
878
- c.move_entity_from(i, o, t, h, this._tick), _ = f[0], f[1] !== m && (this.entity_row[f[1]] = o);
889
+ if (o !== k) {
890
+ const h = r.get_batch_transition_map(c);
891
+ c.move_entity_from(r, o, t, h, this._tick), _ = f[0], f[1] !== m && (this.entity_row[f[1]] = o);
879
892
  } else
880
893
  _ = c.add_entity(t);
881
894
  for (let h = 0; h < e.length; h++)
882
895
  c.write_fields(
883
896
  _,
884
897
  e[h].def,
885
- e[h].values ?? U,
898
+ e[h].values ?? q,
886
899
  this._tick
887
900
  );
888
- this.entity_archetype[s] = r, this.entity_row[s] = _, this._mark_queries_dirty();
901
+ this.entity_archetype[s] = i, this.entity_row[s] = _, this._mark_queries_dirty();
889
902
  } else {
890
- const i = this.arch_get(n), c = this.entity_row[s];
903
+ const r = this.arch_get(n), c = this.entity_row[s];
891
904
  for (let o = 0; o < e.length; o++)
892
- i.write_fields(
905
+ r.write_fields(
893
906
  c,
894
907
  e[o].def,
895
- e[o].values ?? U,
908
+ e[o].values ?? q,
896
909
  this._tick
897
910
  );
898
911
  }
@@ -900,25 +913,25 @@ class At {
900
913
  remove_component(t, e) {
901
914
  if (!this.is_alive(t))
902
915
  return;
903
- const s = y(t), n = this.entity_archetype[s], r = this.arch_get(n);
904
- if (!r.has_component(e)) return;
905
- const i = this.arch_resolve_remove(n, e), c = this.arch_get(i), o = this.entity_row[s], _ = r.get_edge(e);
906
- !c.has_columns && !r.has_columns ? c.move_entity_from_tag(r, o, t) : c.move_entity_from(r, o, t, _.remove_map, this._tick), f[1] !== m && (this.entity_row[f[1]] = o), this.entity_archetype[s] = i, this.entity_row[s] = f[0], this._mark_queries_dirty();
916
+ const s = y(t), n = this.entity_archetype[s], i = this.arch_get(n);
917
+ if (!i.has_component(e)) return;
918
+ const r = this.arch_resolve_remove(n, e), c = this.arch_get(r), o = this.entity_row[s], _ = i.get_edge(e);
919
+ !c.has_columns && !i.has_columns ? c.move_entity_from_tag(i, o, t) : c.move_entity_from(i, o, t, _.remove_map, this._tick), f[1] !== m && (this.entity_row[f[1]] = o), this.entity_archetype[s] = r, this.entity_row[s] = f[0], this._mark_queries_dirty();
907
920
  }
908
921
  /** Remove multiple components in one transition (resolves final archetype, then moves once). */
909
922
  remove_components(t, e) {
910
923
  if (!this.is_alive(t))
911
924
  return;
912
925
  const s = y(t), n = this.entity_archetype[s];
913
- let r = n;
926
+ let i = n;
914
927
  for (let h = 0; h < e.length; h++)
915
- r = this.arch_resolve_remove(
916
- r,
928
+ i = this.arch_resolve_remove(
929
+ i,
917
930
  e[h]
918
931
  );
919
- if (r === n) return;
920
- const i = this.arch_get(n), c = this.arch_get(r), o = this.entity_row[s], _ = M(i, c);
921
- c.move_entity_from(i, o, t, _, this._tick), f[1] !== m && (this.entity_row[f[1]] = o), this.entity_archetype[s] = r, this.entity_row[s] = f[0], this._mark_queries_dirty();
932
+ if (i === n) return;
933
+ const r = this.arch_get(n), c = this.arch_get(i), o = this.entity_row[s], _ = G(r, c);
934
+ c.move_entity_from(r, o, t, _, this._tick), f[1] !== m && (this.entity_row[f[1]] = o), this.entity_archetype[s] = i, this.entity_row[s] = f[0], this._mark_queries_dirty();
922
935
  }
923
936
  has_component(t, e) {
924
937
  if (!this.is_alive(t))
@@ -935,14 +948,14 @@ class At {
935
948
  if (t.length === 0) return;
936
949
  const n = e;
937
950
  if (t.mask.has(n)) return;
938
- const r = this.arch_resolve_add(t.id, n), i = this.arch_get(r), c = t.get_edge(n), o = t.length, _ = this.entity_archetype, h = this.entity_row, l = i.bulk_move_all_from(t, c.add_map, this._tick);
951
+ const i = this.arch_resolve_add(t.id, n), r = this.arch_get(i), c = t.get_edge(n), o = t.length, _ = this.entity_archetype, h = this.entity_row, l = r.bulk_move_all_from(t, c.add_map, this._tick);
939
952
  for (let u = 0; u < o; u++) {
940
- const g = y(i.entity_ids[l + u]);
941
- _[g] = r, h[g] = l + u;
953
+ const g = y(r.entity_ids[l + u]);
954
+ _[g] = i, h[g] = l + u;
942
955
  }
943
956
  if (this.component_metas[n].field_names.length > 0 && s)
944
957
  for (let u = 0; u < o; u++)
945
- i.write_fields(l + u, n, s, this._tick);
958
+ r.write_fields(l + u, n, s, this._tick);
946
959
  this._mark_queries_dirty();
947
960
  }
948
961
  /**
@@ -954,9 +967,9 @@ class At {
954
967
  if (t.length === 0) return;
955
968
  const s = e;
956
969
  if (!t.mask.has(s)) return;
957
- const n = this.arch_resolve_remove(t.id, s), r = this.arch_get(n), i = t.get_edge(s), c = t.length, o = r.bulk_move_all_from(t, i.remove_map, this._tick), _ = this.entity_archetype, h = this.entity_row;
970
+ const n = this.arch_resolve_remove(t.id, s), i = this.arch_get(n), r = t.get_edge(s), c = t.length, o = i.bulk_move_all_from(t, r.remove_map, this._tick), _ = this.entity_archetype, h = this.entity_row;
958
971
  for (let l = 0; l < c; l++) {
959
- const d = y(r.entity_ids[o + l]);
972
+ const d = y(i.entity_ids[o + l]);
960
973
  _[d] = n, h[d] = o + l;
961
974
  }
962
975
  this._mark_queries_dirty();
@@ -980,17 +993,17 @@ class At {
980
993
  */
981
994
  get_matching_archetypes(t, e, s) {
982
995
  const n = t._words;
983
- let r = !1;
996
+ let i = !1;
984
997
  for (let _ = 0; _ < n.length; _++)
985
998
  if (n[_] !== 0) {
986
- r = !0;
999
+ i = !0;
987
1000
  break;
988
1001
  }
989
- if (!r)
1002
+ if (!i)
990
1003
  return this.archetypes.filter(
991
1004
  (_) => (!e || !_.mask.overlaps(e)) && (!s || _.mask.overlaps(s))
992
1005
  );
993
- let i, c = !1;
1006
+ let r, c = !1;
994
1007
  for (let _ = 0; _ < n.length; _++) {
995
1008
  let h = n[_];
996
1009
  if (h === 0) continue;
@@ -1003,13 +1016,13 @@ class At {
1003
1016
  c = !0;
1004
1017
  break;
1005
1018
  }
1006
- (!i || g.size < i.size) && (i = g);
1019
+ (!r || g.size < r.size) && (r = g);
1007
1020
  }
1008
1021
  if (c) break;
1009
1022
  }
1010
- if (c || !i) return [];
1023
+ if (c || !r) return [];
1011
1024
  const o = [];
1012
- for (const _ of i) {
1025
+ for (const _ of r) {
1013
1026
  const h = this.arch_get(_);
1014
1027
  h.matches(t) && (!e || !h.mask.overlaps(e)) && (!s || h.mask.overlaps(s)) && o.push(h);
1015
1028
  }
@@ -1044,7 +1057,7 @@ class At {
1044
1057
  // Event channels
1045
1058
  // =======================================================
1046
1059
  register_event(t) {
1047
- const e = Et(this.event_count++), s = new kt(t);
1060
+ const e = kt(this.event_count++), s = new Tt(t);
1048
1061
  return this.event_channels.push(s), e;
1049
1062
  }
1050
1063
  emit_event(t, e) {
@@ -1105,7 +1118,7 @@ class At {
1105
1118
  return this.resource_key_map.has(t);
1106
1119
  }
1107
1120
  }
1108
- var xt = /* @__PURE__ */ ((a) => (a.PRE_STARTUP = "PRE_STARTUP", a.STARTUP = "STARTUP", a.POST_STARTUP = "POST_STARTUP", a.FIXED_UPDATE = "FIXED_UPDATE", a.PRE_UPDATE = "PRE_UPDATE", a.UPDATE = "UPDATE", a.POST_UPDATE = "POST_UPDATE", a))(xt || {});
1121
+ var It = /* @__PURE__ */ ((a) => (a.PRE_STARTUP = "PRE_STARTUP", a.STARTUP = "STARTUP", a.POST_STARTUP = "POST_STARTUP", a.FIXED_UPDATE = "FIXED_UPDATE", a.PRE_UPDATE = "PRE_UPDATE", a.UPDATE = "UPDATE", a.POST_UPDATE = "POST_UPDATE", a))(It || {});
1109
1122
  const L = [
1110
1123
  "PRE_STARTUP",
1111
1124
  "STARTUP",
@@ -1117,7 +1130,7 @@ const L = [
1117
1130
  "POST_UPDATE"
1118
1131
  /* POST_UPDATE */
1119
1132
  ];
1120
- class It {
1133
+ class St {
1121
1134
  label_systems = /* @__PURE__ */ new Map();
1122
1135
  sorted_cache = /* @__PURE__ */ new Map();
1123
1136
  system_index = /* @__PURE__ */ new Map();
@@ -1132,30 +1145,30 @@ class It {
1132
1145
  }
1133
1146
  add_systems(t, ...e) {
1134
1147
  for (const s of e) {
1135
- const n = "system" in s ? s.system : s, r = "system" in s ? s.ordering : void 0, i = {
1148
+ const n = "system" in s ? s.system : s, i = "system" in s ? s.ordering : void 0, r = {
1136
1149
  descriptor: n,
1137
1150
  insertion_order: this.next_insertion_order++,
1138
- before: new Set(r?.before ?? []),
1139
- after: new Set(r?.after ?? [])
1151
+ before: new Set(i?.before ?? []),
1152
+ after: new Set(i?.after ?? [])
1140
1153
  };
1141
- this.label_systems.get(t).push(i), this.system_index.set(n, t), this.system_last_run.set(n, 0), this.sorted_cache.delete(t);
1154
+ this.label_systems.get(t).push(r), this.system_index.set(n, t), this.system_last_run.set(n, 0), this.sorted_cache.delete(t);
1142
1155
  }
1143
1156
  }
1144
1157
  remove_system(t) {
1145
1158
  const e = this.system_index.get(t);
1146
1159
  if (e === void 0) return;
1147
- const s = this.label_systems.get(e), n = s.findIndex((r) => r.descriptor === t);
1160
+ const s = this.label_systems.get(e), n = s.findIndex((i) => i.descriptor === t);
1148
1161
  if (n !== -1) {
1149
- const r = s.length - 1;
1150
- n !== r && (s[n] = s[r]), s.pop();
1151
- for (const i of s)
1152
- i.before.delete(t), i.after.delete(t);
1162
+ const i = s.length - 1;
1163
+ n !== i && (s[n] = s[i]), s.pop();
1164
+ for (const r of s)
1165
+ r.before.delete(t), r.after.delete(t);
1153
1166
  }
1154
1167
  this.system_index.delete(t), this.system_last_run.delete(t), this.sorted_cache.delete(e);
1155
1168
  }
1156
1169
  run_startup(t, e) {
1157
1170
  for (const s of L)
1158
- this.run_label(s, t, mt, e);
1171
+ this.run_label(s, t, pt, e);
1159
1172
  }
1160
1173
  run_update(t, e, s) {
1161
1174
  for (const n of C)
@@ -1186,9 +1199,9 @@ class It {
1186
1199
  this.sorted_cache.clear(), this.system_index.clear(), this.system_last_run.clear();
1187
1200
  }
1188
1201
  run_label(t, e, s, n) {
1189
- const r = this.get_sorted(t);
1190
- for (let i = 0; i < r.length; i++)
1191
- this.system_last_run.set(r[i], n), e.last_run_tick = n, r[i].fn(e, s);
1202
+ const i = this.get_sorted(t);
1203
+ for (let r = 0; r < i.length; r++)
1204
+ this.system_last_run.set(i[r], n), e.last_run_tick = n, i[r].fn(e, s);
1192
1205
  e.flush();
1193
1206
  }
1194
1207
  get_sorted(t) {
@@ -1204,21 +1217,21 @@ class It {
1204
1217
  */
1205
1218
  sort_systems(t, e) {
1206
1219
  if (t.length === 0) return [];
1207
- const s = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
1220
+ const s = [], n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set();
1208
1221
  for (const _ of t)
1209
- s.push(_.descriptor), n.set(_.descriptor, _.insertion_order), r.add(_.descriptor);
1210
- const i = /* @__PURE__ */ new Map();
1222
+ s.push(_.descriptor), n.set(_.descriptor, _.insertion_order), i.add(_.descriptor);
1223
+ const r = /* @__PURE__ */ new Map();
1211
1224
  for (const _ of t)
1212
- i.set(_.descriptor, []);
1225
+ r.set(_.descriptor, []);
1213
1226
  for (const _ of t) {
1214
1227
  for (const h of _.before)
1215
- r.has(h) && i.get(_.descriptor).push(h);
1228
+ i.has(h) && r.get(_.descriptor).push(h);
1216
1229
  for (const h of _.after)
1217
- r.has(h) && i.get(h).push(_.descriptor);
1230
+ i.has(h) && r.get(h).push(_.descriptor);
1218
1231
  }
1219
1232
  const c = (_, h) => n.get(_) - n.get(h), o = (_) => _.name ?? `system_${_.id}`;
1220
1233
  try {
1221
- return lt(s, i, c, o);
1234
+ return dt(s, r, c, o);
1222
1235
  } catch (_) {
1223
1236
  throw _ instanceof TypeError ? new O(
1224
1237
  D.CIRCULAR_SYSTEM_DEPENDENCY,
@@ -1232,10 +1245,10 @@ function B(a, t) {
1232
1245
  let e = W.get(a);
1233
1246
  if (!e) {
1234
1247
  e = /* @__PURE__ */ Object.create(null);
1235
- const { field_names: r } = a.layout;
1236
- for (let i = 0; i < r.length; i++) {
1237
- const c = i;
1238
- Object.defineProperty(e, r[i], {
1248
+ const { field_names: i } = a.layout;
1249
+ for (let r = 0; r < i.length; r++) {
1250
+ const c = r;
1251
+ Object.defineProperty(e, i[r], {
1239
1252
  get() {
1240
1253
  return this._columns[c][this._row];
1241
1254
  },
@@ -1249,10 +1262,10 @@ function B(a, t) {
1249
1262
  W.set(a, e);
1250
1263
  }
1251
1264
  const s = Object.create(e), n = new Array(a.columns.length);
1252
- for (let r = 0; r < a.columns.length; r++) n[r] = a.columns[r].buf;
1265
+ for (let i = 0; i < a.columns.length; i++) n[i] = a.columns[i].buf;
1253
1266
  return s._columns = n, s._row = t, s;
1254
1267
  }
1255
- class St {
1268
+ class Dt {
1256
1269
  _archetypes;
1257
1270
  _defs;
1258
1271
  _resolver;
@@ -1261,8 +1274,18 @@ class St {
1261
1274
  _any_of;
1262
1275
  _non_empty_archetypes = [];
1263
1276
  _non_empty_dirty = !0;
1264
- constructor(t, e, s, n, r, i) {
1265
- this._archetypes = t, this._defs = e, this._resolver = s, this._include = n, this._exclude = r, this._any_of = i;
1277
+ // Per-Query composition caches single-component fast path.
1278
+ // The final Query produced by _resolve_query is already cached by the
1279
+ // resolver, but the caller pays a BitSet copy + defs slice per call
1280
+ // before the resolver can hash and hit that cache. These caches
1281
+ // short-circuit that allocation path for the common single-component
1282
+ // composition shape (q.and(X), q.changed(X), etc).
1283
+ _and_cache_single = null;
1284
+ _not_cache_single = null;
1285
+ _any_of_cache_single = null;
1286
+ _changed_cache_single = null;
1287
+ constructor(t, e, s, n, i, r) {
1288
+ this._archetypes = t, this._defs = e, this._resolver = s, this._include = n, this._exclude = i, this._any_of = r;
1266
1289
  }
1267
1290
  /** Number of matching archetypes (including empty ones). */
1268
1291
  get archetype_count() {
@@ -1280,6 +1303,17 @@ class St {
1280
1303
  }
1281
1304
  /** Extend required component set. Returns a new (cached) Query. */
1282
1305
  and(...t) {
1306
+ if (t.length === 1) {
1307
+ const n = t[0], i = this._and_cache_single;
1308
+ if (i !== null) {
1309
+ const _ = i.get(n);
1310
+ if (_ !== void 0) return _;
1311
+ }
1312
+ const r = this._include.copy(), c = this._defs.slice();
1313
+ r.has(n) || (r.set(n), c.push(t[0]));
1314
+ const o = this._resolver._resolve_query(r, this._exclude, this._any_of, c);
1315
+ return (this._and_cache_single ??= /* @__PURE__ */ new Map()).set(n, o), o;
1316
+ }
1283
1317
  const e = this._include.copy(), s = this._defs.slice();
1284
1318
  for (let n = 0; n < t.length; n++)
1285
1319
  e.has(t[n]) || (e.set(t[n]), s.push(t[n]));
@@ -1287,7 +1321,23 @@ class St {
1287
1321
  }
1288
1322
  /** Exclude archetypes that have any of these components. */
1289
1323
  not(...t) {
1290
- const e = this._exclude ? this._exclude.copy() : new k();
1324
+ if (t.length === 1) {
1325
+ const s = t[0], n = this._not_cache_single;
1326
+ if (n !== null) {
1327
+ const c = n.get(s);
1328
+ if (c !== void 0) return c;
1329
+ }
1330
+ const i = this._exclude ? this._exclude.copy() : new p();
1331
+ i.set(s);
1332
+ const r = this._resolver._resolve_query(
1333
+ this._include,
1334
+ i,
1335
+ this._any_of,
1336
+ this._defs
1337
+ );
1338
+ return (this._not_cache_single ??= /* @__PURE__ */ new Map()).set(s, r), r;
1339
+ }
1340
+ const e = this._exclude ? this._exclude.copy() : new p();
1291
1341
  for (let s = 0; s < t.length; s++) e.set(t[s]);
1292
1342
  return this._resolver._resolve_query(
1293
1343
  this._include,
@@ -1318,7 +1368,23 @@ class St {
1318
1368
  }
1319
1369
  /** Require at least one of these components. */
1320
1370
  any_of(...t) {
1321
- const e = this._any_of ? this._any_of.copy() : new k();
1371
+ if (t.length === 1) {
1372
+ const s = t[0], n = this._any_of_cache_single;
1373
+ if (n !== null) {
1374
+ const c = n.get(s);
1375
+ if (c !== void 0) return c;
1376
+ }
1377
+ const i = this._any_of ? this._any_of.copy() : new p();
1378
+ i.set(s);
1379
+ const r = this._resolver._resolve_query(
1380
+ this._include,
1381
+ this._exclude,
1382
+ i,
1383
+ this._defs
1384
+ );
1385
+ return (this._any_of_cache_single ??= /* @__PURE__ */ new Map()).set(s, r), r;
1386
+ }
1387
+ const e = this._any_of ? this._any_of.copy() : new p();
1322
1388
  for (let s = 0; s < t.length; s++) e.set(t[s]);
1323
1389
  return this._resolver._resolve_query(
1324
1390
  this._include,
@@ -1329,26 +1395,35 @@ class St {
1329
1395
  }
1330
1396
  /** Create a ChangedQuery that filters archetypes by change tick. */
1331
1397
  changed(...t) {
1398
+ if (t.length === 1) {
1399
+ const s = t[0], n = this._changed_cache_single;
1400
+ if (n !== null) {
1401
+ const r = n.get(s);
1402
+ if (r !== void 0) return r;
1403
+ }
1404
+ const i = new $(this, [s]);
1405
+ return (this._changed_cache_single ??= /* @__PURE__ */ new Map()).set(s, i), i;
1406
+ }
1332
1407
  const e = new Array(t.length);
1333
1408
  for (let s = 0; s < t.length; s++) e[s] = t[s];
1334
- return new Nt(this, e);
1409
+ return new $(this, e);
1335
1410
  }
1336
1411
  /** @internal — reads last_run_tick from the resolver (ECS). */
1337
1412
  _ctx_last_run_tick() {
1338
1413
  return this._resolver._get_last_run_tick();
1339
1414
  }
1340
1415
  }
1341
- class Dt {
1416
+ class Rt {
1342
1417
  constructor(t) {
1343
1418
  this._resolver = t;
1344
1419
  }
1345
1420
  every(...t) {
1346
- const e = new k();
1421
+ const e = new p();
1347
1422
  for (let s = 0; s < t.length; s++) e.set(t[s]);
1348
1423
  return this._resolver._resolve_query(e, null, null, t);
1349
1424
  }
1350
1425
  }
1351
- class Rt {
1426
+ class Nt {
1352
1427
  store;
1353
1428
  last_run_tick = 0;
1354
1429
  /** Current world tick. Use this for write ticks in get_column_mut. */
@@ -1362,12 +1437,12 @@ class Rt {
1362
1437
  return this.store.create_entity();
1363
1438
  }
1364
1439
  get_field(t, e, s) {
1365
- const n = this.store.get_entity_archetype(t), r = this.store.get_entity_row(t);
1366
- return n.read_field(r, e, s);
1440
+ const n = this.store.get_entity_archetype(t), i = this.store.get_entity_row(t);
1441
+ return n.read_field(i, e, s);
1367
1442
  }
1368
1443
  set_field(t, e, s, n) {
1369
- const r = this.store.get_entity_archetype(t), i = this.store.get_entity_row(t), c = r.get_column_mut(e, s, this.store._tick);
1370
- c[i] = n;
1444
+ const i = this.store.get_entity_archetype(t), r = this.store.get_entity_row(t), c = i.get_column_mut(e, s, this.store._tick);
1445
+ c[r] = n;
1371
1446
  }
1372
1447
  /** Create a cached read-only component reference for a single entity. See ref.ts. */
1373
1448
  ref(t, e) {
@@ -1384,7 +1459,7 @@ class Rt {
1384
1459
  return this.store.destroy_entity_deferred(t), this;
1385
1460
  }
1386
1461
  add_component(t, e, s) {
1387
- return this.store.add_component_deferred(t, e, s ?? U), this;
1462
+ return this.store.add_component_deferred(t, e, s ?? q), this;
1388
1463
  }
1389
1464
  remove_component(t, e) {
1390
1465
  return this.store.remove_component_deferred(t, e), this;
@@ -1414,7 +1489,7 @@ class Rt {
1414
1489
  return this.store.has_resource(t);
1415
1490
  }
1416
1491
  }
1417
- class Nt {
1492
+ class $ {
1418
1493
  _query;
1419
1494
  _changed_ids;
1420
1495
  constructor(t, e) {
@@ -1422,11 +1497,11 @@ class Nt {
1422
1497
  }
1423
1498
  for_each(t) {
1424
1499
  const e = this._query._ctx_last_run_tick(), s = this._query._non_empty(), n = this._changed_ids;
1425
- for (let r = 0; r < s.length; r++) {
1426
- const i = s[r];
1500
+ for (let i = 0; i < s.length; i++) {
1501
+ const r = s[i];
1427
1502
  for (let c = 0; c < n.length; c++)
1428
- if (i._changed_tick[n[c]] >= e) {
1429
- t(i);
1503
+ if (r._changed_tick[n[c]] >= e) {
1504
+ t(r);
1430
1505
  break;
1431
1506
  }
1432
1507
  }
@@ -1435,7 +1510,7 @@ class Nt {
1435
1510
  const Pt = (a) => F(
1436
1511
  a
1437
1512
  );
1438
- class qt {
1513
+ class Ut {
1439
1514
  store;
1440
1515
  schedule;
1441
1516
  ctx;
@@ -1451,9 +1526,9 @@ class qt {
1451
1526
  // Multiple queries can share the same hash (collision), so each bucket is an array.
1452
1527
  query_cache = /* @__PURE__ */ new Map();
1453
1528
  // Reusable BitSet for building query masks — avoids allocation per query() call
1454
- scratch_mask = new k();
1529
+ scratch_mask = new p();
1455
1530
  constructor(t) {
1456
- this.store = new At(t?.initial_capacity), this.schedule = new It(), this.ctx = new Rt(this.store), this._fixed_timestep = t?.fixed_timestep ?? gt, this._max_fixed_steps = t?.max_fixed_steps ?? yt;
1531
+ this.store = new xt(t?.initial_capacity), this.schedule = new St(), this.ctx = new Nt(this.store), this._fixed_timestep = t?.fixed_timestep ?? yt, this._max_fixed_steps = t?.max_fixed_steps ?? mt;
1457
1532
  }
1458
1533
  get fixed_timestep() {
1459
1534
  return this._fixed_timestep;
@@ -1468,7 +1543,7 @@ class qt {
1468
1543
  register_component(t, e) {
1469
1544
  if (Array.isArray(t)) {
1470
1545
  const s = e ?? "f64", n = /* @__PURE__ */ Object.create(null);
1471
- for (const r of t) n[r] = s;
1546
+ for (const i of t) n[i] = s;
1472
1547
  return this.store.register_component(n);
1473
1548
  }
1474
1549
  return this.store.register_component(t);
@@ -1507,7 +1582,7 @@ class qt {
1507
1582
  return this.store.entity_count;
1508
1583
  }
1509
1584
  add_component(t, e, s) {
1510
- return this.store.add_component(t, e, s ?? U), this;
1585
+ return this.store.add_component(t, e, s ?? q), this;
1511
1586
  }
1512
1587
  add_components(t, e) {
1513
1588
  this.store.add_components(t, e);
@@ -1532,12 +1607,12 @@ class qt {
1532
1607
  this.store.batch_remove_component(t, e);
1533
1608
  }
1534
1609
  get_field(t, e, s) {
1535
- const n = this.store.get_entity_archetype(t), r = this.store.get_entity_row(t);
1536
- return n.read_field(r, e, s);
1610
+ const n = this.store.get_entity_archetype(t), i = this.store.get_entity_row(t);
1611
+ return n.read_field(i, e, s);
1537
1612
  }
1538
1613
  set_field(t, e, s, n) {
1539
- const r = this.store.get_entity_archetype(t), i = this.store.get_entity_row(t), c = r.get_column_mut(e, s, this.store._tick);
1540
- c[i] = n;
1614
+ const i = this.store.get_entity_archetype(t), r = this.store.get_entity_row(t), c = i.get_column_mut(e, s, this.store._tick);
1615
+ c[r] = n;
1541
1616
  }
1542
1617
  emit(t, e) {
1543
1618
  const s = this.store.get_event_def_by_key(t);
@@ -1559,9 +1634,9 @@ class qt {
1559
1634
  }
1560
1635
  /** QueryResolver implementation — creates or retrieves a cached Query. */
1561
1636
  _resolve_query(t, e, s, n) {
1562
- const r = t.hash(), i = e ? e.hash() : 0, c = s ? s.hash() : 0, o = r ^ Math.imul(i, dt) ^ Math.imul(c, ut) | 0, _ = this._find_cached(o, t, e, s);
1637
+ const i = t.hash(), r = e ? e.hash() : 0, c = s ? s.hash() : 0, o = i ^ Math.imul(r, ut) ^ Math.imul(c, ft) | 0, _ = this._find_cached(o, t, e, s);
1563
1638
  if (_ !== void 0) return _.query;
1564
- const h = this.store.register_query(t, e ?? void 0, s ?? void 0), l = new St(
1639
+ const h = this.store.register_query(t, e ?? void 0, s ?? void 0), l = new Dt(
1565
1640
  h,
1566
1641
  n,
1567
1642
  this,
@@ -1569,7 +1644,7 @@ class qt {
1569
1644
  e?.copy() ?? null,
1570
1645
  s?.copy() ?? null
1571
1646
  );
1572
- return this.store.update_query_ref(h, l), K(this.query_cache, o, {
1647
+ return this.store.update_query_ref(h, l), Q(this.query_cache, o, {
1573
1648
  include_mask: t.copy(),
1574
1649
  exclude_mask: e?.copy() ?? null,
1575
1650
  any_of_mask: s?.copy() ?? null,
@@ -1577,10 +1652,10 @@ class qt {
1577
1652
  }), l;
1578
1653
  }
1579
1654
  _find_cached(t, e, s, n) {
1580
- const r = this.query_cache.get(t);
1581
- if (r)
1582
- for (let i = 0; i < r.length; i++) {
1583
- const c = r[i];
1655
+ const i = this.query_cache.get(t);
1656
+ if (i)
1657
+ for (let r = 0; r < i.length; r++) {
1658
+ const c = i[r];
1584
1659
  if (!(!c.include_mask.equals(e) || !(s === null ? c.exclude_mask === null : c.exclude_mask !== null && c.exclude_mask.equals(s)) || !(n === null ? c.any_of_mask === null : c.any_of_mask !== null && c.any_of_mask.equals(n))))
1585
1660
  return c;
1586
1661
  }
@@ -1590,14 +1665,14 @@ class qt {
1590
1665
  let s;
1591
1666
  if (typeof t == "function")
1592
1667
  if (e !== void 0) {
1593
- const i = e(new Dt(this)), c = this.ctx, o = t;
1594
- s = { fn: (_, h) => o(i, c, h) };
1668
+ const r = e(new Rt(this)), c = this.ctx, o = t;
1669
+ s = { fn: (_, h) => o(r, c, h) };
1595
1670
  } else
1596
1671
  s = { fn: t };
1597
1672
  else
1598
1673
  s = t;
1599
- const n = Pt(this.next_system_id++), r = Object.freeze(Object.assign({ id: n }, s));
1600
- return this.systems.add(r), r;
1674
+ const n = Pt(this.next_system_id++), i = Object.freeze(Object.assign({ id: n }, s));
1675
+ return this.systems.add(i), i;
1601
1676
  }
1602
1677
  add_systems(t, ...e) {
1603
1678
  return this.schedule.add_systems(t, ...e), this;
@@ -1635,13 +1710,13 @@ function Mt(a) {
1635
1710
  return Symbol(a);
1636
1711
  }
1637
1712
  export {
1638
- Nt as ChangedQuery,
1639
- qt as ECS,
1640
- St as Query,
1641
- Dt as QueryBuilder,
1642
- xt as SCHEDULE,
1643
- Rt as SystemContext,
1713
+ $ as ChangedQuery,
1714
+ Ut as ECS,
1715
+ Dt as Query,
1716
+ Rt as QueryBuilder,
1717
+ It as SCHEDULE,
1718
+ Nt as SystemContext,
1644
1719
  Ot as event_key,
1645
1720
  Mt as resource_key,
1646
- Ut as signal_key
1721
+ qt as signal_key
1647
1722
  };