Bullet Collision Detection & Physics Library
btSequentialImpulseConstraintSolverMt.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_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
17#define BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
18
22
58{
59public:
60 virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
61 virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
62 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
63 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
64
65 // temp struct used to collect info from persistent manifolds into a cache-friendly struct using multiple threads
67 {
68 static const int MAX_NUM_CONTACT_POINTS = 4;
69
71 int solverBodyIds[2];
74 bool contactHasRollingFriction[MAX_NUM_CONTACT_POINTS];
75 btManifoldPoint* contactPoints[MAX_NUM_CONTACT_POINTS];
76 };
77 // temp struct used for setting up joint constraints in parallel
79 {
83 };
84 void internalInitMultipleJoints(btTypedConstraint * *constraints, int iBegin, int iEnd);
85 void internalConvertMultipleJoints(const btAlignedObjectArray<JointParams>& jointParamsArray, btTypedConstraint** constraints, int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
86
87 // parameters to control batching
88 static bool s_allowNestedParallelForLoops; // whether to allow nested parallel operations
89 static int s_minimumContactManifoldsForBatching; // don't even try to batch if fewer manifolds than this
92 static int s_minBatchSize; // desired number of constraints per batch
93 static int s_maxBatchSize;
94
95protected:
96 static const int CACHE_LINE_SIZE = 64;
97
104 btAlignedObjectArray<int> m_rollingFrictionIndexTable; // lookup table mapping contact index to rolling friction index
106 char m_antiFalseSharingPadding[CACHE_LINE_SIZE]; // padding to keep mutexes in separate cachelines
109
110 virtual void randomizeConstraintOrdering(int iteration, int numIterations);
111 virtual btScalar resolveAllJointConstraints(int iteration);
112 virtual btScalar resolveAllContactConstraints();
113 virtual btScalar resolveAllContactFrictionConstraints();
114 virtual btScalar resolveAllContactConstraintsInterleaved();
115 virtual btScalar resolveAllRollingFrictionConstraints();
116
117 virtual void setupBatchedContactConstraints();
118 virtual void setupBatchedJointConstraints();
119 virtual void convertJoints(btTypedConstraint * *constraints, int numConstraints, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
120 virtual void convertContacts(btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
121 virtual void convertBodies(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
122
123 int getOrInitSolverBodyThreadsafe(btCollisionObject & body, btScalar timeStep);
124 void allocAllContactConstraints(btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
125 void setupAllContactConstraints(const btContactSolverInfo& infoGlobal);
126 void randomizeBatchedConstraintOrdering(btBatchedConstraints * batchedConstraints);
127
128public:
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#endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
#define BT_OVERRIDE
Definition: btThreads.h:26
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
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:27
ManifoldContactPoint collects and maintains persistent contactpoints.
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
static btBatchedConstraints::BatchingMethod s_contactBatchingMethod
btAlignedObjectArray< btContactManifoldCachedInfo > m_manifoldCachedInfoArray
static btBatchedConstraints::BatchingMethod s_jointBatchingMethod
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep becaus...
Definition: btThreads.h:46
TypedConstraint is the baseclass for Bullet constraints and vehicles.