@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/archetype.d.ts +7 -0
- package/dist/archetype.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +361 -286
- package/dist/query.d.ts +4 -0
- package/dist/query.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
class
|
|
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
|
|
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,
|
|
16
|
-
class
|
|
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(
|
|
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
|
|
37
|
-
if ((e[
|
|
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
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
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
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
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
|
|
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,
|
|
63
|
-
for (let
|
|
64
|
-
return
|
|
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
|
|
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 =
|
|
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,
|
|
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
|
|
86
|
+
const i = s << I;
|
|
87
87
|
for (; n !== 0; ) {
|
|
88
|
-
const
|
|
89
|
-
t(
|
|
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
|
|
182
|
+
class nt extends A {
|
|
183
183
|
constructor(t = b) {
|
|
184
184
|
super(Float32Array, t);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
class
|
|
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
|
|
197
|
+
class _t extends A {
|
|
198
198
|
constructor(t = b) {
|
|
199
199
|
super(Int16Array, t);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
class
|
|
202
|
+
class ot extends A {
|
|
203
203
|
constructor(t = b) {
|
|
204
204
|
super(Int32Array, t);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
class
|
|
207
|
+
class ct extends A {
|
|
208
208
|
constructor(t = b) {
|
|
209
209
|
super(Uint8Array, t);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
class
|
|
212
|
+
class ht extends A {
|
|
213
213
|
constructor(t = b) {
|
|
214
214
|
super(Uint16Array, t);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
class
|
|
217
|
+
class H extends A {
|
|
218
218
|
constructor(t = b) {
|
|
219
219
|
super(Uint32Array, t);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
const
|
|
223
|
-
f32:
|
|
224
|
-
f64:
|
|
222
|
+
const at = {
|
|
223
|
+
f32: nt,
|
|
224
|
+
f64: it,
|
|
225
225
|
i8: rt,
|
|
226
|
-
i16:
|
|
227
|
-
i32:
|
|
228
|
-
u8:
|
|
229
|
-
u16:
|
|
230
|
-
u32:
|
|
226
|
+
i16: _t,
|
|
227
|
+
i32: ot,
|
|
228
|
+
u8: ct,
|
|
229
|
+
u16: ht,
|
|
230
|
+
u32: H
|
|
231
231
|
};
|
|
232
|
-
class
|
|
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
|
|
265
|
-
if (s(n, e[
|
|
266
|
-
e[t] = e[
|
|
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,
|
|
273
|
-
for (; t <
|
|
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],
|
|
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] =
|
|
279
|
+
e[t] = r;
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
function
|
|
283
|
-
const n = s ?? ((o) => String(o)),
|
|
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
|
-
|
|
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
|
-
|
|
289
|
+
i.has(h) && i.set(h, i.get(h) + 1);
|
|
290
290
|
}
|
|
291
|
-
const
|
|
291
|
+
const r = new lt(e);
|
|
292
292
|
for (let o = 0; o < a.length; o++)
|
|
293
|
-
|
|
293
|
+
i.get(a[o]) === 0 && r.push(a[o]);
|
|
294
294
|
const c = [];
|
|
295
|
-
for (;
|
|
296
|
-
const o =
|
|
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 (!
|
|
303
|
-
const d =
|
|
304
|
-
|
|
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
|
|
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
|
|
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
|
-
),
|
|
319
|
+
), kt = (a) => F(
|
|
320
320
|
a
|
|
321
321
|
);
|
|
322
|
-
class
|
|
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
|
|
356
|
+
function qt(a) {
|
|
357
357
|
return Symbol(a);
|
|
358
358
|
}
|
|
359
|
-
const
|
|
359
|
+
const bt = (a) => F(
|
|
360
360
|
a
|
|
361
361
|
);
|
|
362
|
-
class
|
|
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 =
|
|
387
|
-
if (this.id = t, this.mask = e, this._entity_ids = new
|
|
388
|
-
let
|
|
389
|
-
for (let
|
|
390
|
-
const c = s[
|
|
391
|
-
this._col_offset[o] =
|
|
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
|
|
394
|
-
_[h] = l, this._flat_columns[
|
|
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
|
|
427
|
-
return this._flat_columns[this._col_offset[n] +
|
|
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
|
|
431
|
-
if (
|
|
432
|
-
this._changed_tick[
|
|
433
|
-
const c = this._field_names[
|
|
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[
|
|
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
|
|
440
|
-
if (
|
|
441
|
-
this._changed_tick[
|
|
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[
|
|
448
|
+
c[r + o].buf[t] = s[o];
|
|
445
449
|
}
|
|
446
450
|
read_field(t, e, s) {
|
|
447
|
-
const n = e,
|
|
448
|
-
if (
|
|
449
|
-
const
|
|
450
|
-
return
|
|
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
|
|
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 =
|
|
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 =
|
|
460
|
-
for (let
|
|
461
|
-
o[u +
|
|
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,
|
|
488
|
+
const n = this._flat_columns, i = this._entity_ids.buf;
|
|
485
489
|
if (t !== e) {
|
|
486
|
-
|
|
487
|
-
for (let
|
|
488
|
-
n[
|
|
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
|
|
491
|
-
n[
|
|
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,
|
|
513
|
-
const
|
|
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]] =
|
|
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] =
|
|
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
|
|
535
|
-
f[0] = n, f[1] =
|
|
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
|
|
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; _ <
|
|
551
|
+
for (let _ = 0; _ < r.length; _++) {
|
|
548
552
|
const h = e[_];
|
|
549
|
-
h >= 0 ?
|
|
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
|
|
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
|
|
568
|
-
const e = t._flat_columns, s = new Int16Array(e.length), n = t._column_ids,
|
|
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 =
|
|
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
|
|
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
|
|
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 ??
|
|
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 =
|
|
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 &&
|
|
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
|
|
659
|
-
this.archetypes.push(
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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 =
|
|
702
|
-
const
|
|
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
|
-
|
|
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 =
|
|
717
|
-
return this.entity_archetype[t] = this.empty_archetype_id, this.entity_row[t] =
|
|
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 !==
|
|
725
|
-
const
|
|
726
|
-
|
|
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] =
|
|
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,
|
|
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 &
|
|
757
|
-
if (_ >=
|
|
769
|
+
const o = t[c], _ = o & M, h = o >> R;
|
|
770
|
+
if (_ >= r || n[_] !== h) continue;
|
|
758
771
|
const l = s[_];
|
|
759
|
-
if (l !==
|
|
760
|
-
const d =
|
|
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[_] =
|
|
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 ??
|
|
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,
|
|
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 &
|
|
785
|
-
if (g >= h || c[g] !==
|
|
786
|
-
const T =
|
|
787
|
-
if (
|
|
788
|
-
_[
|
|
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,
|
|
792
|
-
let
|
|
793
|
-
if (P !==
|
|
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(
|
|
808
|
+
x.move_entity_from_tag(E, P, u);
|
|
796
809
|
else {
|
|
797
|
-
const
|
|
798
|
-
x.move_entity_from(
|
|
810
|
+
const J = E.get_edge(v);
|
|
811
|
+
x.move_entity_from(E, P, u, J.add_map, l);
|
|
799
812
|
}
|
|
800
|
-
|
|
813
|
+
U = f[0], f[1] !== m && (r[f[1]] = P);
|
|
801
814
|
} else
|
|
802
|
-
|
|
803
|
-
_[
|
|
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,
|
|
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 &
|
|
812
|
-
if (d >= o ||
|
|
813
|
-
const g = n[d],
|
|
814
|
-
if (!T.mask.has(
|
|
815
|
-
const
|
|
816
|
-
if (!
|
|
817
|
-
|
|
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(
|
|
820
|
-
|
|
832
|
+
const P = T.get_edge(w);
|
|
833
|
+
E.move_entity_from(T, N, l, P.remove_map, _);
|
|
821
834
|
}
|
|
822
|
-
f[1] !== m && (
|
|
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 =
|
|
834
|
-
for (let
|
|
835
|
-
|
|
836
|
-
return this.component_metas.push({ field_names: s, field_index:
|
|
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),
|
|
842
|
-
if (
|
|
843
|
-
|
|
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(
|
|
864
|
+
const c = this.arch_resolve_add(i, e), o = this.arch_get(c), _ = this.entity_row[n];
|
|
852
865
|
let h;
|
|
853
|
-
if (_ !==
|
|
854
|
-
const l =
|
|
855
|
-
!o.has_columns && !
|
|
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
|
|
871
|
-
for (let
|
|
872
|
-
|
|
873
|
-
if (
|
|
874
|
-
const
|
|
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 !==
|
|
877
|
-
const h =
|
|
878
|
-
c.move_entity_from(
|
|
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 ??
|
|
898
|
+
e[h].values ?? q,
|
|
886
899
|
this._tick
|
|
887
900
|
);
|
|
888
|
-
this.entity_archetype[s] =
|
|
901
|
+
this.entity_archetype[s] = i, this.entity_row[s] = _, this._mark_queries_dirty();
|
|
889
902
|
} else {
|
|
890
|
-
const
|
|
903
|
+
const r = this.arch_get(n), c = this.entity_row[s];
|
|
891
904
|
for (let o = 0; o < e.length; o++)
|
|
892
|
-
|
|
905
|
+
r.write_fields(
|
|
893
906
|
c,
|
|
894
907
|
e[o].def,
|
|
895
|
-
e[o].values ??
|
|
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],
|
|
904
|
-
if (!
|
|
905
|
-
const
|
|
906
|
-
!c.has_columns && !
|
|
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
|
|
926
|
+
let i = n;
|
|
914
927
|
for (let h = 0; h < e.length; h++)
|
|
915
|
-
|
|
916
|
-
|
|
928
|
+
i = this.arch_resolve_remove(
|
|
929
|
+
i,
|
|
917
930
|
e[h]
|
|
918
931
|
);
|
|
919
|
-
if (
|
|
920
|
-
const
|
|
921
|
-
c.move_entity_from(
|
|
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
|
|
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(
|
|
941
|
-
_[g] =
|
|
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
|
-
|
|
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),
|
|
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(
|
|
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
|
|
996
|
+
let i = !1;
|
|
984
997
|
for (let _ = 0; _ < n.length; _++)
|
|
985
998
|
if (n[_] !== 0) {
|
|
986
|
-
|
|
999
|
+
i = !0;
|
|
987
1000
|
break;
|
|
988
1001
|
}
|
|
989
|
-
if (!
|
|
1002
|
+
if (!i)
|
|
990
1003
|
return this.archetypes.filter(
|
|
991
1004
|
(_) => (!e || !_.mask.overlaps(e)) && (!s || _.mask.overlaps(s))
|
|
992
1005
|
);
|
|
993
|
-
let
|
|
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
|
-
(!
|
|
1019
|
+
(!r || g.size < r.size) && (r = g);
|
|
1007
1020
|
}
|
|
1008
1021
|
if (c) break;
|
|
1009
1022
|
}
|
|
1010
|
-
if (c || !
|
|
1023
|
+
if (c || !r) return [];
|
|
1011
1024
|
const o = [];
|
|
1012
|
-
for (const _ of
|
|
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 =
|
|
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
|
|
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
|
|
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,
|
|
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(
|
|
1139
|
-
after: new Set(
|
|
1151
|
+
before: new Set(i?.before ?? []),
|
|
1152
|
+
after: new Set(i?.after ?? [])
|
|
1140
1153
|
};
|
|
1141
|
-
this.label_systems.get(t).push(
|
|
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((
|
|
1160
|
+
const s = this.label_systems.get(e), n = s.findIndex((i) => i.descriptor === t);
|
|
1148
1161
|
if (n !== -1) {
|
|
1149
|
-
const
|
|
1150
|
-
n !==
|
|
1151
|
-
for (const
|
|
1152
|
-
|
|
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,
|
|
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
|
|
1190
|
-
for (let
|
|
1191
|
-
this.system_last_run.set(r
|
|
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(),
|
|
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),
|
|
1210
|
-
const
|
|
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
|
-
|
|
1225
|
+
r.set(_.descriptor, []);
|
|
1213
1226
|
for (const _ of t) {
|
|
1214
1227
|
for (const h of _.before)
|
|
1215
|
-
|
|
1228
|
+
i.has(h) && r.get(_.descriptor).push(h);
|
|
1216
1229
|
for (const h of _.after)
|
|
1217
|
-
|
|
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
|
|
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:
|
|
1236
|
-
for (let
|
|
1237
|
-
const c =
|
|
1238
|
-
Object.defineProperty(e, r
|
|
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
|
|
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
|
|
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
|
-
|
|
1265
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
1416
|
+
class Rt {
|
|
1342
1417
|
constructor(t) {
|
|
1343
1418
|
this._resolver = t;
|
|
1344
1419
|
}
|
|
1345
1420
|
every(...t) {
|
|
1346
|
-
const e = new
|
|
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
|
|
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),
|
|
1366
|
-
return n.read_field(
|
|
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
|
|
1370
|
-
c[
|
|
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 ??
|
|
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
|
|
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
|
|
1426
|
-
const
|
|
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 (
|
|
1429
|
-
t(
|
|
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
|
|
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
|
|
1529
|
+
scratch_mask = new p();
|
|
1455
1530
|
constructor(t) {
|
|
1456
|
-
this.store = new
|
|
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
|
|
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 ??
|
|
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),
|
|
1536
|
-
return n.read_field(
|
|
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
|
|
1540
|
-
c[
|
|
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
|
|
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
|
|
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),
|
|
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
|
|
1581
|
-
if (
|
|
1582
|
-
for (let
|
|
1583
|
-
const c = r
|
|
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
|
|
1594
|
-
s = { fn: (_, h) => o(
|
|
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++),
|
|
1600
|
-
return this.systems.add(
|
|
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
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
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
|
-
|
|
1721
|
+
qt as signal_key
|
|
1647
1722
|
};
|