@vworlds/vecs 1.0.10 → 1.0.12
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/.husky/pre-commit +1 -0
- package/README.md +299 -228
- package/dist/command.d.ts +1 -46
- package/dist/component.d.ts +51 -59
- package/dist/component.js +31 -25
- package/dist/component.js.map +1 -1
- package/dist/dsl.d.ts +34 -26
- package/dist/dsl.js +46 -20
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +96 -106
- package/dist/entity.js +261 -190
- package/dist/entity.js.map +1 -1
- package/dist/filter.d.ts +31 -23
- package/dist/filter.js +24 -17
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -1
- package/dist/phase.d.ts +12 -30
- package/dist/phase.js +11 -10
- package/dist/phase.js.map +1 -1
- package/dist/query.d.ts +107 -144
- package/dist/query.js +200 -169
- package/dist/query.js.map +1 -1
- package/dist/system.d.ts +170 -86
- package/dist/system.js +253 -114
- package/dist/system.js.map +1 -1
- package/dist/timer.d.ts +50 -0
- package/dist/timer.js +154 -0
- package/dist/timer.js.map +1 -0
- package/dist/util/array_map.d.ts +4 -55
- package/dist/util/array_map.js +35 -37
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.d.ts +40 -50
- package/dist/util/bitset.js +76 -62
- package/dist/util/bitset.js.map +1 -1
- package/dist/util/events.d.ts +14 -18
- package/dist/util/events.js +24 -3
- package/dist/util/events.js.map +1 -1
- package/dist/util/ordered_set.d.ts +1 -17
- package/dist/util/ordered_set.js +74 -25
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world.d.ts +230 -218
- package/dist/world.js +422 -327
- package/dist/world.js.map +1 -1
- package/eslint-rules/internal-underscore.js +60 -0
- package/eslint.config.js +5 -0
- package/package.json +3 -1
package/dist/query.js
CHANGED
|
@@ -1,89 +1,188 @@
|
|
|
1
1
|
import { OrderedSet } from "./util/ordered_set.js";
|
|
2
2
|
import { ArrayMap } from "./util/array_map.js";
|
|
3
3
|
import { Bitset } from "./util/bitset.js";
|
|
4
|
-
import {
|
|
4
|
+
import { _HAS, _buildEntityTest, } from "./dsl.js";
|
|
5
5
|
const EMPTY_ENTITIES = new Set();
|
|
6
6
|
/**
|
|
7
|
-
* A reactive, always-
|
|
8
|
-
*
|
|
7
|
+
* A reactive, always-up-to-date set of entities matching a {@link QueryDSL}
|
|
8
|
+
* predicate.
|
|
9
9
|
*
|
|
10
|
-
* `Query`
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* set is exposed via {@link entities} and {@link forEach}.
|
|
10
|
+
* `Query` listens to entity / component mutations through the world's command
|
|
11
|
+
* queue and tracks which entities currently satisfy its predicate. It fires
|
|
12
|
+
* `enter`, `exit`, and `update` callbacks as the matched set changes. The
|
|
13
|
+
* tracked set is exposed via {@link entities} and {@link forEach}.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Callbacks fire **synchronously** when the world routes a command — so
|
|
16
|
+
* mutations made inside one of these callbacks are themselves observed
|
|
17
|
+
* immediately by other queries / systems.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* {@link System} extends `Query` and queues callbacks into an inbox replayed
|
|
20
|
+
* during `_run` instead of firing them immediately. Use `Query` directly when
|
|
21
|
+
* you want a reactive entity set without pipeline integration.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam R - Component classes guaranteed present on every matched entity
|
|
24
|
+
* (declared via {@link requires} or the `_guaranteed` hint of {@link query}).
|
|
25
|
+
* Components in `R` appear as non-nullable in {@link sort}, {@link forEach},
|
|
26
|
+
* and {@link update} callback tuples.
|
|
23
27
|
*/
|
|
24
28
|
export class Query {
|
|
25
29
|
constructor(
|
|
26
|
-
/** Unique name
|
|
30
|
+
/** Unique display name; appears in logs and debug output. */
|
|
27
31
|
name,
|
|
28
|
-
/**
|
|
32
|
+
/** World that owns this query. */
|
|
29
33
|
world, track = true) {
|
|
30
34
|
this.name = name;
|
|
31
35
|
this.world = world;
|
|
36
|
+
/** @internal Predicate compiled from the query DSL; defaults to "match nothing". */
|
|
37
|
+
this._belongs = (_e) => false;
|
|
38
|
+
/** @internal `true` once {@link query} or {@link requires} has set an explicit predicate. */
|
|
39
|
+
this._hasQuery = false;
|
|
40
|
+
/** @internal `enter` callback (already wraps any injection logic). */
|
|
32
41
|
this._enterCallback = undefined;
|
|
42
|
+
/** @internal `exit` callback (already wraps any injection logic). */
|
|
33
43
|
this._exitCallback = undefined;
|
|
34
|
-
/** @internal
|
|
44
|
+
/** @internal Type ids the exit callback needs snapshotted before component removal. */
|
|
35
45
|
this._exitSnapshotTypes = undefined;
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
/** @internal
|
|
39
|
-
this.
|
|
40
|
-
/** @internal Bitmask of component types this query is watching for updates. */
|
|
41
|
-
this.watchlistBitmask = new Bitset();
|
|
46
|
+
/** @internal Per-component-type `update` callbacks. */
|
|
47
|
+
this._componentUpdateCallbacks = new ArrayMap();
|
|
48
|
+
/** @internal Bitmask of component types this query reacts to via `update`. */
|
|
49
|
+
this._watchlistBitmask = new Bitset();
|
|
42
50
|
world._addQuery(this);
|
|
43
51
|
if (track) {
|
|
44
52
|
this.track();
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
|
-
/** Returns the query name. */
|
|
48
|
-
toString() {
|
|
49
|
-
return this.name;
|
|
50
|
-
}
|
|
51
55
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* Idempotent. When called after {@link World.start}, immediately backfills all
|
|
56
|
-
* existing entities that currently satisfy the query predicate.
|
|
57
|
-
*
|
|
58
|
-
* @returns `this` for chaining.
|
|
56
|
+
* @internal Backfill the tracked set with every existing entity that
|
|
57
|
+
* satisfies the current predicate. Runs inside a deferred scope so the
|
|
58
|
+
* caller's reentrant routing remains consistent.
|
|
59
59
|
*/
|
|
60
|
-
|
|
61
|
-
this._entities ?? (this._entities = new Set());
|
|
62
|
-
this.backfill();
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
backfill() {
|
|
60
|
+
_backfill() {
|
|
66
61
|
if (this._entities === undefined) {
|
|
67
62
|
return;
|
|
68
63
|
}
|
|
69
64
|
this.world.defer(() => {
|
|
70
65
|
this.world.entities.forEach((e) => {
|
|
71
|
-
if (this.belongs(e) && !e.
|
|
66
|
+
if (this.belongs(e) && !e._isInQuery(this)) {
|
|
72
67
|
this._enter(e);
|
|
73
68
|
}
|
|
74
69
|
});
|
|
75
70
|
});
|
|
76
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* @internal Resolve one element of an `inject` tuple to a component
|
|
74
|
+
* instance, falling back to `exitSnapshot` when the entity is mid-exit.
|
|
75
|
+
*/
|
|
76
|
+
_getComponent(e, C, exitSnapshot) {
|
|
77
|
+
if (typeof C === "number") {
|
|
78
|
+
return exitSnapshot?.get(C) ?? e.get(C);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return e.parent?.get(C.parent);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @internal Resolve every element of an `inject` tuple, throwing if any
|
|
86
|
+
* required component is missing on the entity (or its parent).
|
|
87
|
+
*/
|
|
88
|
+
_getInjected(e, inject, exitSnapshot) {
|
|
89
|
+
const injected = [];
|
|
90
|
+
inject.forEach((C) => {
|
|
91
|
+
const c = this._getComponent(e, C, exitSnapshot);
|
|
92
|
+
if (!c) {
|
|
93
|
+
throw "query does not contain component";
|
|
94
|
+
}
|
|
95
|
+
injected.push(c);
|
|
96
|
+
});
|
|
97
|
+
return injected;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @internal Translate a tuple of component classes (or `{ parent: C }`
|
|
101
|
+
* markers) into the corresponding type ids understood by {@link _getInjected}.
|
|
102
|
+
*/
|
|
103
|
+
_mapInjectedClassToTypes(inject) {
|
|
104
|
+
return inject.map((C) => {
|
|
105
|
+
if (typeof C === "function") {
|
|
106
|
+
return this.world.getComponentType(C);
|
|
107
|
+
}
|
|
108
|
+
return { parent: this.world.getComponentType(C.parent) };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @internal Add `e` to the tracked set, register query membership on the
|
|
113
|
+
* entity, fire any registered `enter` callback, then bridge the entity's
|
|
114
|
+
* already-attached watched components through {@link _notifyModified} so
|
|
115
|
+
* `update` callbacks see them once on entry.
|
|
116
|
+
*
|
|
117
|
+
* `System` overrides this to push events into its inbox.
|
|
118
|
+
*/
|
|
119
|
+
_enter(e) {
|
|
120
|
+
this._entities?.add(e);
|
|
121
|
+
e._addQueryMembership(this);
|
|
122
|
+
this._enterCallback?.(e);
|
|
123
|
+
e.components.forEach((c) => {
|
|
124
|
+
if (this._watchlistBitmask.hasBit(c.bitPtr)) {
|
|
125
|
+
this._notifyModified(c);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @internal Remove `e` from the tracked set, deregister query membership,
|
|
131
|
+
* and fire any registered `exit` callback. `System` overrides this to push
|
|
132
|
+
* an inbox event.
|
|
133
|
+
*/
|
|
134
|
+
_exit(e) {
|
|
135
|
+
this._exitCallback?.(e);
|
|
136
|
+
this._entities?.delete(e);
|
|
137
|
+
e._removeQueryMembership(this);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @internal Routing entry: when the watchlist matches, invoke the registered
|
|
141
|
+
* `update` callback for the component type. `System` overrides this to push
|
|
142
|
+
* an inbox event instead of firing immediately.
|
|
143
|
+
*/
|
|
144
|
+
_notifyModified(c) {
|
|
145
|
+
if (!this._watchlistBitmask.hasBit(c.bitPtr)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const callback = this._componentUpdateCallbacks.get(c.type);
|
|
149
|
+
if (callback) {
|
|
150
|
+
callback(c);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
77
153
|
/**
|
|
78
154
|
* Read-only view of the entities currently tracked by this query.
|
|
79
155
|
*
|
|
80
|
-
* Populated as entities enter
|
|
81
|
-
* tracking is enabled
|
|
82
|
-
* {@link
|
|
156
|
+
* Populated as entities enter and removed as they exit. Empty unless
|
|
157
|
+
* tracking is enabled — that is the default for standalone queries created
|
|
158
|
+
* via {@link World.query}, but {@link System} requires an explicit
|
|
159
|
+
* {@link track}, {@link sort}, or `each` call.
|
|
83
160
|
*/
|
|
84
161
|
get entities() {
|
|
85
162
|
return this._entities ?? EMPTY_ENTITIES;
|
|
86
163
|
}
|
|
164
|
+
/** Returns the query name. */
|
|
165
|
+
toString() {
|
|
166
|
+
return this.name;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Enable entity tracking: matched entities are inserted into {@link entities}
|
|
170
|
+
* as they enter and removed as they exit.
|
|
171
|
+
*
|
|
172
|
+
* Idempotent. When called after {@link World.start}, immediately backfills
|
|
173
|
+
* every existing entity that satisfies the current predicate.
|
|
174
|
+
*
|
|
175
|
+
* @returns This query, for chaining.
|
|
176
|
+
*/
|
|
177
|
+
track() {
|
|
178
|
+
this._entities ?? (this._entities = new Set());
|
|
179
|
+
this._backfill();
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
/** Returns `true` when `e` satisfies this query's predicate. */
|
|
183
|
+
belongs(e) {
|
|
184
|
+
return this._belongs(e);
|
|
185
|
+
}
|
|
87
186
|
forEach(componentsOrCallback, callback) {
|
|
88
187
|
this.world.beginDefer();
|
|
89
188
|
try {
|
|
@@ -105,63 +204,14 @@ export class Query {
|
|
|
105
204
|
this.world.endDefer();
|
|
106
205
|
}
|
|
107
206
|
}
|
|
108
|
-
/** Returns `true` if the entity satisfies this query's predicate. */
|
|
109
|
-
belongs(e) {
|
|
110
|
-
return this._belongs(e);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* @internal Called by the world during command-queue routing when a Set
|
|
114
|
-
* command targets an entity that this query currently tracks. Default:
|
|
115
|
-
* fires the user-registered `update` callback for the component's type.
|
|
116
|
-
* `System` overrides this to push into its inbox instead.
|
|
117
|
-
*/
|
|
118
|
-
notifyModified(c) {
|
|
119
|
-
if (!this.watchlistBitmask.hasBit(c.bitPtr)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const callback = this.componentUpdateCallbacks.get(c.type);
|
|
123
|
-
if (callback) {
|
|
124
|
-
callback(c);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @internal Adds the entity to the tracked set, registers query membership
|
|
129
|
-
* on the entity, fires registered enter callbacks, then bridges any
|
|
130
|
-
* already-attached watched components through `notifyModified` so that
|
|
131
|
-
* `update` callbacks see the entity once on entry. `System` overrides this
|
|
132
|
-
* to push inbox events (events fire later in `_run`).
|
|
133
|
-
*/
|
|
134
|
-
_enter(e) {
|
|
135
|
-
this._entities?.add(e);
|
|
136
|
-
e._addQueryMembership(this);
|
|
137
|
-
this._enterCallback?.(e);
|
|
138
|
-
// Bridge: surface the entity's already-attached watched components as
|
|
139
|
-
// update events so `update` handlers fire once on entry without the user
|
|
140
|
-
// having to call `modified()` explicitly.
|
|
141
|
-
e.forEachComponent((c) => {
|
|
142
|
-
if (this.watchlistBitmask.hasBit(c.bitPtr)) {
|
|
143
|
-
this.notifyModified(c);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @internal Removes the entity from the tracked set, deregisters query
|
|
149
|
-
* membership, and fires registered exit callbacks. `System` overrides this
|
|
150
|
-
* to also push an inbox event.
|
|
151
|
-
*/
|
|
152
|
-
_exit(e) {
|
|
153
|
-
this._exitCallback?.(e);
|
|
154
|
-
this._entities?.delete(e);
|
|
155
|
-
e._removeQueryMembership(this);
|
|
156
|
-
}
|
|
157
207
|
enter(injectOrCallback, callback) {
|
|
158
208
|
if (typeof injectOrCallback === "function") {
|
|
159
209
|
this._enterCallback = injectOrCallback;
|
|
160
210
|
}
|
|
161
211
|
else {
|
|
162
|
-
const inject = this.
|
|
212
|
+
const inject = this._mapInjectedClassToTypes(injectOrCallback);
|
|
163
213
|
this._enterCallback = (e) => {
|
|
164
|
-
callback(e, this.
|
|
214
|
+
callback(e, this._getInjected(e, inject));
|
|
165
215
|
};
|
|
166
216
|
}
|
|
167
217
|
return this;
|
|
@@ -172,12 +222,10 @@ export class Query {
|
|
|
172
222
|
this._exitSnapshotTypes = undefined;
|
|
173
223
|
}
|
|
174
224
|
else {
|
|
175
|
-
const inject = this.
|
|
176
|
-
// Only direct (non-parent) types need snapshotting; parent refs are read
|
|
177
|
-
// from e.parent at callback time, which is still alive.
|
|
225
|
+
const inject = this._mapInjectedClassToTypes(injectOrCallback);
|
|
178
226
|
this._exitSnapshotTypes = inject.filter((t) => typeof t === "number");
|
|
179
227
|
this._exitCallback = (e, exitSnapshot) => {
|
|
180
|
-
callback(e, this.
|
|
228
|
+
callback(e, this._getInjected(e, inject, exitSnapshot));
|
|
181
229
|
};
|
|
182
230
|
}
|
|
183
231
|
return this;
|
|
@@ -186,7 +234,7 @@ export class Query {
|
|
|
186
234
|
const type = this.world.getComponentType(ComponentClass);
|
|
187
235
|
if (typeof injectOrCallback === "function") {
|
|
188
236
|
callback = injectOrCallback;
|
|
189
|
-
this.
|
|
237
|
+
this._componentUpdateCallbacks.set(type, callback);
|
|
190
238
|
}
|
|
191
239
|
else {
|
|
192
240
|
const inject = injectOrCallback;
|
|
@@ -200,25 +248,30 @@ export class Query {
|
|
|
200
248
|
callback(c, injected);
|
|
201
249
|
}
|
|
202
250
|
};
|
|
203
|
-
this.
|
|
251
|
+
this._componentUpdateCallbacks.set(type, cb);
|
|
204
252
|
}
|
|
205
|
-
this.
|
|
206
|
-
if (!this.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
253
|
+
this._watchlistBitmask.add(type);
|
|
254
|
+
if (!this._hasQuery) {
|
|
255
|
+
// Update-only queries derive membership from the watched component set.
|
|
256
|
+
// Install that predicate before backfill so the default match-nothing
|
|
257
|
+
// predicate is never used for update-watchlist expansion.
|
|
258
|
+
const watchlist = this._watchlistBitmask.indices();
|
|
259
|
+
this._belongs = _HAS(this.world, ...watchlist);
|
|
260
|
+
this._backfill();
|
|
210
261
|
}
|
|
211
262
|
return this;
|
|
212
263
|
}
|
|
213
264
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* component instances for each pair
|
|
265
|
+
* Switch the tracked set to a sorted ordering: matched entities are stored
|
|
266
|
+
* in the position determined by `compare`, which receives a tuple of
|
|
267
|
+
* resolved component instances for each pair being ordered.
|
|
268
|
+
*
|
|
269
|
+
* Implies {@link track}.
|
|
217
270
|
*
|
|
218
271
|
* @param components - Component classes to resolve and pass to `compare`.
|
|
219
|
-
* @param compare -
|
|
220
|
-
* `a` should sort
|
|
221
|
-
* @returns
|
|
272
|
+
* @param compare - Negative when `a` should sort before `b`, zero for
|
|
273
|
+
* equality, positive when `a` should sort after `b`.
|
|
274
|
+
* @returns This query, for chaining.
|
|
222
275
|
*
|
|
223
276
|
* @example
|
|
224
277
|
* ```ts
|
|
@@ -230,21 +283,22 @@ export class Query {
|
|
|
230
283
|
sort(components, compare) {
|
|
231
284
|
const types = components.map((C) => this.world.getComponentType(C));
|
|
232
285
|
this._entities = new OrderedSet((a, b) => compare(types.map((t) => a.get(t)), types.map((t) => b.get(t))));
|
|
233
|
-
this.
|
|
286
|
+
this._backfill();
|
|
234
287
|
return this;
|
|
235
288
|
}
|
|
236
289
|
/**
|
|
237
|
-
* Set the entity
|
|
290
|
+
* Set the entity-membership predicate using a {@link QueryDSL} expression.
|
|
238
291
|
*
|
|
239
|
-
* Replaces any previous predicate. The optional `
|
|
240
|
-
* pure type-level hint: it tells {@link sort}
|
|
241
|
-
*
|
|
242
|
-
* those positions. It has no
|
|
292
|
+
* Replaces any previous predicate. The optional `_guaranteed` tuple is a
|
|
293
|
+
* pure type-level hint: it tells {@link sort} / {@link forEach} /
|
|
294
|
+
* {@link update} callbacks which components are guaranteed present on every
|
|
295
|
+
* matched entity, eliminating `| undefined` from those positions. It has no
|
|
296
|
+
* effect at runtime.
|
|
243
297
|
*
|
|
244
|
-
* @param q -
|
|
298
|
+
* @param q - Query expression.
|
|
245
299
|
* @param _guaranteed - Component classes guaranteed present on every matched
|
|
246
300
|
* entity (type hint only — not validated at runtime).
|
|
247
|
-
* @returns
|
|
301
|
+
* @returns This query, retyped with the guaranteed tuple as its `R`.
|
|
248
302
|
*
|
|
249
303
|
* @example
|
|
250
304
|
* ```ts
|
|
@@ -256,66 +310,43 @@ export class Query {
|
|
|
256
310
|
* ```
|
|
257
311
|
*/
|
|
258
312
|
query(q, _guaranteed) {
|
|
259
|
-
this._belongs =
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
313
|
+
this._belongs = _buildEntityTest(this.world, q);
|
|
314
|
+
this._hasQuery = true;
|
|
315
|
+
this._backfill();
|
|
262
316
|
return this;
|
|
263
317
|
}
|
|
264
318
|
/**
|
|
265
|
-
*
|
|
319
|
+
* Shorthand for `query([...components])`: track entities that have **all**
|
|
320
|
+
* of the listed component types.
|
|
266
321
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
322
|
+
* Equivalent to `query({ HAS: components })`. Unlike `query`, the listed
|
|
323
|
+
* components are also recorded in the type parameter `R`, so {@link sort}
|
|
324
|
+
* and {@link forEach} callbacks see them as non-nullable.
|
|
270
325
|
*
|
|
271
|
-
*
|
|
326
|
+
* @param components - Component classes to require.
|
|
327
|
+
* @returns This query, retyped with the required tuple as its `R`.
|
|
272
328
|
*/
|
|
273
|
-
|
|
274
|
-
this.
|
|
275
|
-
this
|
|
276
|
-
this.world = undefined;
|
|
329
|
+
requires(...components) {
|
|
330
|
+
this.query(components);
|
|
331
|
+
return this;
|
|
277
332
|
}
|
|
278
333
|
/**
|
|
279
|
-
*
|
|
280
|
-
* **all** of the listed component types.
|
|
334
|
+
* Permanently remove this query from the world.
|
|
281
335
|
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
336
|
+
* Every entity that currently belongs to this query has the membership
|
|
337
|
+
* silently purged (no `exit` callbacks fire), the tracked set is cleared,
|
|
338
|
+
* and the `world` reference is forced to `undefined`. Calling any method on
|
|
339
|
+
* the query afterwards is **undefined behavior**.
|
|
285
340
|
*
|
|
286
|
-
* @
|
|
287
|
-
* @returns `this` for chaining.
|
|
341
|
+
* Not supported on {@link System} — calling it on a system throws.
|
|
288
342
|
*/
|
|
289
|
-
|
|
290
|
-
this.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
return e.parent?.get(C.parent);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
getInjected(e, inject, exitSnapshot) {
|
|
302
|
-
const injected = [];
|
|
303
|
-
inject.forEach((C) => {
|
|
304
|
-
const c = this.getComponent(e, C, exitSnapshot);
|
|
305
|
-
if (!c) {
|
|
306
|
-
throw "query does not contain component";
|
|
307
|
-
}
|
|
308
|
-
injected.push(c);
|
|
309
|
-
});
|
|
310
|
-
return injected;
|
|
311
|
-
}
|
|
312
|
-
mapInjectedClassToTypes(inject) {
|
|
313
|
-
return inject.map((C) => {
|
|
314
|
-
if (typeof C === "function") {
|
|
315
|
-
return this.world.getComponentType(C);
|
|
316
|
-
}
|
|
317
|
-
return { parent: this.world.getComponentType(C.parent) };
|
|
318
|
-
});
|
|
343
|
+
destroy() {
|
|
344
|
+
this.world._removeQuery(this);
|
|
345
|
+
this._entities?.forEach((e) => e._purgeQuery(this));
|
|
346
|
+
this._entities?.clear();
|
|
347
|
+
this._entities = undefined;
|
|
348
|
+
this._belongs = (_e) => false;
|
|
349
|
+
this.world = undefined;
|
|
319
350
|
}
|
|
320
351
|
}
|
|
321
352
|
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C,OAAO,EACL,IAAI,EACJ,gBAAgB,GAIjB,MAAM,UAAU,CAAC;AAoBlB,MAAM,cAAc,GAAwB,IAAI,GAAG,EAAE,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,KAAK;IAoBhB;IACE,6DAA6D;IAC7C,IAAY;IAC5B,kCAAkC;IAClB,KAAY,EAC5B,QAAiB,IAAI;QAHL,SAAI,GAAJ,IAAI,CAAQ;QAEZ,UAAK,GAAL,KAAK,CAAO;QArB9B,oFAAoF;QAC1E,aAAQ,GAAmB,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAC;QAC3D,6FAA6F;QACnF,cAAS,GAAY,KAAK,CAAC;QAErC,sEAAsE;QAC5D,mBAAc,GAA+B,SAAS,CAAC;QACjE,qEAAqE;QAC3D,kBAAa,GAA+B,SAAS,CAAC;QAChE,uFAAuF;QAC7E,uBAAkB,GAAyB,SAAS,CAAC;QAE/D,uDAAuD;QAC7C,8BAAyB,GAAG,IAAI,QAAQ,EAAqB,CAAC;QACxE,8EAA8E;QACpE,sBAAiB,GAAW,IAAI,MAAM,EA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