* 移除所有实体 * Remove all entities * * 包括 buffer 中的实体和待添加队列中的实体。 * Includes entities in buffer and entities in pending add queue.
()
| 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 | * 更新实体列表,处理延迟操作 |
no test coverage detected