MCPcopy Create free account
hub / github.com/esengine/esengine / queryAny

Method queryAny

packages/core/src/ECS/Core/QuerySystem.ts:383–402  ·  view source on GitHub ↗

* 查询包含任意指定组件的实体 * * 返回包含任意一个指定组件类型的实体列表。 * 内部使用响应式查询作为智能缓存,自动跟踪实体变化,性能更优。 * * @param componentTypes 要查询的组件类型列表 * @returns 查询结果,包含匹配的实体和性能信息 * * @example * ```typescript * // 查询具有武器或护甲组件的实体 * const result = querySystem.queryAny(WeaponComponent, A

(...componentTypes: ComponentType[])

Source from the content-addressed store, hash-verified

381 * ```
382 */
383 public queryAny(...componentTypes: ComponentType[]): QueryResult {
384 const startTime = performance.now();
385 this._queryStats.totalQueries++;
386
387 // 使用内部响应式查询作为智能缓存
388 const reactiveQuery = this.getOrCreateReactiveQuery(QueryConditionType.ANY, componentTypes);
389
390 // 从响应式查询获取结果(永远是最新的)
391 const entities = reactiveQuery.getEntities();
392
393 // 统计为缓存命中(响应式查询本质上是永不过期的智能缓存)
394 this._queryStats.cacheHits++;
395
396 return {
397 entities,
398 count: entities.length,
399 executionTime: performance.now() - startTime,
400 fromCache: true
401 };
402 }
403
404 /**
405 * 查询不包含任何指定组件的实体

Callers 3

executeMethod · 0.45

Calls 3

nowMethod · 0.80
getEntitiesMethod · 0.65

Tested by

no test coverage detected