Ejemplo n.º 1
0
CEntityLayer::~CEntityLayer()
{
	for (TEntityProps::iterator it = m_entities.begin(); it != m_entities.end(); ++it)
	{
		CEntity* pEntity = (CEntity*) (g_pIEntitySystem->GetEntityFromID(it->first));
		if (!pEntity)
			continue;
		if (it->second.m_bIsNoAwake && pEntity->GetPhysicalProxy() && pEntity->GetPhysicalProxy()->GetPhysicalEntity())
		{
			pe_action_awake aa;
			aa.bAwake = false;
			pEntity->GetPhysicalProxy()->GetPhysicalEntity()->Action(&aa);
		}
		it->second.m_bIsNoAwake = false;
	}

	if (m_pHeap)
		m_pGarbageHeaps->push_back(SEntityLayerGarbage(m_pHeap, m_name));
}
Ejemplo n.º 2
0
void CEntityLayer::EnableEntities( bool isEnable )
{
	if (m_isEnabled != isEnable)
	{
		m_isEnabled = isEnable;

		if (isEnable)
		{
			if (gEnv->pRenderer)
			{
				gEnv->pRenderer->ActivateLayer(m_name.c_str(), isEnable); // Want flash instances on materials activated before entities
			}
		}

		// activate static lights but not brushes
		gEnv->p3DEngine->ActivateObjectsLayer(m_id, isEnable, m_havePhysics, false, true, m_name.c_str(), m_pHeap);

		pe_action_awake noAwake;
		noAwake.bAwake = false;

		for (TEntityProps::iterator it = m_entities.begin(); it != m_entities.end(); ++it)
		{
			EntityProp &prop = it->second;

			CEntity* pEntity = (CEntity*) (g_pIEntitySystem->GetEntityFromID(prop.m_id));

			if (!pEntity)
				continue;

			// when is serializing (reading, as we never call this on writing), we dont want to change those values. we just use the values that come directly from serialization.
			if (!isEnable && !gEnv->pSystem->IsSerializingFile())
			{
				prop.m_bIsHidden = pEntity->IsHidden();
				prop.m_bIsActive = pEntity->IsActive();
			}

			if (prop.m_bIsHidden)
				continue;

			if (isEnable)
			{
				pEntity->Hide(!isEnable);
				pEntity->Activate(prop.m_bIsActive);

				if (prop.m_bIsNoAwake && pEntity->GetPhysicalProxy() && pEntity->GetPhysicalProxy()->GetPhysicalEntity())
					pEntity->GetPhysicalProxy()->GetPhysicalEntity()->Action(&noAwake);

				prop.m_bIsNoAwake = false;

				SEntityEvent event;
				event.nParam[0] = 1;
				static IEntityClass* pConstraintClass = g_pIEntitySystem->GetClassRegistry()->FindClass("Constraint");
				if (pConstraintClass && pEntity->GetClass() == pConstraintClass)
				{
					event.event = ENTITY_EVENT_RESET;
					pEntity->SendEvent(event);
					event.event = ENTITY_EVENT_LEVEL_LOADED;
					pEntity->SendEvent(event);
				}
				if (!m_wasReEnabled && pEntity->GetPhysics() && pEntity->GetPhysics()->GetType() == PE_ROPE)
				{
					event.event = ENTITY_EVENT_LEVEL_LOADED;
					pEntity->SendEvent(event);
				}
			}
			else
			{
				prop.m_bIsNoAwake = false;
				CPhysicalProxy* pPhProxy = pEntity->GetPhysicalProxy();
				if (pPhProxy)
				{
					pe_status_awake  isawake;
					IPhysicalEntity* pPhEnt = pPhProxy->GetPhysicalEntity();
					if (pPhEnt && pPhEnt->GetStatus(&isawake) == 0)
						prop.m_bIsNoAwake = true;
				}
				pEntity->Hide(!isEnable);
				pEntity->Activate(isEnable);
				if (prop.m_bIsNoAwake && pEntity->GetPhysicalProxy() && pEntity->GetPhysicalProxy()->GetPhysicalEntity())
					pEntity->GetPhysicalProxy()->GetPhysicalEntity()->Action(&noAwake);
			}
		}

		if (!isEnable)
		{
			if (gEnv->pRenderer)
			{
				gEnv->pRenderer->ActivateLayer(m_name.c_str(), isEnable); // Want flash instances on materials deactivated after entities
			}
		}
		else
			m_wasReEnabled = true;
	}

	ReEvalNeedForHeap();
}