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

Method queryChangedSince

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

* 查询自指定 epoch 以来发生变更的实体 * * 返回拥有指定组件且该组件在 sinceEpoch 之后被修改过的实体。 * 用于实现增量更新,只处理发生变化的实体。 * * Query entities with components changed since the specified epoch. * Returns entities that have the specified component type(s) and that component * was modified after sinceEp

(sinceEpoch: number, ...componentTypes: ComponentType[])

Source from the content-addressed store, hash-verified

571 * ```
572 */
573 public queryChangedSince(sinceEpoch: number, ...componentTypes: ComponentType[]): QueryResult {
574 const startTime = performance.now();
575 this._queryStats.totalQueries++;
576 this._queryStats.dirtyChecks++;
577
578 // 先获取所有拥有这些组件的实体
579 const baseResult = this.queryAll(...componentTypes);
580 const changedEntities: Entity[] = [];
581
582 // 过滤出组件发生变更的实体
583 for (const entity of baseResult.entities) {
584 let hasChanged = false;
585
586 for (const componentType of componentTypes) {
587 const component = entity.getComponent(componentType);
588 if (component && component.lastWriteEpoch > sinceEpoch) {
589 hasChanged = true;
590 break;
591 }
592 }
593
594 if (hasChanged) {
595 changedEntities.push(entity);
596 }
597 }
598
599 return {
600 entities: changedEntities,
601 count: changedEntities.length,
602 executionTime: performance.now() - startTime,
603 fromCache: false
604 };
605 }
606
607 /**
608 * 按单个组件类型查询实体

Callers

nothing calls this directly

Calls 4

queryAllMethod · 0.95
nowMethod · 0.80
pushMethod · 0.65
getComponentMethod · 0.45

Tested by

no test coverage detected