@vworlds/vecs 1.0.13 → 1.0.15
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/README.md +18 -9
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +77 -54
- package/dist/entity.js +225 -180
- package/dist/entity.js.map +1 -1
- package/dist/filter.js.map +1 -1
- package/dist/package.json +7 -20
- package/dist/query.js.map +1 -1
- package/dist/system.js.map +1 -1
- package/dist/timer.js.map +1 -1
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.js.map +1 -1
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world.d.ts +1 -1
- package/dist/world.js +4 -1
- package/dist/world.js.map +1 -1
- package/package.json +7 -20
- package/tsconfig.build.json +13 -0
- package/.husky/pre-commit +0 -3
- package/.prettierrc +0 -7
- package/eslint-rules/internal-underscore.js +0 -60
- package/eslint.config.js +0 -22
package/README.md
CHANGED
|
@@ -120,11 +120,12 @@ for (let tick = 0; tick < 5; tick++) {
|
|
|
120
120
|
|
|
121
121
|
## Deferred mode
|
|
122
122
|
|
|
123
|
-
Inside a system body, a `Query.forEach`, or any `world.defer(...)` block, the world is in **deferred mode**: entity mutations (`add` / `set` / `remove` / `destroy` / `setParent` / `modified`) are queued instead of applied inline. The queue drains on the boundary that opened the deferred scope.
|
|
123
|
+
Inside a system body, a `Query.forEach`, or any `world.defer(...)` block, the world is in **deferred mode**: entity mutations (`add` / `attach` / `set` / `remove` / `destroy` / `setParent` / `modified`) are queued instead of applied inline. The queue drains on the boundary that opened the deferred scope.
|
|
124
124
|
|
|
125
125
|
Concretely, while deferred:
|
|
126
126
|
|
|
127
127
|
- `entity.get(C)` returns `undefined` after `entity.add(C)` (no instance has been created yet).
|
|
128
|
+
- `entity.get(C)` returns `undefined` after `entity.attach(instance)` if C was absent.
|
|
128
129
|
- `entity.get(C)` returns the **previous** value after `entity.set(C, props)`.
|
|
129
130
|
- `entity.get(C)` still returns the component after `entity.remove(C)`.
|
|
130
131
|
|
|
@@ -213,7 +214,7 @@ world
|
|
|
213
214
|
.onSet((entity, sprite) => sprite.syncToScene(entity));
|
|
214
215
|
```
|
|
215
216
|
|
|
216
|
-
`onAdd` fires when the component is first attached. `onRemove` fires when it is removed (or the entity is destroyed). `onSet` fires whenever `entity.modified(C)` is called,
|
|
217
|
+
`onAdd` fires when the component is first attached. `onRemove` fires when it is removed (or the entity is destroyed). `onSet` fires whenever `entity.modified(C)` is called, when `entity.set(C, props)` applies data, and when `entity.attach(instance)` stores an existing instance. Hook callbacks receive the owning entity because component instances do not carry entity references.
|
|
217
218
|
|
|
218
219
|
#### Phases
|
|
219
220
|
|
|
@@ -384,15 +385,20 @@ entity.modified(Position); // tell the world this component changed
|
|
|
384
385
|
|
|
385
386
|
// Equivalent — set assigns props and fires onSet automatically:
|
|
386
387
|
entity.set(Position, { x: 100 });
|
|
388
|
+
|
|
389
|
+
// Store an existing instance directly:
|
|
390
|
+
const shared = new Position();
|
|
391
|
+
entity.attach(shared);
|
|
392
|
+
entity.get(Position) === shared; // true
|
|
387
393
|
```
|
|
388
394
|
|
|
389
|
-
| Rule | Description
|
|
390
|
-
| ------------------------- |
|
|
391
|
-
| Plain class | Components should be ordinary classes with field initializers and methods as needed.
|
|
392
|
-
| No-arg construction | vecs calls `new ComponentClass()`, so constructors should be omitted or take no parameters.
|
|
393
|
-
| Explicit registration | Call `world.registerComponent(C)` before using the class as a component.
|
|
394
|
-
| Shared instances possible |
|
|
395
|
-
| Manual dirty marking | After mutating fields directly, call `entity.modified(C)` to notify hooks, queries, and systems.
|
|
395
|
+
| Rule | Description |
|
|
396
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
397
|
+
| Plain class | Components should be ordinary classes with field initializers and methods as needed. |
|
|
398
|
+
| No-arg construction | vecs calls `new ComponentClass()`, so constructors should be omitted or take no parameters. |
|
|
399
|
+
| Explicit registration | Call `world.registerComponent(C)` before using the class as a component. |
|
|
400
|
+
| Shared instances possible | `entity.attach(instance)` stores the exact passed object; code should use the entity passed by vecs callbacks. |
|
|
401
|
+
| Manual dirty marking | After mutating fields directly, call `entity.modified(C)` to notify hooks, queries, and systems. |
|
|
396
402
|
|
|
397
403
|
Use `world.getComponentMeta(C)` or `world.getComponentType(C)` when you need metadata such as the numeric type id or component name. Metadata is world-specific.
|
|
398
404
|
|
|
@@ -409,6 +415,7 @@ Created via `world.entity()` (auto-assigned id) or `world.getOrCreateEntity(id,
|
|
|
409
415
|
| `componentBitmask` | `Bitset` of component type ids attached to this entity. Used by archetype matching. |
|
|
410
416
|
| `properties` | `Map<string, any>` free-form bag for module-level bookkeeping. |
|
|
411
417
|
| `add(Class)` | Attach a component (idempotent). Returns the entity for chaining. |
|
|
418
|
+
| `attach(instance)` | Attach an existing registered component instance directly; replaces any previous instance for that component class and fires `onSet`. |
|
|
412
419
|
| `set(Class, props)` | Attach a component and assign `props`; fires `onSet`. Returns the entity for chaining. |
|
|
413
420
|
| `modified(Class)` | Queue an `onSet` / `update` notification for a component class or numeric type id. Returns the entity for chaining. |
|
|
414
421
|
| `get(Class)` | Return the component instance, or `undefined`. |
|
|
@@ -430,6 +437,8 @@ vel.vx += accel;
|
|
|
430
437
|
entity.modified(Velocity); // chainable
|
|
431
438
|
```
|
|
432
439
|
|
|
440
|
+
Use `entity.attach(instance)` when component ownership is intentionally shared with caller code or another object graph. The instance constructor must be registered in the entity's world; unregistered instances throw. If the component belongs to an exclusive component group, conflicting components are removed before the instance is stored.
|
|
441
|
+
|
|
433
442
|
#### Parent / child hierarchy
|
|
434
443
|
|
|
435
444
|
```ts
|
package/dist/dsl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dsl.js","sourceRoot":"","sources":["../src/dsl.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAmGxB;;;;;;;;;GASG;AACH,MAAM,UAAU,IAAI,CAAC,KAAY,EAAE,G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AAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,yBAAyB,CAAC;AAClC,CAAC"}
|
package/dist/entity.d.ts
CHANGED
|
@@ -19,18 +19,20 @@ type EntityEvents = Events<{
|
|
|
19
19
|
* e.set(Position, { x: 100 });
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* Entities support a parent
|
|
22
|
+
* Entities support a parent-child hierarchy. `parent` and `children` form a
|
|
23
23
|
* bidirectional link maintained by {@link setParent}; the children set is
|
|
24
24
|
* created lazily. Destroying a parent recursively destroys its children.
|
|
25
25
|
*
|
|
26
26
|
* ## Deferred semantics
|
|
27
27
|
*
|
|
28
28
|
* Inside a system body or `forEach` iteration the world is in **deferred
|
|
29
|
-
* mode**: `add` / `set` / `modified` / `remove` / `destroy` /
|
|
30
|
-
* enqueue commands. The data layer (the components map and
|
|
31
|
-
* is mutated when the world drains its queue. Concretely,
|
|
29
|
+
* mode**: `add` / `attach` / `set` / `modified` / `remove` / `destroy` /
|
|
30
|
+
* `setParent` only enqueue commands. The data layer (the components map and
|
|
31
|
+
* `componentBitmask`) is mutated when the world drains its queue. Concretely,
|
|
32
|
+
* while deferred:
|
|
32
33
|
*
|
|
33
34
|
* - `entity.get(C)` returns `undefined` after `entity.add(C)` (no instance yet).
|
|
35
|
+
* - `entity.get(C)` returns `undefined` after `entity.attach(instance)` if C was absent.
|
|
34
36
|
* - `entity.get(C)` returns the previous value after `entity.set(C, props)`.
|
|
35
37
|
* - `entity.get(C)` still returns the component after `entity.remove(C)`.
|
|
36
38
|
*
|
|
@@ -57,11 +59,19 @@ export declare class Entity {
|
|
|
57
59
|
world: World,
|
|
58
60
|
/** Unique numeric entity id assigned at creation. */
|
|
59
61
|
eid: number);
|
|
62
|
+
/** Fire every `onAdd` hook registered for `meta`. */
|
|
63
|
+
private _runOnAddHandlers;
|
|
64
|
+
/** Fire every `onSet` hook registered for `meta`. */
|
|
65
|
+
private _runOnSetHandlers;
|
|
60
66
|
/**
|
|
61
67
|
* Re-evaluate every world query for this entity, firing `_enter` / `_exit`
|
|
62
68
|
* routing whenever membership flipped.
|
|
63
69
|
*/
|
|
64
70
|
private _updateQueries;
|
|
71
|
+
/** Store a component instance and perform the shared add-side bookkeeping. */
|
|
72
|
+
private _storeComponent;
|
|
73
|
+
/** Perform the shared set-side hook and query update routing. */
|
|
74
|
+
private _notifyComponentSet;
|
|
65
75
|
/**
|
|
66
76
|
* Construct a fresh component of `type`, apply `props`, store it on this
|
|
67
77
|
* entity, fire the `onAdd` hook, and route query updates.
|
|
@@ -70,57 +80,39 @@ export declare class Entity {
|
|
|
70
80
|
* component already on this entity is removed first.
|
|
71
81
|
*/
|
|
72
82
|
private _new;
|
|
73
|
-
/** Parent entity in the scene hierarchy, or `undefined` for a root entity. */
|
|
74
|
-
get parent(): Entity | undefined;
|
|
75
83
|
/**
|
|
76
84
|
* Read-only view of direct child entities. The backing set is created lazily
|
|
77
85
|
* on the first child link; before that this getter returns a shared empty set.
|
|
78
86
|
*/
|
|
79
87
|
get children(): ReadonlySet<Entity>;
|
|
80
|
-
/**
|
|
81
|
-
* Typed event emitter for entity-level lifecycle events. Currently only the
|
|
82
|
-
* `"destroy"` event is emitted, just before the entity is fully torn down.
|
|
83
|
-
*
|
|
84
|
-
* The emitter is created lazily on first access.
|
|
85
|
-
*/
|
|
86
|
-
get events(): EntityEvents;
|
|
87
|
-
/** `true` when no components are currently attached to this entity. */
|
|
88
|
-
get empty(): boolean;
|
|
89
88
|
/**
|
|
90
89
|
* Read-only view of all components currently attached to this entity, keyed
|
|
91
90
|
* by numeric component type id.
|
|
92
91
|
*
|
|
93
92
|
* The mutating methods (`set`, `delete`, `clear`) are not exposed. Use
|
|
94
|
-
* `entity.add`, `entity.set`, and `entity.remove` to change
|
|
95
|
-
* set.
|
|
93
|
+
* `entity.add`, `entity.attach`, `entity.set`, and `entity.remove` to change
|
|
94
|
+
* the component set.
|
|
96
95
|
*
|
|
97
96
|
* ```ts
|
|
98
97
|
* entity.components.forEach((c) => console.log(c.constructor.name));
|
|
99
98
|
* ```
|
|
100
99
|
*/
|
|
101
100
|
get components(): ReadonlyArrayMap<Component>;
|
|
101
|
+
/** `true` when no components are currently attached to this entity. */
|
|
102
|
+
get empty(): boolean;
|
|
102
103
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* @param newParent - New parent, or `undefined` to make this a root entity.
|
|
107
|
-
*/
|
|
108
|
-
setParent(newParent: Entity | undefined): void;
|
|
109
|
-
/**
|
|
110
|
-
* Mark a component type as having changed, queueing the corresponding `onSet` / `update`
|
|
111
|
-
* notifications.
|
|
112
|
-
*
|
|
113
|
-
* Repeated calls before the world routes the modified command are coalesced via
|
|
114
|
-
* the entity's dirty component bitset.
|
|
104
|
+
* Typed event emitter for entity-level lifecycle events. Currently only the
|
|
105
|
+
* `"destroy"` event is emitted, just before the entity is fully torn down.
|
|
115
106
|
*
|
|
116
|
-
*
|
|
117
|
-
* @returns This entity, for chaining.
|
|
107
|
+
* The emitter is created lazily on first access.
|
|
118
108
|
*/
|
|
119
|
-
|
|
109
|
+
get events(): EntityEvents;
|
|
110
|
+
/** Parent entity in the scene hierarchy, or `undefined` for a root entity. */
|
|
111
|
+
get parent(): Entity | undefined;
|
|
120
112
|
/**
|
|
121
113
|
* Attach a component to this entity if it is not already present.
|
|
122
114
|
*
|
|
123
|
-
* Idempotent. Does not fire `onSet`
|
|
115
|
+
* Idempotent. Does not fire `onSet` -- use {@link set} when you want to apply
|
|
124
116
|
* data and notify watchers.
|
|
125
117
|
*
|
|
126
118
|
* @param Class - Component class to instantiate.
|
|
@@ -135,26 +127,44 @@ export declare class Entity {
|
|
|
135
127
|
*/
|
|
136
128
|
add(type: number): Entity;
|
|
137
129
|
/**
|
|
138
|
-
* Attach
|
|
139
|
-
*
|
|
140
|
-
*
|
|
130
|
+
* Attach an existing component instance to this entity and store that exact
|
|
131
|
+
* object. If a component of the same registered class already exists, it is
|
|
132
|
+
* replaced rather than assigned into.
|
|
141
133
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
134
|
+
* `attach` uses the instance constructor to resolve component metadata, so
|
|
135
|
+
* the constructor must already be registered in this world. The operation
|
|
136
|
+
* fires hooks and query updates like a `set` operation.
|
|
144
137
|
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param props - Properties to assign onto the component instance.
|
|
138
|
+
* @param component - Existing component instance to store on the entity.
|
|
147
139
|
* @returns This entity, for chaining.
|
|
148
140
|
*/
|
|
149
|
-
|
|
141
|
+
attach(component: Component): Entity;
|
|
150
142
|
/**
|
|
151
|
-
*
|
|
143
|
+
* Destroy this entity and recursively destroy its children.
|
|
152
144
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
145
|
+
* Each component fires its `onRemove` hook, the `"destroy"` event is emitted
|
|
146
|
+
* just before teardown, and the entity is unregistered from the world.
|
|
147
|
+
* After destruction the entity must not be used.
|
|
148
|
+
*/
|
|
149
|
+
destroy(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Look up a component on this entity.
|
|
152
|
+
*
|
|
153
|
+
* @param typeOrClass - Component class or numeric type id.
|
|
154
|
+
* @returns The component instance, or `undefined` when it is not attached.
|
|
155
|
+
*/
|
|
156
|
+
get<C extends ComponentClass>(typeOrClass: number | C): InstanceType<C> | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Mark a component type as having changed, queueing the corresponding `onSet` / `update`
|
|
159
|
+
* notifications.
|
|
160
|
+
*
|
|
161
|
+
* Repeated calls before the world routes the modified command are coalesced via
|
|
162
|
+
* the entity's dirty component bitset.
|
|
163
|
+
*
|
|
164
|
+
* @param typeOrClass - Component class or numeric type id whose data changed.
|
|
155
165
|
* @returns This entity, for chaining.
|
|
156
166
|
*/
|
|
157
|
-
|
|
167
|
+
modified(typeOrClass: ComponentClassOrType): Entity;
|
|
158
168
|
/**
|
|
159
169
|
* Detach a component from this entity.
|
|
160
170
|
*
|
|
@@ -172,20 +182,33 @@ export declare class Entity {
|
|
|
172
182
|
*/
|
|
173
183
|
remove(type: number): void;
|
|
174
184
|
/**
|
|
175
|
-
*
|
|
185
|
+
* Reparent this entity. In deferred mode the change is queued; outside
|
|
186
|
+
* deferred mode it executes inline.
|
|
176
187
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @returns The component instance, or `undefined` when it is not attached.
|
|
188
|
+
* @param newParent - New parent, or `undefined` to make this a root entity.
|
|
179
189
|
*/
|
|
180
|
-
|
|
190
|
+
setParent(newParent: Entity | undefined): void;
|
|
181
191
|
/**
|
|
182
|
-
*
|
|
192
|
+
* Attach a component (creating it if necessary), copy `props` onto the
|
|
193
|
+
* instance, and fire the `onSet` hook plus any `update` callbacks for the
|
|
194
|
+
* component type.
|
|
183
195
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
196
|
+
* In deferred mode `props` are not applied until the queued `Set` command is
|
|
197
|
+
* routed.
|
|
198
|
+
*
|
|
199
|
+
* @param Class - Component class to instantiate.
|
|
200
|
+
* @param props - Properties to assign onto the component instance.
|
|
201
|
+
* @returns This entity, for chaining.
|
|
187
202
|
*/
|
|
188
|
-
|
|
203
|
+
set<C extends ComponentClass>(Class: C, props: Partial<InstanceType<C>>): Entity;
|
|
204
|
+
/**
|
|
205
|
+
* Attach a component by numeric type id and copy `props` onto it.
|
|
206
|
+
*
|
|
207
|
+
* @param type - Numeric component type id.
|
|
208
|
+
* @param props - Properties to assign onto the component instance.
|
|
209
|
+
* @returns This entity, for chaining.
|
|
210
|
+
*/
|
|
211
|
+
set(type: number, props: Partial<Component>): Entity;
|
|
189
212
|
/** Returns `"EntityN"` where N is the entity id. */
|
|
190
213
|
toString(): string;
|
|
191
214
|
}
|