27 int initialAllocatedSize = 2;
28 m_overlappingPairArray.reserve(initialAllocatedSize);
32btHashedOverlappingPairCache::~btHashedOverlappingPairCache()
38 if (pair.m_algorithm && dispatcher)
41 pair.m_algorithm->~btCollisionAlgorithm();
48void btHashedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy,
btDispatcher* dispatcher)
52 btBroadphaseProxy* m_cleanProxy;
58 : m_cleanProxy(cleanProxy),
59 m_pairCache(pairCache),
65 if ((pair.m_pProxy0 == m_cleanProxy) ||
66 (pair.m_pProxy1 == m_cleanProxy))
74 CleanPairCallback cleanPairs(proxy,
this, dispatcher);
79void btHashedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,
btDispatcher* dispatcher)
83 btBroadphaseProxy* m_obsoleteProxy;
86 RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
87 : m_obsoleteProxy(obsoleteProxy)
92 return ((pair.m_pProxy0 == m_obsoleteProxy) ||
93 (pair.m_pProxy1 == m_obsoleteProxy));
97 RemovePairCallback removeCallback(proxy);
102btBroadphasePair* btHashedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
104 if (proxy0->m_uniqueId > proxy1->m_uniqueId)
106 int proxyId1 = proxy0->getUid();
107 int proxyId2 = proxy1->getUid();
112 int hash =
static_cast<int>(getHash(
static_cast<unsigned int>(proxyId1),
static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
120 while (index !=
BT_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyId1, proxyId2) ==
false)
130 btAssert(index < m_overlappingPairArray.size());
132 return &m_overlappingPairArray[index];
137void btHashedOverlappingPairCache::growTables()
139 int newCapacity = m_overlappingPairArray.capacity();
151 for (i = 0; i < newCapacity; ++i)
155 for (i = 0; i < newCapacity; ++i)
160 for (i = 0; i < curHashtableSize; i++)
163 int proxyId1 = pair.m_pProxy0->getUid();
164 int proxyId2 = pair.m_pProxy1->getUid();
167 int hashValue =
static_cast<int>(getHash(
static_cast<unsigned int>(proxyId1),
static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
174btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
176 if (proxy0->m_uniqueId > proxy1->m_uniqueId)
178 int proxyId1 = proxy0->getUid();
179 int proxyId2 = proxy1->getUid();
184 int hash =
static_cast<int>(getHash(
static_cast<unsigned int>(proxyId1),
static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
200 int count = m_overlappingPairArray.size();
201 int oldCapacity = m_overlappingPairArray.capacity();
202 void* mem = &m_overlappingPairArray.expandNonInitializing();
208 int newCapacity = m_overlappingPairArray.capacity();
210 if (oldCapacity < newCapacity)
214 hash =
static_cast<int>(getHash(
static_cast<unsigned int>(proxyId1),
static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
220 pair->m_algorithm = 0;
221 pair->m_internalTmpValue = 0;
229void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,
btDispatcher* dispatcher)
231 if (proxy0->m_uniqueId > proxy1->m_uniqueId)
233 int proxyId1 = proxy0->getUid();
234 int proxyId2 = proxy1->getUid();
239 int hash =
static_cast<int>(getHash(
static_cast<unsigned int>(proxyId1),
static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
249 void* userData = pair->m_internalInfo1;
251 btAssert(pair->m_pProxy0->getUid() == proxyId1);
252 btAssert(pair->m_pProxy1->getUid() == proxyId2);
254 int pairIndex =
int(pair - &m_overlappingPairArray[0]);
255 btAssert(pairIndex < m_overlappingPairArray.size());
262 while (index != pairIndex)
282 int lastPairIndex = m_overlappingPairArray.
size() - 1;
288 if (lastPairIndex == pairIndex)
290 m_overlappingPairArray.pop_back();
297 int lastHash =
static_cast<int>(getHash(
static_cast<unsigned int>(last->m_pProxy0->getUid()),
static_cast<unsigned int>(last->m_pProxy1->getUid())) & (m_overlappingPairArray.capacity() - 1));
303 while (index != lastPairIndex)
320 m_overlappingPairArray[pairIndex] = m_overlappingPairArray[lastPairIndex];
334 BT_PROFILE(
"btHashedOverlappingPairCache::processAllOverlappingPairs");
338 for (i = 0; i < m_overlappingPairArray.size();)
341 if (
callback->processOverlap(*pair))
364 const int uidA0 = a.m_uidA0;
365 const int uidB0 =
b.m_uidA0;
366 const int uidA1 = a.m_uidA1;
367 const int uidB1 =
b.m_uidA1;
368 return uidA0 > uidB0 || (uidA0 == uidB0 && uidA1 > uidB1);
380 indices.resize(pa.
size());
381 for (
int i = 0; i < indices.size(); i++)
384 const int uidA0 = p.m_pProxy0 ? p.m_pProxy0->m_uniqueId : -1;
385 const int uidA1 = p.m_pProxy1 ? p.m_pProxy1->m_uniqueId : -1;
387 indices[i].m_uidA0 = uidA0;
388 indices[i].m_uidA1 = uidA1;
389 indices[i].m_orgIndex = i;
394 BT_PROFILE(
"btHashedOverlappingPairCache::processAllOverlappingPairs");
396 for (i = 0; i < indices.size();)
399 if (
callback->processOverlap(*pair))
416void btHashedOverlappingPairCache::sortOverlappingPairs(
btDispatcher* dispatcher)
421 for (i = 0; i < m_overlappingPairArray.size(); i++)
423 tmpPairs.
push_back(m_overlappingPairArray[i]);
426 for (i = 0; i < tmpPairs.
size(); i++)
438 for (i = 0; i < tmpPairs.
size(); i++)
444void* btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,
btDispatcher* dispatcher)
446 if (!hasDeferredRemoval())
451 if (findIndex < m_overlappingPairArray.
size())
454 void* userData = pair.m_internalInfo1;
455 cleanOverlappingPair(pair, dispatcher);
456 if (m_ghostPairCallback)
459 m_overlappingPairArray.
swap(findIndex, m_overlappingPairArray.
capacity() - 1);
468btBroadphasePair* btSortedOverlappingPairCache::addOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
473 if (!needsBroadphaseCollision(proxy0, proxy1))
479 if (m_ghostPairCallback)
488btBroadphasePair* btSortedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
490 if (!needsBroadphaseCollision(proxy0, proxy1))
496 if (findIndex < m_overlappingPairArray.
size())
511 for (i = 0; i < m_overlappingPairArray.
size();)
514 if (
callback->processOverlap(*pair))
516 cleanOverlappingPair(*pair, dispatcher);
519 m_overlappingPairArray.
swap(i, m_overlappingPairArray.
size() - 1);
529btSortedOverlappingPairCache::btSortedOverlappingPairCache() : m_blockedForChanges(
false),
530 m_hasDeferredRemoval(
true),
534 int initialAllocatedSize = 2;
535 m_overlappingPairArray.reserve(initialAllocatedSize);
538btSortedOverlappingPairCache::~btSortedOverlappingPairCache()
544 if (pair.m_algorithm)
547 pair.m_algorithm->~btCollisionAlgorithm();
549 pair.m_algorithm = 0;
554void btSortedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy,
btDispatcher* dispatcher)
558 btBroadphaseProxy* m_cleanProxy;
564 : m_cleanProxy(cleanProxy),
565 m_pairCache(pairCache),
571 if ((pair.m_pProxy0 == m_cleanProxy) ||
572 (pair.m_pProxy1 == m_cleanProxy))
580 CleanPairCallback cleanPairs(proxy,
this, dispatcher);
582 processAllOverlappingPairs(&cleanPairs, dispatcher);
585void btSortedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,
btDispatcher* dispatcher)
589 btBroadphaseProxy* m_obsoleteProxy;
592 RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
593 : m_obsoleteProxy(obsoleteProxy)
598 return ((pair.m_pProxy0 == m_obsoleteProxy) ||
599 (pair.m_pProxy1 == m_obsoleteProxy));
603 RemovePairCallback removeCallback(proxy);
605 processAllOverlappingPairs(&removeCallback, dispatcher);
608void btSortedOverlappingPairCache::sortOverlappingPairs(
btDispatcher* dispatcher)
btBroadphaseProxy * m_pProxy0
btBroadphaseProxy * m_pProxy1
btDispatcher * m_dispatcher
btAlignedObjectArray< int > m_next
virtual void processAllOverlappingPairs(btOverlapCallback *, btDispatcher *dispatcher)
btOverlapFilterCallback * m_overlapFilterCallback
void cleanOverlappingPair(btBroadphasePair &pair, btDispatcher *dispatcher)
virtual btBroadphasePair * addOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)
btOverlappingPairCallback * m_ghostPairCallback
virtual void * removeOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1, btDispatcher *dispatcher)
btBroadphasePairArray & getOverlappingPairArray()
btAlignedObjectArray< int > m_hashTable
SIMD_FORCE_INLINE void btSwap(T &a, T &b)
bool operator()(const MyPairIndex &a, const MyPairIndex &b) const
SIMD_FORCE_INLINE int capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
int findLinearSearch(const T &key) const
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
void swap(int index0, int index1)
SIMD_FORCE_INLINE void pop_back()
SIMD_FORCE_INLINE void resize(int newsize, const T &fillData=T())
void quickSort(const L &CompareFunc)
SIMD_FORCE_INLINE T & expandNonInitializing()
SIMD_FORCE_INLINE void push_back(const T &_Val)
virtual void freeCollisionAlgorithm(void *ptr)=0
virtual void cleanOverlappingPair(btBroadphasePair &pair, btDispatcher *dispatcher)=0
virtual void * removeOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1, btDispatcher *dispatcher)=0
virtual btBroadphasePair * addOverlappingPair(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1)=0
local_group_size(16, 16) .push_constant(Type b
DEGForeachIDComponentCallback callback
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
bool m_deterministicOverlappingPairs
virtual bool processOverlap(btBroadphasePair &pair)=0