Blender  V3.3
btHashedSimplePairCache.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
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:
10 
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.
14 */
15 
16 #ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
17 #define BT_HASHED_SIMPLE_PAIR_CACHE_H
18 
20 
21 const int BT_SIMPLE_NULL_PAIR = 0xffffffff;
22 
24 {
25  btSimplePair(int indexA, int indexB)
26  : m_indexA(indexA),
27  m_indexB(indexB),
28  m_userPointer(0)
29  {
30  }
31 
32  int m_indexA;
33  int m_indexB;
34  union {
37  };
38 };
39 
41 
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
48 
50 {
51  btSimplePairArray m_overlappingPairArray;
52 
53 protected:
56 
57 public:
59  virtual ~btHashedSimplePairCache();
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  {
88  return m_overlappingPairArray;
89  }
90 
92  {
93  return m_overlappingPairArray;
94  }
95 
96  btSimplePair* findPair(int indexA, int indexB);
97 
98  int GetCount() const { return m_overlappingPairArray.size(); }
99 
101  {
102  return m_overlappingPairArray.size();
103  }
104 
105 private:
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 
143  btAssert(index < m_overlappingPairArray.size());
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:280
#define btAssert(x)
Definition: btScalar.h:295
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
const btSimplePairArray & getOverlappingPairArray() const
btAlignedObjectArray< int > m_hashTable
btAlignedObjectArray< int > m_next
virtual btSimplePair * getOverlappingPairArrayPtr()
btSimplePairArray & getOverlappingPairArray()
btSimplePair * findPair(int indexA, int indexB)
virtual btSimplePair * addOverlappingPair(int indexA, int indexB)
virtual void * removeOverlappingPair(int indexA, int indexB)
const btSimplePair * getOverlappingPairArrayPtr() const
#define hash
Definition: noise.c:153
btSimplePair(int indexA, int indexB)