bool CEntityPool::CreatePoolEntity(CEntity* &pOutEntity, bool bAddToInactiveList) { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(!gEnv->IsEditor()); MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, EMemStatContextFlags::MSF_Instance, "Create Pool Entity"); bool bResult = false; assert(m_pEntityPoolManager); CEntitySystem* pEntitySystem = m_pEntityPoolManager->GetEntitySystem(); if (pEntitySystem) { SEntitySpawnParams params; CreateSpawnParams(params); params.vScale.Set(1.0f,1.0f,1.0f); CEntity* pEntity = (CEntity*)pEntitySystem->SpawnEntity(params); if (pEntity) { pEntity->SetPoolControl(true); // Put into map if (bAddToInactiveList) { const EntityId poolId = pEntity->GetId(); stl::push_back_unique(m_InactivePoolIds, poolId); } pOutEntity = pEntity; bResult = true; } } return bResult; }
bool CEntityPool::DestroyPoolEntity(EntityId entityId) const { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(!gEnv->IsEditor()); bool bResult = false; // Set the entity as garbage so it can be deleted CEntity* pEntity = (CEntity*)gEnv->pEntitySystem->GetEntity(entityId); if (pEntity && ContainsEntity(entityId)) { assert(pEntity->IsPoolControlled()); pEntity->ClearFlags(ENTITY_FLAG_UNREMOVABLE); pEntity->SetPoolControl(false); gEnv->pEntitySystem->RemoveEntity(entityId, true); bResult = true; } return bResult; }