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

Method removeAllEntities

packages/core/src/ECS/Utils/EntityList.ts:88–118  ·  view source on GitHub ↗

* 移除所有实体 * Remove all entities * * 包括 buffer 中的实体和待添加队列中的实体。 * Includes entities in buffer and entities in pending add queue.

()

Source from the content-addressed store, hash-verified

86 * Includes entities in buffer and entities in pending add queue.
87 */
88 public removeAllEntities(): void {
89 const idsToRecycle: number[] = [];
90
91 // 销毁 buffer 中的实体
92 // Destroy entities in buffer
93 for (let i = this.buffer.length - 1; i >= 0; i--) {
94 idsToRecycle.push(this.buffer[i]!.id);
95 this.buffer[i]!.destroy();
96 }
97
98 // 销毁待添加队列中的实体(这些实体已创建但尚未加入 buffer)
99 // Destroy entities in pending add queue (created but not yet in buffer)
100 for (const entity of this._entitiesToAdd) {
101 idsToRecycle.push(entity.id);
102 entity.destroy();
103 }
104
105 // 批量回收 ID
106 // Recycle IDs in batch
107 if (this._scene && this._scene.identifierPool) {
108 for (const id of idsToRecycle) {
109 this._scene.identifierPool.checkIn(id);
110 }
111 }
112
113 this.buffer.length = 0;
114 this._idToEntity.clear();
115 this._nameToEntities.clear();
116 this._entitiesToAdd.length = 0;
117 this._entitiesToRemove.length = 0;
118 }
119
120 /**
121 * 更新实体列表,处理延迟操作

Callers 6

endMethod · 0.45
destroyAllEntitiesMethod · 0.45
EntityList.test.tsFile · 0.45
newSceneMethod · 0.45
enterPrefabEditModeMethod · 0.45
exitPrefabEditModeMethod · 0.45

Calls 4

pushMethod · 0.65
destroyMethod · 0.65
clearMethod · 0.65
checkInMethod · 0.45

Tested by

no test coverage detected