Beispiel #1
0
void	btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) 
{
	//m_blockedForChanges = true;

	btCollisionPairCallback	collisionCallback(dispatchInfo,this);

	pairCache->processAllOverlappingPairs(&collisionCallback,dispatcher);

	//m_blockedForChanges = false;

}
void	SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo, btDispatcher* dispatcher) 
{

	if (dispatchInfo.m_enableSPU)
	{
		m_maxNumOutstandingTasks = m_threadInterface->getNumTasks();

		{
			BT_PROFILE("processAllOverlappingPairs");

			if (!m_spuCollisionTaskProcess)
				m_spuCollisionTaskProcess = new SpuCollisionTaskProcess(m_threadInterface,m_maxNumOutstandingTasks);
		
			m_spuCollisionTaskProcess->setNumTasks(m_maxNumOutstandingTasks);
	//		printf("m_maxNumOutstandingTasks =%d\n",m_maxNumOutstandingTasks);

			m_spuCollisionTaskProcess->initialize2(dispatchInfo.m_useEpa);
			
		
			///modified version of btCollisionDispatcher::dispatchAllCollisionPairs:
			{
				btSpuCollisionPairCallback	collisionCallback(dispatchInfo,this);

				pairCache->processAllOverlappingPairs(&collisionCallback,dispatcher);
			}
		}

		//send one big batch
		int numTotalPairs = pairCache->getNumOverlappingPairs();
		if (numTotalPairs)
		{
			btBroadphasePair* pairPtr = pairCache->getOverlappingPairArrayPtr();
			int i;
			{
				int pairRange =	SPU_BATCHSIZE_BROADPHASE_PAIRS;
				if (numTotalPairs < (m_spuCollisionTaskProcess->getNumTasks()*SPU_BATCHSIZE_BROADPHASE_PAIRS))
				{
					pairRange = (numTotalPairs/m_spuCollisionTaskProcess->getNumTasks())+1;
				}
	
				BT_PROFILE("addWorkToTask");
				for (i=0;i<numTotalPairs;)
				{
					//Performance Hint: tweak this number during benchmarking
					
					int endIndex = (i+pairRange) < numTotalPairs ? i+pairRange : numTotalPairs;
					m_spuCollisionTaskProcess->addWorkToTask(pairPtr,i,endIndex);
					i = endIndex;
				}
			}
			{
				BT_PROFILE("PPU fallback");
				//handle PPU fallback pairs
				for (i=0;i<numTotalPairs;i++)
				{
					btBroadphasePair& collisionPair = pairPtr[i];
					if (collisionPair.m_internalTmpValue == 3)
					{
						if (collisionPair.m_algorithm)
						{
							btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
							btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
	
							if (dispatcher->needsCollision(colObj0,colObj1))
							{
							//discrete collision detection query
								btCollisionObjectWrapper ob0(0,colObj0->getCollisionShape(),colObj0,colObj0->getWorldTransform());
								btCollisionObjectWrapper ob1(0,colObj1->getCollisionShape(),colObj1,colObj1->getWorldTransform());

								btManifoldResult contactPointResult(&ob0,&ob1);
								
								if (dispatchInfo.m_dispatchFunc == 		btDispatcherInfo::DISPATCH_DISCRETE)
								{
									
									collisionPair.m_algorithm->processCollision(&ob0,&ob1,dispatchInfo,&contactPointResult);
								} else
								{
									//continuous collision detection query, time of impact (toi)
									btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
									if (dispatchInfo.m_timeOfImpact > toi)
										dispatchInfo.m_timeOfImpact = toi;
	
								}
							}
						}
					}
				}
			}
		}
		{
			BT_PROFILE("flush2");
			//make sure all SPU work is done
			m_spuCollisionTaskProcess->flush2();
		}

	} else
	{
		///PPU fallback
		///!Need to make sure to clear all 'algorithms' when switching between SPU and PPU
		btCollisionDispatcher::dispatchAllCollisionPairs(pairCache,dispatchInfo,dispatcher);
	}
}
void btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) 
{
    btCollisionPairCallback collisionCallback(dispatchInfo,this);
    pairCache->processAllOverlappingPairs(&collisionCallback,dispatcher);
}