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

Method addEntities

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

* 批量添加实体 * * 高效地批量添加多个实体,减少缓存清理次数。 * 使用Set来避免O(n)的重复检查。 * * @param entities 要添加的实体列表

(entities: Entity[])

Source from the content-addressed store, hash-verified

132 * @param entities 要添加的实体列表
133 */
134 public addEntities(entities: Entity[]): void {
135 if (entities.length === 0) return;
136
137 // 使用Set来快速检查重复
138 const existingIds = new Set(this._entities.map((e) => e.id));
139 let addedCount = 0;
140
141 for (const entity of entities) {
142 if (!existingIds.has(entity.id)) {
143 this._entities.push(entity);
144 this.addEntityToIndexes(entity);
145
146 // 更新索引管理器
147 this._archetypeSystem.addEntity(entity);
148
149 existingIds.add(entity.id);
150 addedCount++;
151 }
152 }
153
154 // 只在有实体被添加时才清理缓存
155 if (addedCount > 0) {
156 this.clearQueryCache();
157 }
158 }
159
160 /**
161 * 批量添加实体(无重复检查版本)

Callers 1

Calls 7

addEntityToIndexesMethod · 0.95
clearQueryCacheMethod · 0.95
hasMethod · 0.65
pushMethod · 0.65
addEntityMethod · 0.65
mapMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected