Bullet Collision Detection & Physics Library
btDiscreteDynamicsWorldMt.cpp
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://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
18
19//collision detection
27
28//rigidbody & constraints
40
41
44
45
49
51
52
54{
59
61 btConstraintSolver* solver,
65 m_solver(solver),
68 {
69
70 }
71
73 {
74 btAssert(0);
75 (void)other;
76 return *this;
77 }
78
80 {
84 }
85
86
87 virtual void processIsland( btCollisionObject** bodies,
88 int numBodies,
90 int numManifolds,
93 int islandId
94 )
95 {
96 m_solver->solveGroup( bodies,
105 );
106 }
107
108};
109
110
114
116{
117 int i = 0;
118#if BT_THREADSAFE
119 i = btGetCurrentThreadIndex() % m_solvers.size();
120#endif // #if BT_THREADSAFE
121 while ( true )
122 {
123 ThreadSolver& solver = m_solvers[ i ];
124 if ( solver.mutex.tryLock() )
125 {
126 return &solver;
127 }
128 // failed, try the next one
129 i = ( i + 1 ) % m_solvers.size();
130 }
131 return NULL;
132}
133
135{
137 m_solvers.resize( numSolvers );
138 for ( int i = 0; i < numSolvers; ++i )
139 {
140 m_solvers[ i ].solver = solvers[ i ];
141 }
142 if ( numSolvers > 0 )
143 {
145 }
146}
147
148// create the solvers for me
150{
153 for ( int i = 0; i < numSolvers; ++i )
154 {
156 solvers.push_back( solver );
157 }
158 init( &solvers[ 0 ], numSolvers );
159}
160
161// pass in fully constructed solvers (destructor will delete them)
163{
165}
166
168{
169 // delete all solvers
170 for ( int i = 0; i < m_solvers.size(); ++i )
171 {
172 ThreadSolver& solver = m_solvers[ i ];
173 delete solver.solver;
174 solver.solver = NULL;
175 }
176}
177
180 int numBodies,
182 int numManifolds,
184 int numConstraints,
185 const btContactSolverInfo& info,
188)
189{
191 ts->solver->solveGroup( bodies, numBodies, manifolds, numManifolds, constraints, numConstraints, info, debugDrawer, dispatcher );
192 ts->mutex.unlock();
193 return 0.0f;
194}
195
197{
198 for ( int i = 0; i < m_solvers.size(); ++i )
199 {
200 ThreadSolver& solver = m_solvers[ i ];
201 solver.mutex.lock();
202 solver.solver->reset();
203 solver.mutex.unlock();
204 }
205}
206
207
211
214{
216 {
219 }
220 {
223 }
224 {
229 }
230}
231
232
234{
236 {
237 m_solverIslandCallbackMt->~InplaceSolverIslandCallbackMt();
239 }
241 {
244 }
245}
246
247
249{
250 BT_PROFILE("solveConstraints");
251
254
258
260}
261
262
264{
267
268 void forLoop( int iBegin, int iEnd ) const BT_OVERRIDE
269 {
270 for ( int i = iBegin; i < iEnd; ++i )
271 {
272 btRigidBody* body = rigidBodies[ i ];
273 if ( !body->isStaticOrKinematicObject() )
274 {
275 //don't integrate/update velocities here, it happens in the constraint solver
276 body->applyDamping( timeStep );
278 }
279 }
280 }
281};
282
283
285{
286 BT_PROFILE( "predictUnconstraintMotion" );
287 if ( m_nonStaticRigidBodies.size() > 0 )
288 {
290 update.timeStep = timeStep;
291 update.rigidBodies = &m_nonStaticRigidBodies[ 0 ];
292 int grainSize = 50; // num of iterations per task for task scheduler
294 }
295}
296
297
299{
300 BT_PROFILE( "createPredictiveContacts" );
302 if ( m_nonStaticRigidBodies.size() > 0 )
303 {
305 update.world = this;
306 update.timeStep = timeStep;
307 update.rigidBodies = &m_nonStaticRigidBodies[ 0 ];
308 int grainSize = 50; // num of iterations per task for task scheduler
310 }
311}
312
313
315{
316 BT_PROFILE( "integrateTransforms" );
317 if ( m_nonStaticRigidBodies.size() > 0 )
318 {
320 update.world = this;
321 update.timeStep = timeStep;
322 update.rigidBodies = &m_nonStaticRigidBodies[ 0 ];
323 int grainSize = 50; // num of iterations per task for task scheduler
325 }
326}
327
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
@ BT_SEQUENTIAL_IMPULSE_SOLVER
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:29
#define BT_PROFILE(name)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:292
#define SIMD_FORCE_INLINE
Definition btScalar.h:81
#define btAssert(x)
Definition btScalar.h:131
unsigned int btGetCurrentThreadIndex()
void btParallelFor(int iBegin, int iEnd, int grainSize, const btIParallelForBody &body)
#define BT_OVERRIDE
Definition btThreads.h:28
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int size() const
return the number of elements in the array
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size,...
btCollisionObject can be used to manage collision detection objects.
bool isStaticOrKinematicObject() const
const btTransform & getInterpolationWorldTransform() const
btDispatcher * getDispatcher()
virtual btIDebugDraw * getDebugDrawer()
int getNumCollisionObjects() const
btIDebugDraw * m_debugDrawer
btConstraintSolverPoolMt - masquerades as a constraint solver, but really it is a threadsafe pool of ...
ThreadSolver * getAndLockThreadSolver()
btConstraintSolverPoolMt
virtual void reset() BT_OVERRIDE
clear internal cached data and reset random seed
btConstraintSolverType m_solverType
void init(btConstraintSolver **solvers, int numSolvers)
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifolds, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher) BT_OVERRIDE
solve a group of constraints
btAlignedObjectArray< ThreadSolver > m_solvers
virtual btConstraintSolverType getSolverType() const =0
virtual void allSolved(const btContactSolverInfo &, class btIDebugDraw *)
virtual void prepareSolve(int, int)
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, class btIDebugDraw *debugDrawer, btDispatcher *dispatcher)=0
solve a group of constraints
virtual void reset()=0
clear internal cached data and reset random seed
virtual void solveConstraints(btContactSolverInfo &solverInfo) BT_OVERRIDE
virtual void integrateTransforms(btScalar timeStep) BT_OVERRIDE
virtual void predictUnconstraintMotion(btScalar timeStep) BT_OVERRIDE
InplaceSolverIslandCallbackMt * m_solverIslandCallbackMt
virtual void createPredictiveContacts(btScalar timeStep) BT_OVERRIDE
btDiscreteDynamicsWorldMt(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolverPoolMt *constraintSolver, btCollisionConfiguration *collisionConfiguration)
btDiscreteDynamicsWorldMt
btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete Cc...
btSimulationIslandManager * m_islandManager
btAlignedObjectArray< btTypedConstraint * > m_constraints
btAlignedObjectArray< btRigidBody * > m_nonStaticRigidBodies
btConstraintSolver * m_constraintSolver
btCollisionWorld * getCollisionWorld()
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
btContactSolverInfo m_solverInfo
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:63
void applyDamping(btScalar timeStep)
applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
void predictIntegratedTransform(btScalar step, btTransform &predictedTransform)
continuous collision detection needs prediction
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
SimulationIslandManagerMt – Multithread capable version of SimulationIslandManager Splits the world u...
virtual void buildAndProcessIslands(btDispatcher *dispatcher, btCollisionWorld *collisionWorld, btAlignedObjectArray< btTypedConstraint * > &constraints, IslandCallback *callback)
bool tryLock()
void unlock()
The StackAlloc class provides some fast stack-based memory allocator (LIFO last-in first-out)
TypedConstraint is the baseclass for Bullet constraints and vehicles.
virtual void processIsland(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifolds, int numManifolds, btTypedConstraint **constraints, int numConstraints, int islandId)
InplaceSolverIslandCallbackMt(btConstraintSolver *solver, btStackAlloc *stackAlloc, btDispatcher *dispatcher)
InplaceSolverIslandCallbackMt & operator=(InplaceSolverIslandCallbackMt &other)
void setup(btContactSolverInfo *solverInfo, btIDebugDraw *debugDrawer)
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE