예제 #1
0
파일: Flock.cpp 프로젝트: Vondoe90/Seasons
void CFlock::UpdateBoidCollisions()
{
	if(!m_bc.avoidObstacles)
		return;
	const int numberOfChecks = 5;

	CTimeValue now = gEnv->pTimer->GetFrameStartTime();
	int checked = 0;

	// rough check
	if(m_BoidCollisionMap.size() != m_boids.size())
	{
		m_BoidCollisionMap.clear();
		for (Boids::iterator it = m_boids.begin(),itEnd = m_boids.end(); it != itEnd; ++it)
			m_BoidCollisionMap.insert(std::make_pair(now,*it));
	}

	for (TTimeBoidMap::iterator it = m_BoidCollisionMap.begin(),itEnd = m_BoidCollisionMap.end(); 
				it != itEnd && checked < numberOfChecks; ++it)
{
		CBoidObject* pBoid = it->second;
		if(pBoid && pBoid->ShouldUpdateCollisionInfo(now))
	{
			pBoid->UpdateCollisionInfo();
			m_BoidCollisionMap.erase(it);
			m_BoidCollisionMap.insert(std::make_pair(now,pBoid));
			it = m_BoidCollisionMap.begin();
			++checked;
		}
	}
}
예제 #2
0
파일: Flock.cpp 프로젝트: hybridsix/Code
void CFlock::UpdateBoidCollisions()
{
	if(!m_bc.avoidObstacles)
		return;
	const int numberOfChecks = 5;
	
	CTimeValue now = gEnv->pTimer->GetFrameStartTime();
	int checked = 0;

	// rough check
	if(m_BoidCollisionMap.size() != m_boids.size())
	{
		m_BoidCollisionMap.clear();
		m_BoidCollisionMap.reserve( m_boids.size() );

		for (Boids::iterator it = m_boids.begin(),itEnd = m_boids.end(); it != itEnd; ++it)
		{
			m_BoidCollisionMap.push_back( SBoidCollisionTime( now, *it ) );
		}

		std::sort( m_BoidCollisionMap.begin(), m_BoidCollisionMap.end(), FSortBoidByTime() );
	}
	
	for (TTimeBoidMap::iterator it = m_BoidCollisionMap.begin(),itEnd = m_BoidCollisionMap.end(); 
				it != itEnd && checked < numberOfChecks; ++it)
	{
		CBoidObject* pBoid = it->m_pBoid;
		if(pBoid && pBoid->ShouldUpdateCollisionInfo(now))
		{
			pBoid->UpdateCollisionInfo();
			it->m_time = now;
			++checked;
		}
	}	
	std::sort( m_BoidCollisionMap.begin(), m_BoidCollisionMap.end(), FSortBoidByTime() );
}