Beispiel #1
0
void CFlock::DeleteEntities( bool bForceDeleteAll )
{
	if (m_pEntity)
	{
		IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)m_pEntity->GetProxy(ENTITY_PROXY_RENDER);
		if (pRenderProxy)
			pRenderProxy->ClearSlots();
	}

	I3DEngine *engine = gEnv->p3DEngine;
	for (Boids::iterator it = m_boids.begin(); it != m_boids.end(); ++it)
	{
		CBoidObject* boid = *it;

		if (boid->m_pickedUp && !bForceDeleteAll) // Do not delete picked up boids.
			continue;

		//		SAFE_RELEASE(boid->m_object);
		boid->m_object = 0;
		boid->m_noentity = true;
		if (boid->m_entity)
		{
			// Delete entity.

			IEntity *pBoidEntity = gEnv->pEntitySystem->GetEntity(boid->m_entity);
			if (pBoidEntity)
			{
				CBoidObjectProxy *pBoidObjectProxy = static_cast<CBoidObjectProxy *>(pBoidEntity->GetProxy(ENTITY_PROXY_BOID_OBJECT));
/*			Luciano: old code did this (without getting the existing boid object proxy first), not sure why
				if(!pBoidObjectProxy)
				{
					pBoidObjectProxy = new CBoidObjectProxy(pBoidEntity);
				pBoidEntity->SetProxy(ENTITY_PROXY_BOID_OBJECT,pBoidObjectProxy);
				}*/

				if (pBoidObjectProxy)
					pBoidObjectProxy->SetBoid(0);
			}

			gEnv->pEntitySystem->RemoveEntity(boid->m_entity);

			boid->m_entity = 0;
			boid->m_pPhysics = 0;
			boid->m_physicsControlled = false;
		}
	}
	m_bEntityCreated = false;
}
Beispiel #2
0
void CBugsFlock::CreateBoids( SBoidsCreateContext &ctx )
{
	CFlock::CreateBoids(ctx);
	
	int i;

	if (!m_e_flocks)
		return;

	if (m_pEntity)
	{
		IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)m_pEntity->GetProxy(ENTITY_PROXY_RENDER);
		if (pRenderProxy)
			pRenderProxy->ClearSlots();
	}

	// Different boids.
	for (i = 0; i < ctx.boidsCount; i++)
	{
		CBoidBug *boid = new CBoidBug( m_bc );
		float radius = m_bc.fSpawnRadius;
		boid->m_pos = m_origin + Vec3(radius*Boid::Frand(),radius*Boid::Frand(),
			m_bc.MinHeight+(m_bc.MaxHeight-m_bc.MinHeight)*Boid::Frand() );

		boid->m_heading = Vec3(Boid::Frand(),Boid::Frand(),0).GetNormalized();
		boid->m_speed = m_bc.MinSpeed + (m_bc.MaxSpeed-m_bc.MinSpeed)*Boid::Frand();
		boid->m_scale = m_bc.boidScale + Boid::Frand()*m_bc.boidRandomScale;

		/*
		//boid->CalcRandomTarget( GetPos(),m_bc );
		if (!ctx.characterModel.empty())
		{
			if (numObj == 0 || (i % (numObj+1) == 0))
			{
				m_pEntity->LoadCharacter( i,ctx.characterModel );
				boid->m_object = m_pEntity->GetCharacter(i);
				if (boid->m_object)
				{
					AABB aabb=boid->m_object->GetAABB();
					bbox.Add( aabb.min );
					bbox.Add( aabb.max );
					if (!ctx.animation.empty())
					{
						CryCharAnimationParams animParams;
						animParams.m_nFlags |= CA_REMOVE_FROM_FIFO;

						// Play animation in loop.
						boid->m_object->GetISkeleton()->StartAnimation( ctx.animation.c_str(),0, 0,0,  animParams );
						IAnimationSet* animSet = boid->m_object->GetIAnimationSet();
						if (animSet)
						{
							//Ivo: this is an animation flag in the new system
							//boid->m_object->SetLoop( ctx.animation.c_str(), true, 0 );
						}
					}
				}
			}
		}
	
		if (numObj > 0)
			boid->m_objectId = (i % numObj);
		else
			boid->m_objectId = 0;

		if (!boid->m_object)
		{
			m_pEntity->LoadGeometry( i,ctx.models[boid->m_objectId] );
		}
		*/

		//boid->m_p = gEnv->p3DEngine->MakeCharacter( model.c_str() );
		/*
		if (boid->m_object)
		{
			boid->Physicalize(m_bc);
		}
		*/
		AddBoid(boid);
	}
}