Bullet Collision Detection & Physics Library
btHashedSimplePairCache.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
17#define BT_HASHED_SIMPLE_PAIR_CACHE_H
18
20
21const int BT_SIMPLE_NULL_PAIR = 0xffffffff;
22
24{
25 btSimplePair(int indexA, int indexB)
26 : m_indexA(indexA),
27 m_indexB(indexB),
29 {
30 }
31
34 union {
37 };
38};
39
41
42#ifdef BT_DEBUG_COLLISION_PAIRS
43extern int gOverlappingSimplePairs;
44extern int gRemoveSimplePairs;
45extern int gAddedSimplePairs;
46extern int gFindSimplePairs;
47#endif //BT_DEBUG_COLLISION_PAIRS
48
50{
52
53protected:
56
57public:
60
61 void removeAllPairs();
62
63 virtual void* removeOverlappingPair(int indexA, int indexB);
64
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)
68 {
69#ifdef BT_DEBUG_COLLISION_PAIRS
70 gAddedSimplePairs++;
71#endif
72
73 return internalAddPair(indexA, indexB);
74 }
75
77 {
78 return &m_overlappingPairArray[0];
79 }
80
82 {
83 return &m_overlappingPairArray[0];
84 }
85
87 {
89 }
90
92 {
94 }
95
96 btSimplePair* findPair(int indexA, int indexB);
97
98 int GetCount() const { return m_overlappingPairArray.size(); }
99
101 {
103 }
104
105private:
106 btSimplePair* internalAddPair(int indexA, int indexB);
107
108 void growTables();
109
110 SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
111 {
112 return pair.m_indexA == indexA && pair.m_indexB == indexB;
113 }
114
115 SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
116 {
117 unsigned int key = indexA | (indexB << 16);
118 // Thomas Wang's hash
119
120 key += ~(key << 15);
121 key ^= (key >> 10);
122 key += (key << 3);
123 key ^= (key >> 6);
124 key += ~(key << 11);
125 key ^= (key >> 16);
126 return key;
127 }
128
129 SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA, int proxyIdB, int hash)
130 {
131 int index = m_hashTable[hash];
132
133 while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
134 {
135 index = m_next[index];
136 }
137
138 if (index == BT_SIMPLE_NULL_PAIR)
139 {
140 return NULL;
141 }
142
144
145 return &m_overlappingPairArray[index];
146 }
147};
148
149#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
const int BT_SIMPLE_NULL_PAIR
btAlignedObjectArray< btSimplePair > btSimplePairArray
#define SIMD_FORCE_INLINE
Definition: btScalar.h:98
#define btAssert(x)
Definition: btScalar.h:153
int size() const
return the number of elements in the array
btSimplePair * internalFindPair(int proxyIdA, int proxyIdB, int hash)
const btSimplePair * getOverlappingPairArrayPtr() const
const btSimplePairArray & getOverlappingPairArray() const
unsigned int getHash(unsigned int indexA, unsigned int indexB)
btSimplePair * internalAddPair(int indexA, int indexB)
virtual btSimplePair * getOverlappingPairArrayPtr()
btAlignedObjectArray< int > m_hashTable
btSimplePairArray & getOverlappingPairArray()
btAlignedObjectArray< int > m_next
btSimplePairArray m_overlappingPairArray
btSimplePair * findPair(int indexA, int indexB)
virtual btSimplePair * addOverlappingPair(int indexA, int indexB)
bool equalsPair(const btSimplePair &pair, int indexA, int indexB)
virtual void * removeOverlappingPair(int indexA, int indexB)
btSimplePair(int indexA, int indexB)