@codehz/ecs 0.7.6 → 0.8.0
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/builder.d.mts +13 -10
- package/dist/world.mjs +13 -10
- package/dist/world.mjs.map +1 -1
- package/package.json +1 -1
- package/src/world/world.ts +13 -10
package/dist/builder.d.mts
CHANGED
|
@@ -1152,25 +1152,28 @@ declare class World {
|
|
|
1152
1152
|
* **Important:** Store the query reference and reuse it across frames for optimal performance.
|
|
1153
1153
|
* Creating a new query each frame defeats the caching mechanism.
|
|
1154
1154
|
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1155
|
+
* **Note on optional components:** Only **required** (non-optional) component types should be
|
|
1156
|
+
* passed to `createQuery`. Optional components (wrapped with `{ optional: ... }`) must be
|
|
1157
|
+
* specified at **iteration time** via {@link Query.forEach}, {@link Query.getEntitiesWithComponents},
|
|
1158
|
+
* or {@link Query.iterate} — NOT here. Including optional wrappers in `createQuery` will cause
|
|
1159
|
+
* undefined behavior because the internal normalization relies on numeric sorting of component IDs.
|
|
1160
|
+
*
|
|
1161
|
+
* @param componentTypes - Array of **required** component types to match (do not include optional wrappers)
|
|
1162
|
+
* @param filter - Optional filter for additional constraints (e.g., exclude entities with certain components)
|
|
1157
1163
|
* @returns A Query instance that can be used to iterate matching entities
|
|
1158
1164
|
*
|
|
1159
1165
|
* @example
|
|
1160
|
-
* // Create once, reuse many times
|
|
1166
|
+
* // Create once, reuse many times (required components only)
|
|
1161
1167
|
* const movementQuery = world.createQuery([Position, Velocity]);
|
|
1162
1168
|
*
|
|
1163
|
-
* //
|
|
1164
|
-
* movementQuery.forEach((entity) => {
|
|
1165
|
-
*
|
|
1166
|
-
* const vel = world.get(entity, Velocity);
|
|
1167
|
-
* pos.x += vel.x;
|
|
1168
|
-
* pos.y += vel.y;
|
|
1169
|
+
* // Optional components are passed at iteration time, not creation time:
|
|
1170
|
+
* movementQuery.forEach([Position, { optional: Velocity }], (entity, pos, vel) => {
|
|
1171
|
+
* pos.x += vel?.value?.x ?? 0;
|
|
1169
1172
|
* });
|
|
1170
1173
|
*
|
|
1171
1174
|
* // With filter
|
|
1172
1175
|
* const activeQuery = world.createQuery([Position], {
|
|
1173
|
-
*
|
|
1176
|
+
* negativeComponentTypes: [Disabled]
|
|
1174
1177
|
* });
|
|
1175
1178
|
*/
|
|
1176
1179
|
createQuery(componentTypes: EntityId<any>[], filter?: QueryFilter): Query;
|
package/dist/world.mjs
CHANGED
|
@@ -2612,25 +2612,28 @@ var World = class {
|
|
|
2612
2612
|
* **Important:** Store the query reference and reuse it across frames for optimal performance.
|
|
2613
2613
|
* Creating a new query each frame defeats the caching mechanism.
|
|
2614
2614
|
*
|
|
2615
|
-
*
|
|
2616
|
-
*
|
|
2615
|
+
* **Note on optional components:** Only **required** (non-optional) component types should be
|
|
2616
|
+
* passed to `createQuery`. Optional components (wrapped with `{ optional: ... }`) must be
|
|
2617
|
+
* specified at **iteration time** via {@link Query.forEach}, {@link Query.getEntitiesWithComponents},
|
|
2618
|
+
* or {@link Query.iterate} — NOT here. Including optional wrappers in `createQuery` will cause
|
|
2619
|
+
* undefined behavior because the internal normalization relies on numeric sorting of component IDs.
|
|
2620
|
+
*
|
|
2621
|
+
* @param componentTypes - Array of **required** component types to match (do not include optional wrappers)
|
|
2622
|
+
* @param filter - Optional filter for additional constraints (e.g., exclude entities with certain components)
|
|
2617
2623
|
* @returns A Query instance that can be used to iterate matching entities
|
|
2618
2624
|
*
|
|
2619
2625
|
* @example
|
|
2620
|
-
* // Create once, reuse many times
|
|
2626
|
+
* // Create once, reuse many times (required components only)
|
|
2621
2627
|
* const movementQuery = world.createQuery([Position, Velocity]);
|
|
2622
2628
|
*
|
|
2623
|
-
* //
|
|
2624
|
-
* movementQuery.forEach((entity) => {
|
|
2625
|
-
*
|
|
2626
|
-
* const vel = world.get(entity, Velocity);
|
|
2627
|
-
* pos.x += vel.x;
|
|
2628
|
-
* pos.y += vel.y;
|
|
2629
|
+
* // Optional components are passed at iteration time, not creation time:
|
|
2630
|
+
* movementQuery.forEach([Position, { optional: Velocity }], (entity, pos, vel) => {
|
|
2631
|
+
* pos.x += vel?.value?.x ?? 0;
|
|
2629
2632
|
* });
|
|
2630
2633
|
*
|
|
2631
2634
|
* // With filter
|
|
2632
2635
|
* const activeQuery = world.createQuery([Position], {
|
|
2633
|
-
*
|
|
2636
|
+
* negativeComponentTypes: [Disabled]
|
|
2634
2637
|
* });
|
|
2635
2638
|
*/
|
|
2636
2639
|
createQuery(componentTypes, filter = {}) {
|