Windows: Add support for building with clang.
[blender.git] / extern / bullet2 / patches / blender.patch
1 diff --git a/extern/bullet2/src/LinearMath/btScalar.h b/extern/bullet2/src/LinearMath/btScalar.h
2 --- a/extern/bullet2/src/LinearMath/btScalar.h
3 +++ b/extern/bullet2/src/LinearMath/btScalar.h
4 @@ -16,6 +16,9 @@
5  
6  #ifndef BT_SCALAR_H
7  #define BT_SCALAR_H
8 +#if defined(_MSC_VER) && defined(__clang__) /* clang supplies it's own overloads already */
9 +#define BT_NO_SIMD_OPERATOR_OVERLOADS
10 +#endif
11  
12  #ifdef BT_MANAGED_CODE
13  //Aligned data types not supported in managed code
14 @@ -83,7 +86,7 @@
15                         #ifdef BT_USE_SSE
16  
17  #if (_MSC_FULL_VER >= 170050727)//Visual Studio 2012 can compile SSE4/FMA3 (but SSE4/FMA3 is not enabled by default)
18 -                       #define BT_ALLOW_SSE4
19 +                       //#define BT_ALLOW_SSE4 //disable this cause blender targets sse2 
20  #endif //(_MSC_FULL_VER >= 160040219)
21  
22                         //BT_USE_SSE_IN_API is disabled under Windows by default, because 
23 @@ -102,7 +105,7 @@
24                 #endif //__MINGW32__
25  
26  #ifdef BT_DEBUG
27 -       #ifdef _MSC_VER
28 +       #if defined(_MSC_VER) && !defined(__clang__)
29                 #include <stdio.h>
30                 #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak();       }}
31         #else//_MSC_VER
32 diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
33 index be9eca6..ec40c96 100644
34 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
35 +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
36 @@ -15,7 +15,7 @@ subject to the following restrictions:
37  
38  
39  /**
40 - * @mainpage Bullet Documentation
41 + * @page Bullet Documentation
42   *
43   * @section intro_sec Introduction
44   * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ).
45 diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
46 index 36dd043..57eb817 100644
47 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
48 +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
49 @@ -579,14 +579,10 @@ btCollisionShape* btCollisionWorldImporter::convertCollisionShape(  btCollisionS
50                                 btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
51                                 btCompoundShape* compoundShape = createCompoundShape();
52  
53 -                               btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0];
54 -
55  
56                                 btAlignedObjectArray<btCollisionShape*> childShapes;
57                                 for (int i=0;i<compoundData->m_numChildShapes;i++)
58                                 {
59 -                                       btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i];
60 -
61                                         btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
62  
63                                         btCollisionShape* childShape = convertCollisionShape(cd);
64 diff --git a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp
65 index 57fc119..31faf1d 100644
66 --- a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp
67 +++ b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp
68 @@ -29,14 +29,11 @@ subject to the following restrictions:
69  static btVector3
70  getNormalizedVector(const btVector3& v)
71  {
72 -       btScalar l = v.length();
73 -       btVector3 n = v;
74 -       if (l < SIMD_EPSILON) {
75 -               n.setValue(0,0,0);
76 -       } else {
77 -               n /= l;
78 -       }
79 +       btVector3 n(0, 0, 0);
80  
81 +       if (v.length() > SIMD_EPSILON) {
82 +               n = v.normalized();
83 +       }
84         return n;
85  }
86  
87 diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverBody.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverBody.h
88 index 27ccefe..8e4456e 100644
89 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverBody.h
90 +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverBody.h
91 @@ -37,8 +37,13 @@ struct       btSimdScalar
92         {
93  
94         }
95 -
96 +/* workaround for clang 3.4 ( == apple clang 5.1 ) issue, friction would fail with forced inlining */
97 +#if (defined(__clang__) && defined(__apple_build_version__) &&  (__clang_major__ == 5) && (__clang_minor__ == 1)) \
98 +|| (defined(__clang__) && !defined(__apple_build_version__) && (__clang_major__ == 3) && (__clang_minor__ == 4))
99 +       inline __attribute__ ((noinline)) btSimdScalar(float    fl)
100 +#else
101         SIMD_FORCE_INLINE       btSimdScalar(float      fl)
102 +#endif
103         :m_vec128 (_mm_set1_ps(fl))
104         {
105         }
106 diff --git a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
107 index 5d62da7..fcd312e 100644
108 --- a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
109 +++ b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBody.cpp
110 @@ -28,7 +28,6 @@
111  #include "btMultiBodyJointFeedback.h"
112  #include "LinearMath/btTransformUtil.h"
113  #include "LinearMath/btSerializer.h"
114 -#include "Bullet3Common/b3Logging.h"
115  // #define INCLUDE_GYRO_TERM 
116  
117  ///todo: determine if we need these options. If so, make a proper API, otherwise delete those globals
118 @@ -1732,7 +1731,6 @@ void btMultiBody::goToSleep()
119  
120  void btMultiBody::checkMotionAndSleepIfRequired(btScalar timestep)
121  {
122 -       int num_links = getNumLinks();
123         extern bool gDisableDeactivation;
124      if (!m_canSleep || gDisableDeactivation) 
125         {
126 diff --git a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp
127 index 8a034b3..4f66b20 100644
128 --- a/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp
129 +++ b/extern/bullet2/src/BulletDynamics/Featherstone/btMultiBodyConstraintSolver.cpp
130 @@ -809,7 +809,6 @@ static void applyJointFeedback(btMultiBodyJacobianData& data, const btMultiBodyS
131  }
132  #endif
133  
134 -#include "Bullet3Common/b3Logging.h"
135  void btMultiBodyConstraintSolver::writeBackSolverBodyToMultiBody(btMultiBodySolverConstraint& c, btScalar deltaTime)
136  {
137  #if 1 
138 diff --git a/extern/bullet2/src/BulletSoftBody/btSparseSDF.h b/extern/bullet2/src/BulletSoftBody/btSparseSDF.h
139 index bcf0c79..8992ddb 100644
140 --- a/extern/bullet2/src/BulletSoftBody/btSparseSDF.h
141 +++ b/extern/bullet2/src/BulletSoftBody/btSparseSDF.h
142 @@ -185,7 +185,6 @@ struct      btSparseSdf
143                 {
144                         ++nprobes;              
145                         ++ncells;
146 -                       int sz = sizeof(Cell);
147                         if (ncells>m_clampCells)
148                         {
149                                 static int numResets=0;
150 diff --git a/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp b/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp
151 index d58ac95..3fd77df 100644
152 --- a/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp
153 +++ b/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp
154 @@ -2665,6 +2665,7 @@ btScalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, in
155         }
156  
157         vertices.resize(0);
158 +       original_vertex_index.resize(0);
159         edges.resize(0);
160         faces.resize(0);
161  
162 @@ -2675,6 +2676,7 @@ btScalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, in
163         {
164                 btConvexHullInternal::Vertex* v = oldVertices[copied];
165                 vertices.push_back(hull.getCoordinates(v));
166 +               original_vertex_index.push_back(v->point.index);
167                 btConvexHullInternal::Edge* firstEdge = v->edges;
168                 if (firstEdge)
169                 {
170 diff --git a/extern/bullet2/src/LinearMath/btConvexHullComputer.h b/extern/bullet2/src/LinearMath/btConvexHullComputer.h
171 index 7240ac4..6871ce8 100644
172 --- a/extern/bullet2/src/LinearMath/btConvexHullComputer.h
173 +++ b/extern/bullet2/src/LinearMath/btConvexHullComputer.h
174 @@ -67,6 +67,7 @@ class btConvexHullComputer
175  
176                 // Vertices of the output hull
177                 btAlignedObjectArray<btVector3> vertices;
178 +               btAlignedObjectArray<int> original_vertex_index;
179  
180                 // Edges of the output hull
181                 btAlignedObjectArray<Edge> edges;
182 diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
183 index 0623e35..02ea503 100644
184 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
185 +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
186 @@ -13,9 +13,9 @@ subject to the following restrictions:
187  3. This notice may not be removed or altered from any source distribution.
188  */
189  
190 -#if defined (_WIN32) || defined (__i386__)
191 -#define BT_USE_SSE_IN_API
192 -#endif
193 +//#if defined (_WIN32) || defined (__i386__)
194 +//#define BT_USE_SSE_IN_API
195 +//#endif
196  
197  #include "btConvexHullShape.h"
198  #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
199 diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
200 index b56d729..88018b4 100644
201 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
202 +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
203 @@ -13,9 +13,9 @@ subject to the following restrictions:
204  3. This notice may not be removed or altered from any source distribution.
205  */
206  
207 -#if defined (_WIN32) || defined (__i386__)
208 -#define BT_USE_SSE_IN_API
209 -#endif
210 +//#if defined (_WIN32) || defined (__i386__)
211 +//#define BT_USE_SSE_IN_API
212 +//#endif
213  
214  #include "btConvexShape.h"
215  #include "btTriangleShape.h"
216 diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
217 index a7362ea..6abfdff 100644
218 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
219 +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
220 @@ -13,9 +13,9 @@ subject to the following restrictions:
221  3. This notice may not be removed or altered from any source distribution.
222  */
223  
224 -#if defined (_WIN32) || defined (__i386__)
225 -#define BT_USE_SSE_IN_API
226 -#endif
227 +//#if defined (_WIN32) || defined (__i386__)
228 +//#define BT_USE_SSE_IN_API
229 +//#endif
230  
231  #include "btMultiSphereShape.h"
232  #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
233 diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
234 index 4854f37..9095c59 100644
235 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
236 +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
237 @@ -12,9 +12,9 @@ subject to the following restrictions:
238  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
239  3. This notice may not be removed or altered from any source distribution.
240  */
241 -#if defined (_WIN32) || defined (__i386__)
242 -#define BT_USE_SSE_IN_API
243 -#endif
244 +//#if defined (_WIN32) || defined (__i386__)
245 +//#define BT_USE_SSE_IN_API
246 +//#endif
247  
248  #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
249  #include "btConvexPolyhedron.h"
250 diff --git a/extern/bullet2/src/LinearMath/btVector3.cpp b/extern/bullet2/src/LinearMath/btVector3.cpp
251 index e05bdcc..dbcf2b6 100644
252 --- a/extern/bullet2/src/LinearMath/btVector3.cpp
253 +++ b/extern/bullet2/src/LinearMath/btVector3.cpp
254 @@ -15,9 +15,9 @@
255   This source version has been altered.
256   */
257  
258 -#if defined (_WIN32) || defined (__i386__)
259 -#define BT_USE_SSE_IN_API
260 -#endif
261 +//#if defined (_WIN32) || defined (__i386__)
262 +//#define BT_USE_SSE_IN_API
263 +//#endif
264  
265  
266  #include "btVector3.h"
267 diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
268 index e0e8bc7..a788268 100644
269 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
270 +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
271 @@ -425,50 +425,38 @@ void btRigidBody::setCenterOfMassTransform(const btTransform& xform)
272  }
273  
274  
275 +bool btRigidBody::checkCollideWithOverride(const  btCollisionObject* co) const
276 +{
277 +       const btRigidBody* otherRb = btRigidBody::upcast(co);
278 +       if (!otherRb)
279 +               return true;
280 +
281 +       for (int i = 0; i < m_constraintRefs.size(); ++i)
282 +       {
283 +               const btTypedConstraint* c = m_constraintRefs[i];
284 +               if (c->isEnabled())
285 +                       if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb)
286 +                               return false;
287 +       }
288 +
289 +       return true;
290 +}
291  
292  
293  
294  void btRigidBody::addConstraintRef(btTypedConstraint* c)
295  {
296 -       ///disable collision with the 'other' body
297 -
298         int index = m_constraintRefs.findLinearSearch(c);
299 -       //don't add constraints that are already referenced
300 -       //btAssert(index == m_constraintRefs.size());
301         if (index == m_constraintRefs.size())
302 -       {
303 -               m_constraintRefs.push_back(c);
304 -               btCollisionObject* colObjA = &c->getRigidBodyA();
305 -               btCollisionObject* colObjB = &c->getRigidBodyB();
306 -               if (colObjA == this)
307 -               {
308 -                       colObjA->setIgnoreCollisionCheck(colObjB, true);
309 -               }
310 -               else
311 -               {
312 -                       colObjB->setIgnoreCollisionCheck(colObjA, true);
313 -               }
314 -       } 
315 +               m_constraintRefs.push_back(c); 
316 +
317 +       m_checkCollideWith = true;
318  }
319  
320  void btRigidBody::removeConstraintRef(btTypedConstraint* c)
321  {
322 -       int index = m_constraintRefs.findLinearSearch(c);
323 -       //don't remove constraints that are not referenced
324 -       if(index < m_constraintRefs.size())
325 -    {
326 -        m_constraintRefs.remove(c);
327 -        btCollisionObject* colObjA = &c->getRigidBodyA();
328 -        btCollisionObject* colObjB = &c->getRigidBodyB();
329 -        if (colObjA == this)
330 -        {
331 -            colObjA->setIgnoreCollisionCheck(colObjB, false);
332 -        }
333 -        else
334 -        {
335 -            colObjB->setIgnoreCollisionCheck(colObjA, false);
336 -        }
337 -    }
338 +       m_constraintRefs.remove(c);
339 +       m_checkCollideWith = m_constraintRefs.size() > 0;
340  }
341  
342  int    btRigidBody::calculateSerializeBufferSize()     const
343 diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
344 index 1d177db..c2f8c5d 100644
345 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
346 +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
347 @@ -509,6 +509,8 @@ public:
348                 return (getBroadphaseProxy() != 0);
349         }
350  
351 +       virtual bool checkCollideWithOverride(const  btCollisionObject* co) const;
352 +
353         void addConstraintRef(btTypedConstraint* c);
354         void removeConstraintRef(btTypedConstraint* c);
355