------------------------- UnifiedScene::AddEntity Add an entity to the ECS and resolve dependency links - set parent to INVALID_ENTITY_ID to indicate a root entity
| 210 | // - set parent to INVALID_ENTITY_ID to indicate a root entity |
| 211 | // |
| 212 | void UnifiedScene::AddEntity(EntityDescriptor const& entDesc, T_EntityId const parent) |
| 213 | { |
| 214 | T_EntityId const id = m_Scene.AddEntityChild(parent); |
| 215 | |
| 216 | // update all entity links referring to the assigned ID |
| 217 | EntityLinkResolver::Instance().OnEntityIdAssigned(entDesc.GetId(), id); |
| 218 | entDesc.SetAssignedId(id); |
| 219 | |
| 220 | // create a component data list |
| 221 | std::vector<RawComponentPtr> components; |
| 222 | for (I_ComponentDescriptor* const compDesc : entDesc.GetComponents()) |
| 223 | { |
| 224 | components.push_back(compDesc->MakeRawData()); |
| 225 | } |
| 226 | |
| 227 | // add the components to our new entity |
| 228 | // we copy the pointer list because the pointers are "repointed" to the constructed components, which doesn't allow us to free the original memory |
| 229 | m_Scene.AddComponents(id, std::vector<RawComponentPtr>(components)); |
| 230 | |
| 231 | // we can now free the memory of our raw component data - this needs to be done manually as we are using void* |
| 232 | for (RawComponentPtr& comp : components) |
| 233 | { |
| 234 | ComponentRegistry::Instance().GetFullDestructor(comp.typeIdx)(comp.data); |
| 235 | } |
| 236 | |
| 237 | components.clear(); |
| 238 | |
| 239 | // add the child entities |
| 240 | for (EntityDescriptor const& childDesc : entDesc.GetChildren()) |
| 241 | { |
| 242 | AddEntity(childDesc, id); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | //------------------------------ |
| 247 | // UnifiedScene::PostLoadEntity |
nothing calls this directly
no test coverage detected