Bullet Collision Detection & Physics Library
btSequentialImpulseConstraintSolverMt.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_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
17 #define BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
18 
20 #include "btBatchedConstraints.h"
21 #include "LinearMath/btThreads.h"
22 
57 {
58 public:
59  virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer) BT_OVERRIDE;
60  virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer) BT_OVERRIDE;
61  virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer) BT_OVERRIDE;
62  virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject** bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
63 
64  // temp struct used to collect info from persistent manifolds into a cache-friendly struct using multiple threads
66  {
67  static const int MAX_NUM_CONTACT_POINTS = 4;
68 
70  int solverBodyIds[ 2 ];
73  bool contactHasRollingFriction[ MAX_NUM_CONTACT_POINTS ];
74  btManifoldPoint* contactPoints[ MAX_NUM_CONTACT_POINTS ];
75  };
76  // temp struct used for setting up joint constraints in parallel
77  struct JointParams
78  {
82  };
83  void internalInitMultipleJoints(btTypedConstraint** constraints, int iBegin, int iEnd);
84  void internalConvertMultipleJoints( const btAlignedObjectArray<JointParams>& jointParamsArray, btTypedConstraint** constraints, int iBegin, int iEnd, const btContactSolverInfo& infoGlobal );
85 
86  // parameters to control batching
87  static bool s_allowNestedParallelForLoops; // whether to allow nested parallel operations
88  static int s_minimumContactManifoldsForBatching; // don't even try to batch if fewer manifolds than this
91  static int s_minBatchSize; // desired number of constraints per batch
92  static int s_maxBatchSize;
93 
94 protected:
95  static const int CACHE_LINE_SIZE = 64;
96 
103  btAlignedObjectArray<int> m_rollingFrictionIndexTable; // lookup table mapping contact index to rolling friction index
105  char m_antiFalseSharingPadding[CACHE_LINE_SIZE]; // padding to keep mutexes in separate cachelines
108 
109  virtual void randomizeConstraintOrdering( int iteration, int numIterations );
110  virtual btScalar resolveAllJointConstraints( int iteration );
111  virtual btScalar resolveAllContactConstraints();
112  virtual btScalar resolveAllContactFrictionConstraints();
113  virtual btScalar resolveAllContactConstraintsInterleaved();
114  virtual btScalar resolveAllRollingFrictionConstraints();
115 
116  virtual void setupBatchedContactConstraints();
117  virtual void setupBatchedJointConstraints();
118  virtual void convertJoints(btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
119  virtual void convertContacts(btPersistentManifold** manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
120  virtual void convertBodies(btCollisionObject** bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
121 
122  int getOrInitSolverBodyThreadsafe(btCollisionObject& body, btScalar timeStep);
123  void allocAllContactConstraints(btPersistentManifold** manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
124  void setupAllContactConstraints(const btContactSolverInfo& infoGlobal);
125  void randomizeBatchedConstraintOrdering( btBatchedConstraints* batchedConstraints );
126 
127 public:
128 
130 
133 
134  btScalar resolveMultipleJointConstraints( const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd, int iteration );
135  btScalar resolveMultipleContactConstraints( const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd );
136  btScalar resolveMultipleContactSplitPenetrationImpulseConstraints( const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd );
137  btScalar resolveMultipleContactFrictionConstraints( const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd );
138  btScalar resolveMultipleContactRollingFrictionConstraints( const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd );
139  btScalar resolveMultipleContactConstraintsInterleaved( const btAlignedObjectArray<int>& contactIndices, int batchBegin, int batchEnd );
140 
141  void internalCollectContactManifoldCachedInfo(btContactManifoldCachedInfo* cachedInfoArray, btPersistentManifold** manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
142  void internalAllocContactConstraints(const btContactManifoldCachedInfo* cachedInfoArray, int numManifolds);
143  void internalSetupContactConstraints(int iContactConstraint, const btContactSolverInfo& infoGlobal);
144  void internalConvertBodies(btCollisionObject** bodies, int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
145  void internalWriteBackContacts(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
146  void internalWriteBackJoints(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
147  void internalWriteBackBodies(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
148 };
149 
150 
151 
152 
153 #endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
154 
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep becau...
Definition: btThreads.h:47
ManifoldContactPoint collects and maintains persistent contactpoints.
static btBatchedConstraints::BatchingMethod s_jointBatchingMethod
static btBatchedConstraints::BatchingMethod s_contactBatchingMethod
#define BT_OVERRIDE
Definition: btThreads.h:28
btCollisionObject can be used to manage collision detection objects.
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
TypedConstraint is the baseclass for Bullet constraints and vehicles.
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btAlignedObjectArray< btContactManifoldCachedInfo > m_manifoldCachedInfoArray
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292