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

Method queryByName

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

* 按名称查询实体 * * 返回具有指定名称的所有实体。 * 名称查询使用专用索引,适用于查找特定的命名实体。 * * @param name 要查询的实体名称 * @returns 查询结果,包含匹配的实体和性能信息 * * @example * ```typescript * // 查找名为"Player"的实体 * const player = querySystem.queryByName("Player"); * ```

(name: string)

Source from the content-addressed store, hash-verified

502 * ```
503 */
504 public queryByName(name: string): QueryResult {
505 const startTime = performance.now();
506 this._queryStats.totalQueries++;
507
508 const cacheKey = `name:${name}`;
509
510 // 检查缓存
511 const cached = this.getFromCache(cacheKey);
512 if (cached) {
513 this._queryStats.cacheHits++;
514 return {
515 entities: cached,
516 count: cached.length,
517 executionTime: performance.now() - startTime,
518 fromCache: true
519 };
520 }
521
522 // 使用索引查询
523 this._queryStats.indexHits++;
524 const entities = Array.from(this._entityIndex.byName.get(name) || []);
525
526 // 缓存结果
527 this.addToCache(cacheKey, entities);
528
529 return {
530 entities,
531 count: entities.length,
532 executionTime: performance.now() - startTime,
533 fromCache: false
534 };
535 }
536
537 /**
538 * 查询自指定 epoch 以来发生变更的实体

Callers 3

Calls 5

getFromCacheMethod · 0.95
addToCacheMethod · 0.95
nowMethod · 0.80
getMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected