@vworlds/vecs 1.0.11 → 1.0.13
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 +169 -72
- package/dist/component.d.ts +22 -70
- package/dist/component.js +4 -59
- package/dist/component.js.map +1 -1
- package/dist/dsl.d.ts +9 -5
- package/dist/dsl.js +6 -3
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +10 -11
- package/dist/entity.js +55 -51
- package/dist/entity.js.map +1 -1
- package/dist/filter.d.ts +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/phase.d.ts +7 -2
- package/dist/phase.js.map +1 -1
- package/dist/query.d.ts +21 -21
- package/dist/query.js +17 -16
- package/dist/query.js.map +1 -1
- package/dist/system.d.ts +120 -8
- package/dist/system.js +152 -12
- 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.js +11 -7
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.d.ts +17 -3
- package/dist/util/bitset.js +47 -30
- package/dist/util/bitset.js.map +1 -1
- package/dist/world.d.ts +48 -17
- package/dist/world.js +91 -25
- package/dist/world.js.map +1 -1
- package/package.json +1 -1
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAoElD;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IAwBxB,YAAY,KAA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|
+
import { type ComponentClass, ComponentClassArray, ComponentClassOrType } from "./component.js";
|
|
2
2
|
import type { Entity } from "./entity.js";
|
|
3
3
|
/**
|
|
4
4
|
* A predicate that decides whether a given entity belongs to a query.
|
|
@@ -26,9 +26,13 @@ export type EntityTestFunc = (e: Entity) => boolean;
|
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
28
|
* Short forms recognized by `query` / `filter`:
|
|
29
|
-
* - A
|
|
29
|
+
* - A registered component class or numeric type id is shorthand for `{ HAS: [C] }`.
|
|
30
30
|
* - An array `[A, B]` is shorthand for `{ HAS: [A, B] }`.
|
|
31
31
|
* - An {@link EntityTestFunc} is invoked directly for fully custom logic.
|
|
32
|
+
*
|
|
33
|
+
* Function values are treated as component classes only when the world already
|
|
34
|
+
* has registered metadata for that class. Register component classes before
|
|
35
|
+
* using them in query DSL expressions.
|
|
32
36
|
*/
|
|
33
37
|
export type QueryDSL = ComponentClassArray | ComponentClassOrType | EntityTestFunc | {
|
|
34
38
|
HAS: ComponentClassArray | ComponentClassOrType;
|
|
@@ -53,13 +57,13 @@ export type QueryDSL = ComponentClassArray | ComponentClassOrType | EntityTestFu
|
|
|
53
57
|
* @typeParam C - Component class being injected.
|
|
54
58
|
* @typeParam R - Tuple of component classes guaranteed present.
|
|
55
59
|
*/
|
|
56
|
-
export type MaybeRequired<C, R extends
|
|
60
|
+
export type MaybeRequired<C, R extends ComponentClass[]> = C extends ComponentClass ? C extends R[number] ? InstanceType<C> : InstanceType<C> | undefined : never;
|
|
57
61
|
/**
|
|
58
62
|
* Statically extract the component classes that are **guaranteed present** on
|
|
59
63
|
* every entity matched by a {@link QueryDSL} expression.
|
|
60
64
|
*
|
|
61
65
|
* Rules:
|
|
62
|
-
* - Plain class `C` → `[C]`
|
|
66
|
+
* - Plain component class `C` → `[C]`
|
|
63
67
|
* - Plain array `[A, B]` → `[A, B]`
|
|
64
68
|
* - `{ HAS: ... }` / `{ HAS_ONLY: ... }` → recurse into the payload
|
|
65
69
|
* - `{ AND: [q1, q2, ...] }` → concatenate each branch's extraction
|
|
@@ -68,7 +72,7 @@ export type MaybeRequired<C, R extends (typeof Component)[]> = C extends typeof
|
|
|
68
72
|
*
|
|
69
73
|
* @typeParam Q - Query expression to analyse.
|
|
70
74
|
*/
|
|
71
|
-
export type ExtractRequired<Q> = Q extends
|
|
75
|
+
export type ExtractRequired<Q> = Q extends ComponentClass ? [Q] : Q extends readonly ComponentClass[] ? Q : Q extends {
|
|
72
76
|
HAS: infer H;
|
|
73
77
|
} ? ExtractRequired<H> : Q extends {
|
|
74
78
|
HAS_ONLY: infer H;
|
package/dist/dsl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _calculateComponentBitmask, } from "./component.js";
|
|
2
2
|
/**
|
|
3
3
|
* Build a predicate that returns `true` when an entity has every component
|
|
4
4
|
* type in `components` set on its archetype.
|
|
@@ -43,11 +43,14 @@ function _PARENT(func) {
|
|
|
43
43
|
* @internal Used by `Query`, `System`, and `Filter` to translate user-supplied
|
|
44
44
|
* DSL expressions into the predicate stored on `Query._belongs`.
|
|
45
45
|
*
|
|
46
|
-
* @param world - World used to resolve component classes to type ids.
|
|
46
|
+
* @param world - World used to resolve registered component classes to type ids.
|
|
47
47
|
* @param q - Query expression.
|
|
48
48
|
*/
|
|
49
49
|
export function _buildEntityTest(world, q) {
|
|
50
|
-
if (typeof q === "number"
|
|
50
|
+
if (typeof q === "number") {
|
|
51
|
+
return _HAS(world, q);
|
|
52
|
+
}
|
|
53
|
+
if (typeof q === "function" && world._tryGetComponentMeta(q)) {
|
|
51
54
|
return _HAS(world, q);
|
|
52
55
|
}
|
|
53
56
|
else if (typeof q === "function") {
|
package/dist/dsl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dsl.js","sourceRoot":"","sources":["../src/dsl.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"dsl.js","sourceRoot":"","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AE,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;KAC9D;IAED,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;KAC7C;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE;QACjB,OAAO,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KACnD;IAED,MAAM,yBAAyB,CAAC;AAClC,CAAC"}
|
package/dist/entity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from "./component.js";
|
|
1
|
+
import { type Component, type ComponentClass, type ComponentClassOrType } from "./component.js";
|
|
2
2
|
import type { World } from "./world.js";
|
|
3
3
|
import { ReadonlyArrayMap } from "./util/array_map.js";
|
|
4
4
|
import { Events } from "./util/events.js";
|
|
@@ -107,17 +107,16 @@ export declare class Entity {
|
|
|
107
107
|
*/
|
|
108
108
|
setParent(newParent: Entity | undefined): void;
|
|
109
109
|
/**
|
|
110
|
-
* Mark
|
|
110
|
+
* Mark a component type as having changed, queueing the corresponding `onSet` / `update`
|
|
111
111
|
* notifications.
|
|
112
112
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* component's dirty flag.
|
|
113
|
+
* Repeated calls before the world routes the modified command are coalesced via
|
|
114
|
+
* the entity's dirty component bitset.
|
|
116
115
|
*
|
|
117
|
-
* @param
|
|
116
|
+
* @param typeOrClass - Component class or numeric type id whose data changed.
|
|
118
117
|
* @returns This entity, for chaining.
|
|
119
118
|
*/
|
|
120
|
-
modified
|
|
119
|
+
modified(typeOrClass: ComponentClassOrType): Entity;
|
|
121
120
|
/**
|
|
122
121
|
* Attach a component to this entity if it is not already present.
|
|
123
122
|
*
|
|
@@ -127,7 +126,7 @@ export declare class Entity {
|
|
|
127
126
|
* @param Class - Component class to instantiate.
|
|
128
127
|
* @returns This entity, for chaining.
|
|
129
128
|
*/
|
|
130
|
-
add<C extends
|
|
129
|
+
add<C extends ComponentClass>(Class: C): Entity;
|
|
131
130
|
/**
|
|
132
131
|
* Attach a component by numeric type id.
|
|
133
132
|
*
|
|
@@ -147,7 +146,7 @@ export declare class Entity {
|
|
|
147
146
|
* @param props - Properties to assign onto the component instance.
|
|
148
147
|
* @returns This entity, for chaining.
|
|
149
148
|
*/
|
|
150
|
-
set<C extends
|
|
149
|
+
set<C extends ComponentClass>(Class: C, props: Partial<InstanceType<C>>): Entity;
|
|
151
150
|
/**
|
|
152
151
|
* Attach a component by numeric type id and copy `props` onto it.
|
|
153
152
|
*
|
|
@@ -165,7 +164,7 @@ export declare class Entity {
|
|
|
165
164
|
*
|
|
166
165
|
* @param Class - Component class to detach.
|
|
167
166
|
*/
|
|
168
|
-
remove<C extends
|
|
167
|
+
remove<C extends ComponentClass>(Class: C): void;
|
|
169
168
|
/**
|
|
170
169
|
* Detach a component by numeric type id.
|
|
171
170
|
*
|
|
@@ -178,7 +177,7 @@ export declare class Entity {
|
|
|
178
177
|
* @param typeOrClass - Component class or numeric type id.
|
|
179
178
|
* @returns The component instance, or `undefined` when it is not attached.
|
|
180
179
|
*/
|
|
181
|
-
get<C extends
|
|
180
|
+
get<C extends ComponentClass>(typeOrClass: number | C): InstanceType<C> | undefined;
|
|
182
181
|
/**
|
|
183
182
|
* Destroy this entity and recursively destroy its children.
|
|
184
183
|
*
|
package/dist/entity.js
CHANGED
|
@@ -42,6 +42,8 @@ export class Entity {
|
|
|
42
42
|
this.eid = eid;
|
|
43
43
|
/** @internal Maps numeric component type id to component instance. */
|
|
44
44
|
this._components = new ArrayMap();
|
|
45
|
+
/** @internal Component types with pending modified delivery. */
|
|
46
|
+
this._dirtyComponentBitmask = new Bitset();
|
|
45
47
|
/** @internal Set of queries this entity currently belongs to. */
|
|
46
48
|
this._queries = new Set();
|
|
47
49
|
/**
|
|
@@ -77,23 +79,22 @@ export class Entity {
|
|
|
77
79
|
* If the component type belongs to an exclusivity group, any conflicting
|
|
78
80
|
* component already on this entity is removed first.
|
|
79
81
|
*/
|
|
80
|
-
_new(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this._remove(exclusiveType);
|
|
82
|
+
_new(meta, props) {
|
|
83
|
+
if (meta._exclusive) {
|
|
84
|
+
for (const exclusiveMeta of meta._exclusive) {
|
|
85
|
+
if (this._components.has(exclusiveMeta.type)) {
|
|
86
|
+
this._remove(exclusiveMeta);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
|
-
const c = new meta.Class(
|
|
90
|
+
const c = new meta.Class();
|
|
90
91
|
if (props !== undefined) {
|
|
91
92
|
Object.assign(c, props);
|
|
92
93
|
}
|
|
93
|
-
this._components.set(type, c);
|
|
94
|
-
this.componentBitmask.
|
|
94
|
+
this._components.set(meta.type, c);
|
|
95
|
+
this.componentBitmask.addBit(meta.bitPtr);
|
|
95
96
|
if (meta._onAddHandlers) {
|
|
96
|
-
meta._onAddHandlers.forEach((handler) => handler(c));
|
|
97
|
+
meta._onAddHandlers.forEach((handler) => handler(this, c));
|
|
97
98
|
}
|
|
98
99
|
this._updateQueries();
|
|
99
100
|
return c;
|
|
@@ -145,23 +146,23 @@ export class Entity {
|
|
|
145
146
|
* `props` if provided, fire `onSet`, and route modified events to every
|
|
146
147
|
* query that watches the component type.
|
|
147
148
|
*/
|
|
148
|
-
_set(
|
|
149
|
+
_set(meta, props) {
|
|
149
150
|
if (this._destroyed) {
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
152
|
-
const existing = this._components.get(type);
|
|
153
|
-
const c = existing ?? this._new(
|
|
153
|
+
const existing = this._components.get(meta.type);
|
|
154
|
+
const c = existing ?? this._new(meta, props);
|
|
154
155
|
if (props !== undefined) {
|
|
155
156
|
if (existing) {
|
|
156
157
|
Object.assign(c, props);
|
|
157
158
|
}
|
|
158
|
-
const setHandlers =
|
|
159
|
+
const setHandlers = meta._onSetHandlers;
|
|
159
160
|
if (setHandlers) {
|
|
160
|
-
setHandlers.forEach((handler) => handler(c));
|
|
161
|
+
setHandlers.forEach((handler) => handler(this, c));
|
|
161
162
|
}
|
|
162
|
-
|
|
163
|
+
this._dirtyComponentBitmask.deleteBit(meta.bitPtr);
|
|
163
164
|
if (existing) {
|
|
164
|
-
this._queries.forEach((q) => q._notifyModified(c));
|
|
165
|
+
this._queries.forEach((q) => q._notifyModified(this, meta, c));
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
}
|
|
@@ -169,39 +170,40 @@ export class Entity {
|
|
|
169
170
|
* @internal Apply a `Modified` command: fire `onSet` and route modified
|
|
170
171
|
* events to every query that watches the component type.
|
|
171
172
|
*/
|
|
172
|
-
_modified(
|
|
173
|
+
_modified(meta) {
|
|
173
174
|
if (this._destroyed) {
|
|
174
175
|
return;
|
|
175
176
|
}
|
|
176
|
-
const c = this._components.get(type);
|
|
177
|
+
const c = this._components.get(meta.type);
|
|
177
178
|
if (!c) {
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
|
-
const setHandlers =
|
|
181
|
+
const setHandlers = meta._onSetHandlers;
|
|
181
182
|
if (setHandlers) {
|
|
182
|
-
setHandlers.forEach((handler) => handler(c));
|
|
183
|
+
setHandlers.forEach((handler) => handler(this, c));
|
|
183
184
|
}
|
|
184
|
-
|
|
185
|
-
this._queries.forEach((q) => q._notifyModified(c));
|
|
185
|
+
this._dirtyComponentBitmask.deleteBit(meta.bitPtr);
|
|
186
|
+
this._queries.forEach((q) => q._notifyModified(this, meta, c));
|
|
186
187
|
}
|
|
187
188
|
/**
|
|
188
189
|
* @internal Apply a `Remove` command: clear the type bit, route exits,
|
|
189
190
|
* detach the component, and fire `onRemove`.
|
|
190
191
|
*/
|
|
191
|
-
_remove(
|
|
192
|
+
_remove(meta) {
|
|
192
193
|
if (this._destroyed) {
|
|
193
194
|
return;
|
|
194
195
|
}
|
|
195
|
-
const c = this._components.get(type);
|
|
196
|
+
const c = this._components.get(meta.type);
|
|
196
197
|
if (!c) {
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
199
|
-
this.
|
|
200
|
+
this._dirtyComponentBitmask.deleteBit(meta.bitPtr);
|
|
201
|
+
this.componentBitmask.deleteBit(meta.bitPtr);
|
|
200
202
|
this._updateQueries();
|
|
201
|
-
this._components.delete(type);
|
|
202
|
-
const removeHandlers =
|
|
203
|
+
this._components.delete(meta.type);
|
|
204
|
+
const removeHandlers = meta._onRemoveHandlers;
|
|
203
205
|
if (removeHandlers) {
|
|
204
|
-
removeHandlers.forEach((handler) => handler(c));
|
|
206
|
+
removeHandlers.forEach((handler) => handler(this, c));
|
|
205
207
|
}
|
|
206
208
|
}
|
|
207
209
|
/**
|
|
@@ -221,12 +223,14 @@ export class Entity {
|
|
|
221
223
|
}
|
|
222
224
|
});
|
|
223
225
|
toExit.forEach((q) => q._exit(this));
|
|
224
|
-
this._components.forEach((c) => {
|
|
225
|
-
const
|
|
226
|
+
this._components.forEach((c, type) => {
|
|
227
|
+
const meta = this.world.getComponentMeta(type);
|
|
228
|
+
const removeHandlers = meta._onRemoveHandlers;
|
|
226
229
|
if (removeHandlers) {
|
|
227
|
-
removeHandlers.forEach((handler) => handler(c));
|
|
230
|
+
removeHandlers.forEach((handler) => handler(this, c));
|
|
228
231
|
}
|
|
229
232
|
});
|
|
233
|
+
this._dirtyComponentBitmask.clear();
|
|
230
234
|
if (this._events) {
|
|
231
235
|
this._events.emit("destroy");
|
|
232
236
|
this._events.removeAllListeners("destroy");
|
|
@@ -315,56 +319,56 @@ export class Entity {
|
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
/**
|
|
318
|
-
* Mark
|
|
322
|
+
* Mark a component type as having changed, queueing the corresponding `onSet` / `update`
|
|
319
323
|
* notifications.
|
|
320
324
|
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* component's dirty flag.
|
|
325
|
+
* Repeated calls before the world routes the modified command are coalesced via
|
|
326
|
+
* the entity's dirty component bitset.
|
|
324
327
|
*
|
|
325
|
-
* @param
|
|
328
|
+
* @param typeOrClass - Component class or numeric type id whose data changed.
|
|
326
329
|
* @returns This entity, for chaining.
|
|
327
330
|
*/
|
|
328
|
-
modified(
|
|
329
|
-
|
|
331
|
+
modified(typeOrClass) {
|
|
332
|
+
const meta = this.world.getComponentMeta(typeOrClass);
|
|
333
|
+
if (this._dirtyComponentBitmask.hasBit(meta.bitPtr)) {
|
|
330
334
|
return this;
|
|
331
335
|
}
|
|
332
|
-
|
|
336
|
+
this._dirtyComponentBitmask.addBit(meta.bitPtr);
|
|
333
337
|
if (this.world.deferred) {
|
|
334
|
-
this.world._enqueue({ kind: 2 /* CommandKind.Modified */, entity: this,
|
|
338
|
+
this.world._enqueue({ kind: 2 /* CommandKind.Modified */, entity: this, meta });
|
|
335
339
|
}
|
|
336
340
|
else {
|
|
337
|
-
this._modified(
|
|
341
|
+
this._modified(meta);
|
|
338
342
|
}
|
|
339
343
|
return this;
|
|
340
344
|
}
|
|
341
345
|
add(typeOrClass) {
|
|
342
|
-
const
|
|
346
|
+
const meta = this.world.getComponentMeta(typeOrClass);
|
|
343
347
|
if (this.world.deferred) {
|
|
344
|
-
this.world._enqueue({ kind: 1 /* CommandKind.Set */, entity: this,
|
|
348
|
+
this.world._enqueue({ kind: 1 /* CommandKind.Set */, entity: this, meta, props: undefined });
|
|
345
349
|
}
|
|
346
350
|
else {
|
|
347
|
-
this._set(
|
|
351
|
+
this._set(meta, undefined);
|
|
348
352
|
}
|
|
349
353
|
return this;
|
|
350
354
|
}
|
|
351
355
|
set(typeOrClass, props) {
|
|
352
|
-
const
|
|
356
|
+
const meta = this.world.getComponentMeta(typeOrClass);
|
|
353
357
|
if (this.world.deferred) {
|
|
354
|
-
this.world._enqueue({ kind: 1 /* CommandKind.Set */, entity: this,
|
|
358
|
+
this.world._enqueue({ kind: 1 /* CommandKind.Set */, entity: this, meta, props });
|
|
355
359
|
}
|
|
356
360
|
else {
|
|
357
|
-
this._set(
|
|
361
|
+
this._set(meta, props);
|
|
358
362
|
}
|
|
359
363
|
return this;
|
|
360
364
|
}
|
|
361
365
|
remove(typeOrClass) {
|
|
362
|
-
const
|
|
366
|
+
const meta = this.world.getComponentMeta(typeOrClass);
|
|
363
367
|
if (this.world.deferred) {
|
|
364
|
-
this.world._enqueue({ kind: 3 /* CommandKind.Remove */, entity: this,
|
|
368
|
+
this.world._enqueue({ kind: 3 /* CommandKind.Remove */, entity: this, meta });
|
|
365
369
|
}
|
|
366
370
|
else {
|
|
367
|
-
this._remove(
|
|
371
|
+
this._remove(meta);
|
|
368
372
|
}
|
|
369
373
|
}
|
|
370
374
|
/**
|
package/dist/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAoB,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,MAAM;IAkCjB;IACE,mCAAmC;IACnB,KAAY;IAC5B,qDAAqD;IACrC,GAAW;QAFX,UAAK,GAAL,KAAK,CAAO;QAEZ,QAAG,GAAH,GAAG,CAAQ;QArC7B,sEAAsE;QAC9D,gBAAW,GAAG,IAAI,QAAQ,EAAa,CAAC;QAChD,gEAAgE;QAC/C,2BAAsB,GAAG,IAAI,MAAM,EAAE,CAAC;QACvD,iEAAiE;QAChD,aAAQ,GAAG,IAAI,GAAG,EAAS,CAAC;QAU7C;;;WAGG;QACa,qBAAgB,GAAG,IAAI,MAAM,EAAE,CAAC;QAEhD;;;W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AAoB,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;SACvE;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SACpB;IACH,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAA2B,WAAuB;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAgC,CAAC;IACxD,CAAC;IAED;;;;;;OAMG;IACI,OAAO;QACZ,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,6BAAqB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;SAClE;aAAM;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjB;QACD,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC/B,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;SACxB;IACH,CAAC;IAED,oDAAoD;IAC7C,QAAQ;QACb,OAAO,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,CAAC;;AA/cD,yEAAyE;AACjD,qBAAc,GAAwB,IAAI,GAAG,EAAE,CAAC"}
|
package/dist/filter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ComponentClass } from "./component.js";
|
|
2
2
|
import type { Entity } from "./entity.js";
|
|
3
3
|
import type { World } from "./world.js";
|
|
4
4
|
import { type MaybeRequired, type QueryDSL } from "./dsl.js";
|
|
@@ -35,7 +35,7 @@ import { type MaybeRequired, type QueryDSL } from "./dsl.js";
|
|
|
35
35
|
* manually via the `_guaranteed` argument. Components in `R` are non-nullable
|
|
36
36
|
* in `forEach` callback tuples.
|
|
37
37
|
*/
|
|
38
|
-
export declare class Filter<R extends
|
|
38
|
+
export declare class Filter<R extends ComponentClass[] = []> {
|
|
39
39
|
/** World this filter reads entities from. */
|
|
40
40
|
readonly world: World;
|
|
41
41
|
private readonly _belongs;
|
|
@@ -61,7 +61,7 @@ export declare class Filter<R extends (typeof Component)[] = []> {
|
|
|
61
61
|
* @param callback - Receives the entity and a tuple of resolved component
|
|
62
62
|
* instances.
|
|
63
63
|
*/
|
|
64
|
-
forEach<J extends
|
|
64
|
+
forEach<J extends ComponentClass[]>(components: readonly [...J], callback: (e: Entity, resolved: {
|
|
65
65
|
[K in keyof J]: MaybeRequired<J[K], R>;
|
|
66
66
|
}) => void): void;
|
|
67
67
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export { type System, type SystemQuery } from "./system.js";
|
|
|
2
2
|
export { Query } from "./query.js";
|
|
3
3
|
export { World } from "./world.js";
|
|
4
4
|
export { Filter } from "./filter.js";
|
|
5
|
-
export { Component, type ComponentMeta } from "./component.js";
|
|
5
|
+
export { type Component, type ComponentClass, type ComponentMeta } from "./component.js";
|
|
6
6
|
export { type Entity } from "./entity.js";
|
|
7
7
|
export { type IPhase } from "./phase.js";
|
|
8
|
+
export { IntervalTickSource, RateTickSource, type ITickSource } from "./timer.js";
|
|
8
9
|
export { Bitset } from "./util/bitset.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Query } from "./query.js";
|
|
2
2
|
export { World } from "./world.js";
|
|
3
3
|
export { Filter } from "./filter.js";
|
|
4
|
-
export {
|
|
4
|
+
export { IntervalTickSource, RateTickSource } from "./timer.js";
|
|
5
5
|
export { Bitset } from "./util/bitset.js";
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/package.json
CHANGED
package/dist/phase.d.ts
CHANGED
|
@@ -12,8 +12,13 @@ import { type World } from "./world.js";
|
|
|
12
12
|
* world.system("NetworkUpdate").phase(preUpdate).run(tick);
|
|
13
13
|
*
|
|
14
14
|
* // each frame:
|
|
15
|
-
* world.
|
|
16
|
-
*
|
|
15
|
+
* world.beginFrame(now, delta);
|
|
16
|
+
* try {
|
|
17
|
+
* world.runPhase(preUpdate, now, delta);
|
|
18
|
+
* world.runPhase(send, now, delta);
|
|
19
|
+
* } finally {
|
|
20
|
+
* world.endFrame();
|
|
21
|
+
* }
|
|
17
22
|
* ```
|
|
18
23
|
*/
|
|
19
24
|
export interface IPhase {
|
package/dist/phase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phase.js","sourceRoot":"","sources":["../src/phase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"phase.js","sourceRoot":"","sources":["../src/phase.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,KAAK;IAIhB;IACE,sDAAsD;IACtC,IAAY;IAC5B,kCAAkC;IAClB,KAAY;QAFZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,UAAK,GAAL,KAAK,CAAO;QAP9B,4DAA4D;QACrD,YAAO,GAAa,EAAE,CAAC;IAO3B,CAAC;CACL"}
|
package/dist/query.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ComponentClass } from "./component.js";
|
|
2
2
|
import type { Entity } from "./entity.js";
|
|
3
3
|
import { type World } from "./world.js";
|
|
4
4
|
import { type EntityTestFunc, type QueryDSL, type MaybeRequired } from "./dsl.js";
|
|
5
5
|
export type { EntityTestFunc, QueryDSL, MaybeRequired };
|
|
6
6
|
/** Component class, or `{ parent: ComponentClass }` to resolve from the entity's parent. */
|
|
7
|
-
type ComponentOrParent =
|
|
8
|
-
parent:
|
|
7
|
+
type ComponentOrParent = ComponentClass | {
|
|
8
|
+
parent: ComponentClass;
|
|
9
9
|
};
|
|
10
10
|
/** Resolves the component instance type for one element of a `ComponentOrParent` tuple. */
|
|
11
11
|
type ComponentInstance<T> = T extends {
|
|
12
|
-
parent:
|
|
13
|
-
} ? InstanceType<T["parent"]> : T extends
|
|
12
|
+
parent: ComponentClass;
|
|
13
|
+
} ? InstanceType<T["parent"]> : T extends ComponentClass ? InstanceType<T> : never;
|
|
14
14
|
/**
|
|
15
15
|
* A reactive, always-up-to-date set of entities matching a {@link QueryDSL}
|
|
16
16
|
* predicate.
|
|
@@ -33,7 +33,7 @@ type ComponentInstance<T> = T extends {
|
|
|
33
33
|
* Components in `R` appear as non-nullable in {@link sort}, {@link forEach},
|
|
34
34
|
* and {@link update} callback tuples.
|
|
35
35
|
*/
|
|
36
|
-
export declare class Query<R extends
|
|
36
|
+
export declare class Query<R extends ComponentClass[] = []> {
|
|
37
37
|
/** Unique display name; appears in logs and debug output. */
|
|
38
38
|
readonly name: string;
|
|
39
39
|
/** World that owns this query. */
|
|
@@ -89,7 +89,7 @@ export declare class Query<R extends (typeof Component)[] = []> {
|
|
|
89
89
|
* @param callback - Receives the entity and a tuple of resolved component
|
|
90
90
|
* instances.
|
|
91
91
|
*/
|
|
92
|
-
forEach<J extends
|
|
92
|
+
forEach<J extends ComponentClass[]>(components: readonly [...J], callback: (e: Entity, resolved: {
|
|
93
93
|
[K in keyof J]: MaybeRequired<J[K], R>;
|
|
94
94
|
}) => void): void;
|
|
95
95
|
/**
|
|
@@ -155,50 +155,50 @@ export declare class Query<R extends (typeof Component)[] = []> {
|
|
|
155
155
|
* predicate becomes a `HAS` of every watched type).
|
|
156
156
|
*
|
|
157
157
|
* @param ComponentClass - Component class to watch.
|
|
158
|
-
* @param callback - Receives the modified component instance.
|
|
158
|
+
* @param callback - Receives the entity and modified component instance.
|
|
159
159
|
* @returns This query, for chaining.
|
|
160
160
|
*
|
|
161
161
|
* @example
|
|
162
162
|
* ```ts
|
|
163
163
|
* world.system("RenderPosition")
|
|
164
|
-
* .update(Position, (pos) => sprite.setPosition(pos.x, pos.y));
|
|
164
|
+
* .update(Position, (e, pos) => sprite.setPosition(pos.x, pos.y));
|
|
165
165
|
* ```
|
|
166
166
|
*/
|
|
167
|
-
update<C extends
|
|
167
|
+
update<C extends ComponentClass>(ComponentClass: C, callback: (e: Entity, c: InstanceType<C>) => void): this;
|
|
168
168
|
/**
|
|
169
169
|
* Like {@link update}, but with extra components injected from the same
|
|
170
170
|
* entity.
|
|
171
171
|
*
|
|
172
172
|
* @param ComponentClass - Component class to watch.
|
|
173
173
|
* @param inject - Additional component classes to resolve from the entity.
|
|
174
|
-
* @param callback - Receives the modified component and
|
|
174
|
+
* @param callback - Receives the entity, modified component, and injected tuple.
|
|
175
175
|
* @returns This query, for chaining.
|
|
176
176
|
*/
|
|
177
|
-
update<C extends
|
|
177
|
+
update<C extends ComponentClass, J extends ComponentClass[]>(ComponentClass: C, inject: readonly [...J], callback: (e: Entity, c: InstanceType<C>, injected: {
|
|
178
178
|
[K in keyof J]: MaybeRequired<J[K], R>;
|
|
179
179
|
}) => void): this;
|
|
180
180
|
/**
|
|
181
181
|
* Switch the tracked set to a sorted ordering: matched entities are stored
|
|
182
|
-
* in the position determined by `compare`, which receives
|
|
183
|
-
* resolved component instances for each pair being ordered.
|
|
182
|
+
* in the position determined by `compare`, which receives each entity and a
|
|
183
|
+
* tuple of resolved component instances for each pair being ordered.
|
|
184
184
|
*
|
|
185
185
|
* Implies {@link track}.
|
|
186
186
|
*
|
|
187
187
|
* @param components - Component classes to resolve and pass to `compare`.
|
|
188
|
-
* @param compare - Negative when `
|
|
189
|
-
* equality, positive when `
|
|
188
|
+
* @param compare - Negative when `entityA` should sort before `entityB`, zero
|
|
189
|
+
* for equality, positive when `entityA` should sort after `entityB`.
|
|
190
190
|
* @returns This query, for chaining.
|
|
191
191
|
*
|
|
192
192
|
* @example
|
|
193
193
|
* ```ts
|
|
194
194
|
* world.system("Render")
|
|
195
195
|
* .requires(Position, Sprite)
|
|
196
|
-
* .sort([Position], ([posA], [posB]) => posA.z - posB.z);
|
|
196
|
+
* .sort([Position], (_entityA, [posA], _entityB, [posB]) => posA.z - posB.z);
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
sort<J extends
|
|
199
|
+
sort<J extends ComponentClass[]>(components: readonly [...J], compare: (entityA: Entity, a: {
|
|
200
200
|
[K in keyof J]: MaybeRequired<J[K], R>;
|
|
201
|
-
}, b: {
|
|
201
|
+
}, entityB: Entity, b: {
|
|
202
202
|
[K in keyof J]: MaybeRequired<J[K], R>;
|
|
203
203
|
}) => number): this;
|
|
204
204
|
/**
|
|
@@ -224,7 +224,7 @@ export declare class Query<R extends (typeof Component)[] = []> {
|
|
|
224
224
|
* });
|
|
225
225
|
* ```
|
|
226
226
|
*/
|
|
227
|
-
query<T extends
|
|
227
|
+
query<T extends ComponentClass[] = []>(q: QueryDSL, _guaranteed?: readonly [...T]): Query<T>;
|
|
228
228
|
/**
|
|
229
229
|
* Shorthand for `query([...components])`: track entities that have **all**
|
|
230
230
|
* of the listed component types.
|
|
@@ -236,7 +236,7 @@ export declare class Query<R extends (typeof Component)[] = []> {
|
|
|
236
236
|
* @param components - Component classes to require.
|
|
237
237
|
* @returns This query, retyped with the required tuple as its `R`.
|
|
238
238
|
*/
|
|
239
|
-
requires<T extends
|
|
239
|
+
requires<T extends ComponentClass[]>(...components: [...T]): Query<T>;
|
|
240
240
|
/**
|
|
241
241
|
* Permanently remove this query from the world.
|
|
242
242
|
*
|