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 http://continuousphysics.com/Bullet/
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
19
20
22
23const int BT_SIMPLE_NULL_PAIR=0xffffffff;
24
26{
27 btSimplePair(int indexA,int indexB)
28 :m_indexA(indexA),
29 m_indexB(indexB),
31 {
32 }
33
36 union
37 {
40 };
41};
42
44
45
46
48extern int gRemoveSimplePairs;
49extern int gAddedSimplePairs;
50extern int gFindSimplePairs;
51
52
53
54
56{
58
59
60protected:
61
64
65
66public:
69
70 void removeAllPairs();
71
72 virtual void* removeOverlappingPair(int indexA,int indexB);
73
74 // Add a pair and return the new pair. If the pair already exists,
75 // no new pair is created and the old one is returned.
76 virtual btSimplePair* addOverlappingPair(int indexA,int indexB)
77 {
79
80 return internalAddPair(indexA,indexB);
81 }
82
83
85 {
86 return &m_overlappingPairArray[0];
87 }
88
90 {
91 return &m_overlappingPairArray[0];
92 }
93
95 {
97 }
98
100 {
102 }
103
104
105 btSimplePair* findPair(int indexA,int indexB);
106
107 int GetCount() const { return m_overlappingPairArray.size(); }
108
110 {
112 }
113private:
114
115 btSimplePair* internalAddPair(int indexA, int indexB);
116
117 void growTables();
118
119 SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
120 {
121 return pair.m_indexA == indexA && pair.m_indexB == indexB;
122 }
123
124
125
126 SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
127 {
128 unsigned int key = indexA | (indexB << 16);
129 // Thomas Wang's hash
130
131 key += ~(key << 15);
132 key ^= (key >> 10);
133 key += (key << 3);
134 key ^= (key >> 6);
135 key += ~(key << 11);
136 key ^= (key >> 16);
137 return key;
138 }
139
140
141
142
143
144 SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA , int proxyIdB, int hash)
145 {
146
147 int index = m_hashTable[hash];
148
149 while( index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
150 {
151 index = m_next[index];
152 }
153
154 if ( index == BT_SIMPLE_NULL_PAIR )
155 {
156 return NULL;
157 }
158
160
161 return &m_overlappingPairArray[index];
162 }
163
164
165};
166
167
168
169
170#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
171
172
const int BT_SIMPLE_NULL_PAIR
btAlignedObjectArray< btSimplePair > btSimplePairArray
int gAddedSimplePairs
int gFindSimplePairs
int gRemoveSimplePairs
int gOverlappingSimplePairs
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
#define btAssert(x)
Definition: btScalar.h:131
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)