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

Method updateEntity

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

* 更新实体在查询系统中的索引 * * 当实体的组件组合发生变化时调用此方法,高效地更新实体在查询系统中的索引。 * * @param entity 要更新的实体

(entity: Entity)

Source from the content-addressed store, hash-verified

225 * @param entity 要更新的实体
226 */
227 public updateEntity(entity: Entity): void {
228 // 检查实体是否在查询系统中
229 if (!this._entities.includes(entity)) {
230 // 如果实体不在系统中,直接添加
231 this.addEntity(entity);
232 return;
233 }
234
235 // 先从索引中移除实体的旧状态
236 this.removeEntityFromIndexes(entity);
237
238 // 更新ArchetypeSystem中的实体状态
239 this._archetypeSystem.updateEntity(entity);
240 // 重新添加实体到索引(基于新的组件状态)
241 this.addEntityToIndexes(entity);
242
243 // 通知响应式查询
244 this.notifyReactiveQueriesEntityChanged(entity);
245
246 // 清理查询缓存,因为实体组件状态已改变
247 this.clearQueryCache();
248
249 // 更新版本号以使缓存失效
250 this._version++;
251 }
252
253 /**
254 * 将实体添加到各种索引中

Callers 2

notifyQuerySystemsMethod · 0.45

Calls 5

addEntityMethod · 0.95
addEntityToIndexesMethod · 0.95
clearQueryCacheMethod · 0.95

Tested by

no test coverage detected