* 添加单个实体到查询系统 * * 将新实体添加到查询系统中,并自动更新相关索引。 * 为了提高批量添加性能,可以延迟缓存清理。 * * @param entity 要添加的实体 * @param deferCacheClear 是否延迟缓存清理(用于批量操作)
(entity: Entity, deferCacheClear: boolean = false)
| 104 | * @param deferCacheClear 是否延迟缓存清理(用于批量操作) |
| 105 | */ |
| 106 | public addEntity(entity: Entity, deferCacheClear: boolean = false): void { |
| 107 | if (!this._entities.includes(entity)) { |
| 108 | this._entities.push(entity); |
| 109 | this.addEntityToIndexes(entity); |
| 110 | |
| 111 | this._archetypeSystem.addEntity(entity); |
| 112 | |
| 113 | // 通知响应式查询 |
| 114 | this.notifyReactiveQueriesEntityAdded(entity); |
| 115 | |
| 116 | // 只有在非延迟模式下才立即清理缓存 |
| 117 | if (!deferCacheClear) { |
| 118 | this.clearQueryCache(); |
| 119 | } |
| 120 | |
| 121 | // 更新版本号 |
| 122 | this._version++; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * 批量添加实体 |
no test coverage detected