2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
2022-01-06 23:37:49 +01:00
|
|
|
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LinearMath/btScalar.h"
|
|
|
|
#include "btSimulationIslandManager.h"
|
|
|
|
#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
|
|
|
|
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
|
|
|
|
|
|
|
//#include <stdio.h>
|
|
|
|
#include "LinearMath/btQuickprof.h"
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimulationIslandManager::btSimulationIslandManager() : m_splitIslands(true)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
btSimulationIslandManager::~btSimulationIslandManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void btSimulationIslandManager::initUnionFind(int n)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
m_unionFind.reset(n);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */, btCollisionWorld* colWorld)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
btOverlappingPairCache* pairCachePtr = colWorld->getPairCache();
|
|
|
|
const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs();
|
|
|
|
if (numOverlappingPairs)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr();
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int i = 0; i < numOverlappingPairs; i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
const btBroadphasePair& collisionPair = pairPtr[i];
|
|
|
|
btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
|
|
|
|
btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
|
|
|
|
((colObj1) && ((colObj1)->mergesSimulationIslands())))
|
|
|
|
{
|
|
|
|
m_unionFind.unite((colObj0)->getIslandTag(),
|
|
|
|
(colObj1)->getIslandTag());
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld, btDispatcher* dispatcher)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// put the index into m_controllers into m_tag
|
2017-08-01 14:30:58 +02:00
|
|
|
int index = 0;
|
|
|
|
{
|
|
|
|
int i;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
|
2017-08-01 14:30:58 +02:00
|
|
|
//Adding filtering here
|
|
|
|
if (!collisionObject->isStaticOrKinematicObject())
|
|
|
|
{
|
|
|
|
collisionObject->setIslandTag(index++);
|
|
|
|
}
|
|
|
|
collisionObject->setCompanionId(-1);
|
|
|
|
collisionObject->setHitFraction(btScalar(1.));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// do the union find
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
initUnionFind(index);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
findUnions(dispatcher, colWorld);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// put the islandId ('find' value) into m_tag
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
int i;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
|
2017-08-01 14:30:58 +02:00
|
|
|
if (!collisionObject->isStaticOrKinematicObject())
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
collisionObject->setIslandTag(m_unionFind.find(index));
|
2017-08-01 14:30:58 +02:00
|
|
|
//Set the correct object offset in Collision Object Array
|
|
|
|
m_unionFind.getElement(index).m_sz = i;
|
|
|
|
collisionObject->setCompanionId(-1);
|
|
|
|
index++;
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
collisionObject->setIslandTag(-1);
|
|
|
|
collisionObject->setCompanionId(-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#else //STATIC_SIMULATION_ISLAND_OPTIMIZATION
|
|
|
|
void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld, btDispatcher* dispatcher)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
initUnionFind(int(colWorld->getCollisionObjectArray().size()));
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
// put the index into m_controllers into m_tag
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
int i;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
|
2017-08-01 14:30:58 +02:00
|
|
|
collisionObject->setIslandTag(index);
|
|
|
|
collisionObject->setCompanionId(-1);
|
|
|
|
collisionObject->setHitFraction(btScalar(1.));
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// do the union find
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
findUnions(dispatcher, colWorld);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// put the islandId ('find' value) into m_tag
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
int i;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
|
2017-08-01 14:30:58 +02:00
|
|
|
if (!collisionObject->isStaticOrKinematicObject())
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
collisionObject->setIslandTag(m_unionFind.find(index));
|
2017-08-01 14:30:58 +02:00
|
|
|
collisionObject->setCompanionId(-1);
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
collisionObject->setIslandTag(-1);
|
|
|
|
collisionObject->setCompanionId(-2);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
inline int getIslandId(const btPersistentManifold* lhs)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int islandId;
|
|
|
|
const btCollisionObject* rcolObj0 = static_cast<const btCollisionObject*>(lhs->getBody0());
|
|
|
|
const btCollisionObject* rcolObj1 = static_cast<const btCollisionObject*>(lhs->getBody1());
|
2019-01-03 14:26:51 +01:00
|
|
|
islandId = rcolObj0->getIslandTag() >= 0 ? rcolObj0->getIslandTag() : rcolObj1->getIslandTag();
|
2017-08-01 14:30:58 +02:00
|
|
|
return islandId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// function object that routes calls to operator<
|
|
|
|
class btPersistentManifoldSortPredicate
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
public:
|
|
|
|
SIMD_FORCE_INLINE bool operator()(const btPersistentManifold* lhs, const btPersistentManifold* rhs) const
|
|
|
|
{
|
|
|
|
return getIslandId(lhs) < getIslandId(rhs);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
|
2018-09-07 16:11:04 +02:00
|
|
|
class btPersistentManifoldSortPredicateDeterministic
|
|
|
|
{
|
|
|
|
public:
|
2019-01-03 14:26:51 +01:00
|
|
|
SIMD_FORCE_INLINE bool operator()(const btPersistentManifold* lhs, const btPersistentManifold* rhs) const
|
2018-09-07 16:11:04 +02:00
|
|
|
{
|
|
|
|
return (
|
2019-01-03 14:26:51 +01:00
|
|
|
(getIslandId(lhs) < getIslandId(rhs)) || ((getIslandId(lhs) == getIslandId(rhs)) && lhs->getBody0()->getBroadphaseHandle()->m_uniqueId < rhs->getBody0()->getBroadphaseHandle()->m_uniqueId) || ((getIslandId(lhs) == getIslandId(rhs)) && (lhs->getBody0()->getBroadphaseHandle()->m_uniqueId == rhs->getBody0()->getBroadphaseHandle()->m_uniqueId) && (lhs->getBody1()->getBroadphaseHandle()->m_uniqueId < rhs->getBody1()->getBroadphaseHandle()->m_uniqueId)));
|
2018-09-07 16:11:04 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
BT_PROFILE("islandUnionFindAndQuickSort");
|
2019-01-03 14:26:51 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
|
|
|
|
|
|
|
|
m_islandmanifold.resize(0);
|
|
|
|
|
|
|
|
//we are going to sort the unionfind array, and store the element id in the size
|
|
|
|
//afterwards, we clean unionfind, to make sure no-one uses it anymore
|
2019-01-03 14:26:51 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
getUnionFind().sortIslands();
|
|
|
|
int numElem = getUnionFind().getNumElements();
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int endIslandIndex = 1;
|
2017-08-01 14:30:58 +02:00
|
|
|
int startIslandIndex;
|
|
|
|
|
|
|
|
//update the sleeping state for bodies, if all are sleeping
|
2019-01-03 14:26:51 +01:00
|
|
|
for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int islandId = getUnionFind().getElement(startIslandIndex).m_id;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (endIslandIndex = startIslandIndex + 1; (endIslandIndex < numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId); endIslandIndex++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//int numSleeping = 0;
|
|
|
|
|
|
|
|
bool allSleeping = true;
|
|
|
|
|
|
|
|
int idx;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (idx = startIslandIndex; idx < endIslandIndex; idx++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int i = getUnionFind().getElement(idx).m_sz;
|
|
|
|
|
|
|
|
btCollisionObject* colObj0 = collisionObjects[i];
|
|
|
|
if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// printf("error in island management\n");
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-08 18:05:43 +01:00
|
|
|
btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
|
2017-08-01 14:30:58 +02:00
|
|
|
if (colObj0->getIslandTag() == islandId)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (colObj0->getActivationState() == ACTIVE_TAG ||
|
|
|
|
colObj0->getActivationState() == DISABLE_DEACTIVATION)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
allSleeping = false;
|
2018-09-07 16:11:04 +02:00
|
|
|
break;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allSleeping)
|
|
|
|
{
|
|
|
|
int idx;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (idx = startIslandIndex; idx < endIslandIndex; idx++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int i = getUnionFind().getElement(idx).m_sz;
|
|
|
|
btCollisionObject* colObj0 = collisionObjects[i];
|
|
|
|
if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// printf("error in island management\n");
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-08 18:05:43 +01:00
|
|
|
btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
if (colObj0->getIslandTag() == islandId)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
colObj0->setActivationState(ISLAND_SLEEPING);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int idx;
|
2019-01-03 14:26:51 +01:00
|
|
|
for (idx = startIslandIndex; idx < endIslandIndex; idx++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int i = getUnionFind().getElement(idx).m_sz;
|
|
|
|
|
|
|
|
btCollisionObject* colObj0 = collisionObjects[i];
|
|
|
|
if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
// printf("error in island management\n");
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2020-01-08 18:05:43 +01:00
|
|
|
btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
|
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
if (colObj0->getIslandTag() == islandId)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (colObj0->getActivationState() == ISLAND_SLEEPING)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
colObj0->setActivationState(WANTS_DEACTIVATION);
|
2017-08-01 14:30:58 +02:00
|
|
|
colObj0->setDeactivationTime(0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int maxNumManifolds = dispatcher->getNumManifolds();
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
//#define SPLIT_ISLANDS 1
|
|
|
|
//#ifdef SPLIT_ISLANDS
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
//#endif //SPLIT_ISLANDS
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (i = 0; i < maxNumManifolds; i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
|
|
|
|
if (collisionWorld->getDispatchInfo().m_deterministicOverlappingPairs)
|
|
|
|
{
|
2018-09-07 16:11:04 +02:00
|
|
|
if (manifold->getNumContacts() == 0)
|
|
|
|
continue;
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2018-09-07 16:11:04 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
|
|
|
|
const btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
|
|
|
|
|
|
|
|
///@todo: check sleeping conditions!
|
|
|
|
if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
|
2017-08-01 14:30:58 +02:00
|
|
|
((colObj1) && colObj1->getActivationState() != ISLAND_SLEEPING))
|
|
|
|
{
|
|
|
|
//kinematic objects don't merge islands, but wake up all connected objects
|
|
|
|
if (colObj0->isKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING)
|
|
|
|
{
|
|
|
|
if (colObj0->hasContactResponse())
|
|
|
|
colObj1->activate();
|
|
|
|
}
|
|
|
|
if (colObj1->isKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING)
|
|
|
|
{
|
|
|
|
if (colObj1->hasContactResponse())
|
|
|
|
colObj0->activate();
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_splitIslands)
|
|
|
|
{
|
2017-08-01 14:30:58 +02:00
|
|
|
//filtering for response
|
2019-01-03 14:26:51 +01:00
|
|
|
if (dispatcher->needsResponse(colObj0, colObj1))
|
2017-08-01 14:30:58 +02:00
|
|
|
m_islandmanifold.push_back(manifold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 18:05:43 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
///@todo: this is random access, it can be walked 'cache friendly'!
|
2019-01-03 14:26:51 +01:00
|
|
|
void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
buildIslands(dispatcher, collisionWorld);
|
2020-01-08 18:05:43 +01:00
|
|
|
processIslands(dispatcher, collisionWorld, callback);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2020-01-08 18:05:43 +01:00
|
|
|
void btSimulationIslandManager::processIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback)
|
|
|
|
{
|
|
|
|
btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
|
2019-01-03 14:26:51 +01:00
|
|
|
int endIslandIndex = 1;
|
2017-08-01 14:30:58 +02:00
|
|
|
int startIslandIndex;
|
|
|
|
int numElem = getUnionFind().getNumElements();
|
|
|
|
|
|
|
|
BT_PROFILE("processIslands");
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!m_splitIslands)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
|
|
|
|
int maxNumManifolds = dispatcher->getNumManifolds();
|
2019-01-03 14:26:51 +01:00
|
|
|
callback->processIsland(&collisionObjects[0], collisionObjects.size(), manifold, maxNumManifolds, -1);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Sort manifolds, based on islands
|
|
|
|
// Sort the vector using predicate and std::sort
|
|
|
|
//std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int numManifolds = int(m_islandmanifold.size());
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
//tried a radix sort, but quicksort/heapsort seems still faster
|
|
|
|
//@todo rewrite island management
|
2018-09-07 16:11:04 +02:00
|
|
|
//btPersistentManifoldSortPredicateDeterministic sorts contact manifolds based on islandid,
|
|
|
|
//but also based on object0 unique id and object1 unique id
|
|
|
|
if (collisionWorld->getDispatchInfo().m_deterministicOverlappingPairs)
|
|
|
|
{
|
|
|
|
m_islandmanifold.quickSort(btPersistentManifoldSortPredicateDeterministic());
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
2018-09-07 16:11:04 +02:00
|
|
|
{
|
|
|
|
m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
|
|
|
|
}
|
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
//m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
|
|
|
|
|
|
|
|
//now process all active islands (sets of manifolds for now)
|
|
|
|
|
|
|
|
int startManifoldIndex = 0;
|
|
|
|
int endManifoldIndex = 1;
|
|
|
|
|
|
|
|
//int islandId;
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
// printf("Start Islands\n");
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
//traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
|
2019-01-03 14:26:51 +01:00
|
|
|
for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int islandId = getUnionFind().getElement(startIslandIndex).m_id;
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
bool islandSleeping = true;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (endIslandIndex = startIslandIndex; (endIslandIndex < numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId); endIslandIndex++)
|
|
|
|
{
|
|
|
|
int i = getUnionFind().getElement(endIslandIndex).m_sz;
|
|
|
|
btCollisionObject* colObj0 = collisionObjects[i];
|
|
|
|
m_islandBodies.push_back(colObj0);
|
|
|
|
if (colObj0->isActive())
|
|
|
|
islandSleeping = false;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
//find the accompanying contact manifold for this islandId
|
|
|
|
int numIslandManifolds = 0;
|
|
|
|
btPersistentManifold** startManifold = 0;
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (startManifoldIndex < numManifolds)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]);
|
|
|
|
if (curIslandId == islandId)
|
|
|
|
{
|
|
|
|
startManifold = &m_islandmanifold[startManifoldIndex];
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (endManifoldIndex = startManifoldIndex + 1; (endManifoldIndex < numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex])); endManifoldIndex++)
|
|
|
|
{
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
/// Process the actual simulation, only if not sleeping/deactivated
|
2019-01-03 14:26:51 +01:00
|
|
|
numIslandManifolds = endManifoldIndex - startManifoldIndex;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!islandSleeping)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
callback->processIsland(&m_islandBodies[0], m_islandBodies.size(), startManifold, numIslandManifolds, islandId);
|
|
|
|
// printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
if (numIslandManifolds)
|
|
|
|
{
|
|
|
|
startManifoldIndex = endManifoldIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_islandBodies.resize(0);
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
} // else if(!splitIslands)
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|