2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
17 #define BT_HASHED_SIMPLE_PAIR_CACHE_H
19 #include "LinearMath/btAlignedObjectArray.h"
21 const int BT_SIMPLE_NULL_PAIR = 0xffffffff;
25 btSimplePair(int indexA, int indexB)
40 typedef btAlignedObjectArray<btSimplePair> btSimplePairArray;
42 #ifdef BT_DEBUG_COLLISION_PAIRS
43 extern int gOverlappingSimplePairs;
44 extern int gRemoveSimplePairs;
45 extern int gAddedSimplePairs;
46 extern int gFindSimplePairs;
47 #endif //BT_DEBUG_COLLISION_PAIRS
49 class btHashedSimplePairCache
51 btSimplePairArray m_overlappingPairArray;
54 btAlignedObjectArray<int> m_hashTable;
55 btAlignedObjectArray<int> m_next;
58 btHashedSimplePairCache();
59 virtual ~btHashedSimplePairCache();
61 void removeAllPairs();
63 virtual void* removeOverlappingPair(int indexA, int indexB);
65 // Add a pair and return the new pair. If the pair already exists,
66 // no new pair is created and the old one is returned.
67 virtual btSimplePair* addOverlappingPair(int indexA, int indexB)
69 #ifdef BT_DEBUG_COLLISION_PAIRS
73 return internalAddPair(indexA, indexB);
76 virtual btSimplePair* getOverlappingPairArrayPtr()
78 return &m_overlappingPairArray[0];
81 const btSimplePair* getOverlappingPairArrayPtr() const
83 return &m_overlappingPairArray[0];
86 btSimplePairArray& getOverlappingPairArray()
88 return m_overlappingPairArray;
91 const btSimplePairArray& getOverlappingPairArray() const
93 return m_overlappingPairArray;
96 btSimplePair* findPair(int indexA, int indexB);
98 int GetCount() const { return m_overlappingPairArray.size(); }
100 int getNumOverlappingPairs() const
102 return m_overlappingPairArray.size();
106 btSimplePair* internalAddPair(int indexA, int indexB);
110 SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
112 return pair.m_indexA == indexA && pair.m_indexB == indexB;
115 SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
117 unsigned int key = indexA | (indexB << 16);
118 // Thomas Wang's hash
129 SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA, int proxyIdB, int hash)
131 int index = m_hashTable[hash];
133 while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
135 index = m_next[index];
138 if (index == BT_SIMPLE_NULL_PAIR)
143 btAssert(index < m_overlappingPairArray.size());
145 return &m_overlappingPairArray[index];
149 #endif //BT_HASHED_SIMPLE_PAIR_CACHE_H