----------------------------- EcsController::AddComponent Add a list of components to an entity
| 315 | // Add a list of components to an entity |
| 316 | // |
| 317 | void EcsController::AddComponents(T_EntityId const entity, std::vector<RawComponentPtr>& components) |
| 318 | { |
| 319 | // get referred entity |
| 320 | EntityData& ent = m_Entities[entity]; |
| 321 | |
| 322 | std::vector<RawComponentPtr> currentComponents; |
| 323 | T_CompTypeList compTypes = GetComponentsAndTypes(ent, currentComponents); |
| 324 | |
| 325 | // add the new components |
| 326 | for (RawComponentPtr const& comp : components) |
| 327 | { |
| 328 | compTypes.emplace_back(comp.typeIdx); |
| 329 | currentComponents.emplace_back(comp); |
| 330 | } |
| 331 | |
| 332 | MoveArchetype(entity, ent, compTypes, currentComponents); |
| 333 | |
| 334 | // reassign the component pointers and emit component add events |
| 335 | for (RawComponentPtr& comp : components) |
| 336 | { |
| 337 | comp.data = ent.archetype->GetPool(comp.typeIdx).At(ent.index); |
| 338 | m_ComponentEvents[comp.typeIdx].Notify(detail::E_EcsEvent::Added, new detail::ComponentEventData(this, comp.data, entity)); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | //--------------------------------- |
| 343 | // EcsController::RemoveComponents |