@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/package.json
CHANGED
package/src/world/world.ts
CHANGED
|
@@ -698,25 +698,28 @@ export class World {
|
|
|
698
698
|
* **Important:** Store the query reference and reuse it across frames for optimal performance.
|
|
699
699
|
* Creating a new query each frame defeats the caching mechanism.
|
|
700
700
|
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
701
|
+
* **Note on optional components:** Only **required** (non-optional) component types should be
|
|
702
|
+
* passed to `createQuery`. Optional components (wrapped with `{ optional: ... }`) must be
|
|
703
|
+
* specified at **iteration time** via {@link Query.forEach}, {@link Query.getEntitiesWithComponents},
|
|
704
|
+
* or {@link Query.iterate} — NOT here. Including optional wrappers in `createQuery` will cause
|
|
705
|
+
* undefined behavior because the internal normalization relies on numeric sorting of component IDs.
|
|
706
|
+
*
|
|
707
|
+
* @param componentTypes - Array of **required** component types to match (do not include optional wrappers)
|
|
708
|
+
* @param filter - Optional filter for additional constraints (e.g., exclude entities with certain components)
|
|
703
709
|
* @returns A Query instance that can be used to iterate matching entities
|
|
704
710
|
*
|
|
705
711
|
* @example
|
|
706
|
-
* // Create once, reuse many times
|
|
712
|
+
* // Create once, reuse many times (required components only)
|
|
707
713
|
* const movementQuery = world.createQuery([Position, Velocity]);
|
|
708
714
|
*
|
|
709
|
-
* //
|
|
710
|
-
* movementQuery.forEach((entity) => {
|
|
711
|
-
*
|
|
712
|
-
* const vel = world.get(entity, Velocity);
|
|
713
|
-
* pos.x += vel.x;
|
|
714
|
-
* pos.y += vel.y;
|
|
715
|
+
* // Optional components are passed at iteration time, not creation time:
|
|
716
|
+
* movementQuery.forEach([Position, { optional: Velocity }], (entity, pos, vel) => {
|
|
717
|
+
* pos.x += vel?.value?.x ?? 0;
|
|
715
718
|
* });
|
|
716
719
|
*
|
|
717
720
|
* // With filter
|
|
718
721
|
* const activeQuery = world.createQuery([Position], {
|
|
719
|
-
*
|
|
722
|
+
* negativeComponentTypes: [Disabled]
|
|
720
723
|
* });
|
|
721
724
|
*/
|
|
722
725
|
createQuery(componentTypes: EntityId<any>[], filter: QueryFilter = {}): Query {
|