* 查询自指定 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[])
| 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 | * 按单个组件类型查询实体 |
nothing calls this directly
no test coverage detected