2017-08-01 14:30:58 +02:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
|
|
|
|
#define BT_HASHED_SIMPLE_PAIR_CACHE_H
|
|
|
|
|
|
|
|
#include "LinearMath/btAlignedObjectArray.h"
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const int BT_SIMPLE_NULL_PAIR = 0xffffffff;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
struct btSimplePair
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimplePair(int indexA, int indexB)
|
|
|
|
: m_indexA(indexA),
|
|
|
|
m_indexB(indexB),
|
|
|
|
m_userPointer(0)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int m_indexA;
|
|
|
|
int m_indexB;
|
2019-01-03 14:26:51 +01:00
|
|
|
union {
|
|
|
|
void* m_userPointer;
|
|
|
|
int m_userValue;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
typedef btAlignedObjectArray<btSimplePair> btSimplePairArray;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2018-09-07 16:11:04 +02:00
|
|
|
#ifdef BT_DEBUG_COLLISION_PAIRS
|
2017-08-01 14:30:58 +02:00
|
|
|
extern int gOverlappingSimplePairs;
|
|
|
|
extern int gRemoveSimplePairs;
|
|
|
|
extern int gAddedSimplePairs;
|
|
|
|
extern int gFindSimplePairs;
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //BT_DEBUG_COLLISION_PAIRS
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
class btHashedSimplePairCache
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimplePairArray m_overlappingPairArray;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
protected:
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedObjectArray<int> m_hashTable;
|
|
|
|
btAlignedObjectArray<int> m_next;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
btHashedSimplePairCache();
|
|
|
|
virtual ~btHashedSimplePairCache();
|
2019-01-03 14:26:51 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
void removeAllPairs();
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* removeOverlappingPair(int indexA, int indexB);
|
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
// Add a pair and return the new pair. If the pair already exists,
|
|
|
|
// no new pair is created and the old one is returned.
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual btSimplePair* addOverlappingPair(int indexA, int indexB)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2018-09-07 16:11:04 +02:00
|
|
|
#ifdef BT_DEBUG_COLLISION_PAIRS
|
2017-08-01 14:30:58 +02:00
|
|
|
gAddedSimplePairs++;
|
2018-09-07 16:11:04 +02:00
|
|
|
#endif
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
return internalAddPair(indexA, indexB);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual btSimplePair* getOverlappingPairArrayPtr()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return &m_overlappingPairArray[0];
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const btSimplePair* getOverlappingPairArrayPtr() const
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return &m_overlappingPairArray[0];
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimplePairArray& getOverlappingPairArray()
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return m_overlappingPairArray;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const btSimplePairArray& getOverlappingPairArray() const
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return m_overlappingPairArray;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimplePair* findPair(int indexA, int indexB);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
int GetCount() const { return m_overlappingPairArray.size(); }
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int getNumOverlappingPairs() const
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return m_overlappingPairArray.size();
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
private:
|
2019-01-03 14:26:51 +01:00
|
|
|
btSimplePair* internalAddPair(int indexA, int indexB);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void growTables();
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
2017-08-01 14:30:58 +02:00
|
|
|
return pair.m_indexA == indexA && pair.m_indexB == indexB;
|
|
|
|
}
|
|
|
|
|
|
|
|
SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
|
|
|
|
{
|
|
|
|
unsigned int key = indexA | (indexB << 16);
|
|
|
|
// Thomas Wang's hash
|
|
|
|
|
|
|
|
key += ~(key << 15);
|
2019-01-03 14:26:51 +01:00
|
|
|
key ^= (key >> 10);
|
|
|
|
key += (key << 3);
|
|
|
|
key ^= (key >> 6);
|
2017-08-01 14:30:58 +02:00
|
|
|
key += ~(key << 11);
|
2019-01-03 14:26:51 +01:00
|
|
|
key ^= (key >> 16);
|
2017-08-01 14:30:58 +02:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA, int proxyIdB, int hash)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
int index = m_hashTable[hash];
|
2019-01-03 14:26:51 +01:00
|
|
|
|
|
|
|
while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
index = m_next[index];
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (index == BT_SIMPLE_NULL_PAIR)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
btAssert(index < m_overlappingPairArray.size());
|
|
|
|
|
|
|
|
return &m_overlappingPairArray[index];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
|