Bullet Collision Detection & Physics Library: btDiscreteDynamicsWorldMt.h Source File

Bullet Collision Detection & Physics Library

btDiscreteDynamicsWorldMt.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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
17 #ifndef BT_DISCRETE_DYNAMICS_WORLD_MT_H
18 #define BT_DISCRETE_DYNAMICS_WORLD_MT_H
19
20 #include "btDiscreteDynamicsWorld.h"
21 #include "btSimulationIslandManagerMt.h"
22 #include "BulletDynamics/ConstraintSolver/btConstraintSolver.h"
23
24 struct InplaceSolverIslandCallbackMt;
25
35 class btConstraintSolverPoolMt : public btConstraintSolver
36 {
37 public:
38 // create the solvers for me
39 explicit btConstraintSolverPoolMt( int numSolvers );
40
41 // pass in fully constructed solvers (destructor will delete them)
42 btConstraintSolverPoolMt( btConstraintSolver** solvers, int numSolvers );
43
44 virtual ~btConstraintSolverPoolMt();
45
47 virtual btScalar solveGroup( btCollisionObject** bodies,
48 int numBodies,
49 btPersistentManifold** manifolds,
50 int numManifolds,
51 btTypedConstraint** constraints,
52 int numConstraints,
53 const btContactSolverInfo& info,
54 btIDebugDraw* debugDrawer,
55 btDispatcher* dispatcher
56 ) BT_OVERRIDE;
57
58 virtual void reset() BT_OVERRIDE;
59 virtual btConstraintSolverType getSolverType() const BT_OVERRIDE { return m_solverType; }
60
61 private:
62 const static size_t kCacheLineSize = 128;
63 struct ThreadSolver
64 {
65 btConstraintSolver* solver;
66 btSpinMutex mutex;
67 char _cachelinePadding[ kCacheLineSize - sizeof( btSpinMutex ) - sizeof( void* ) ]; // keep mutexes from sharing a cache line
68 };
69 btAlignedObjectArray<ThreadSolver> m_solvers;
70 btConstraintSolverType m_solverType;
71
72 ThreadSolver* getAndLockThreadSolver();
73 void init( btConstraintSolver** solvers, int numSolvers );
74 };
75
76
77
88 ATTRIBUTE_ALIGNED16(class) btDiscreteDynamicsWorldMt : public btDiscreteDynamicsWorld
89 {
90 protected:
91 InplaceSolverIslandCallbackMt* m_solverIslandCallbackMt;
92
93 virtual void solveConstraints(btContactSolverInfo& solverInfo) BT_OVERRIDE;
94
95 virtual void predictUnconstraintMotion( btScalar timeStep ) BT_OVERRIDE;
96
97 struct UpdaterCreatePredictiveContacts : public btIParallelForBody
98 {
99 btScalar timeStep;
100 btRigidBody** rigidBodies;
101 btDiscreteDynamicsWorldMt* world;
102
103 void forLoop( int iBegin, int iEnd ) const BT_OVERRIDE
104 {
105 world->createPredictiveContactsInternal( &rigidBodies[ iBegin ], iEnd - iBegin, timeStep );
106 }
107 };
108 virtual void createPredictiveContacts( btScalar timeStep ) BT_OVERRIDE;
109
110 struct UpdaterIntegrateTransforms : public btIParallelForBody
111 {
112 btScalar timeStep;
113 btRigidBody** rigidBodies;
114 btDiscreteDynamicsWorldMt* world;
115
116 void forLoop( int iBegin, int iEnd ) const BT_OVERRIDE
117 {
118 world->integrateTransformsInternal( &rigidBodies[ iBegin ], iEnd - iBegin, timeStep );
119 }
120 };
121 virtual void integrateTransforms( btScalar timeStep ) BT_OVERRIDE;
122
123 public:
124 BT_DECLARE_ALIGNED_ALLOCATOR();
125
126 btDiscreteDynamicsWorldMt(btDispatcher* dispatcher,
127 btBroadphaseInterface* pairCache,
128 btConstraintSolverPoolMt* constraintSolver, // Note this should be a solver-pool for multi-threading
129 btCollisionConfiguration* collisionConfiguration
130 );
131 virtual ~btDiscreteDynamicsWorldMt();
132 };
133
134 #endif //BT_DISCRETE_DYNAMICS_WORLD_H
btConstraintSolverPoolMt::ThreadSolver::_cachelinePadding
char _cachelinePadding[kCacheLineSize - sizeof(btSpinMutex) - sizeof(void *)]
Definition: btDiscreteDynamicsWorldMt.h:67
btConstraintSolverPoolMt::solveGroup
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
Definition: btDiscreteDynamicsWorldMt.cpp:179
btConstraintSolverPoolMt::~btConstraintSolverPoolMt
virtual ~btConstraintSolverPoolMt()
Definition: btDiscreteDynamicsWorldMt.cpp:167
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:63
btDiscreteDynamicsWorldMt::UpdaterCreatePredictiveContacts::timeStep
btScalar timeStep
Definition: btDiscreteDynamicsWorldMt.h:99
btConstraintSolverPoolMt
btConstraintSolverPoolMt - masquerades as a constraint solver, but really it is a threadsafe pool of ...
Definition: btDiscreteDynamicsWorldMt.h:35
btConstraintSolverPoolMt::ThreadSolver::solver
btConstraintSolver * solver
Definition: btDiscreteDynamicsWorldMt.h:65
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
btConstraintSolverType
btConstraintSolverType
btConstraintSolver provides solver interface
Definition: btConstraintSolver.h:33
btConstraintSolverPoolMt::ThreadSolver
Definition: btDiscreteDynamicsWorldMt.h:63
btDiscreteDynamicsWorldMt::UpdaterCreatePredictiveContacts::rigidBodies
btRigidBody ** rigidBodies
Definition: btDiscreteDynamicsWorldMt.h:100
btDiscreteDynamicsWorld::integrateTransformsInternal
void integrateTransformsInternal(btRigidBody **bodies, int numBodies, btScalar timeStep)
Definition: btDiscreteDynamicsWorld.cpp:988
btDiscreteDynamicsWorld
btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete Cc...
Definition: btDiscreteDynamicsWorld.h:38
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size...
Definition: btCollisionConfiguration.h:26
btConstraintSolverPoolMt::kCacheLineSize
static const size_t kCacheLineSize
Definition: btDiscreteDynamicsWorldMt.h:62
btDiscreteDynamicsWorldMt::UpdaterIntegrateTransforms::forLoop
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
Definition: btDiscreteDynamicsWorldMt.h:116
btDiscreteDynamicsWorldMt::UpdaterIntegrateTransforms::timeStep
btScalar timeStep
Definition: btDiscreteDynamicsWorldMt.h:112
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep beca...
Definition: btThreads.h:45
btDiscreteDynamicsWorldMt::UpdaterIntegrateTransforms::world
btDiscreteDynamicsWorldMt * world
Definition: btDiscreteDynamicsWorldMt.h:114
btConstraintSolverPoolMt::init
void init(btConstraintSolver **solvers, int numSolvers)
Definition: btDiscreteDynamicsWorldMt.cpp:134
btConstraintSolverPoolMt::reset
virtual void reset() BT_OVERRIDE
clear internal cached data and reset random seed
Definition: btDiscreteDynamicsWorldMt.cpp:196
btSimulationIslandManagerMt.h
btConstraintSolverPoolMt::ThreadSolver::mutex
btSpinMutex mutex
Definition: btDiscreteDynamicsWorldMt.h:66
btDiscreteDynamicsWorldMt::UpdaterIntegrateTransforms
Definition: btDiscreteDynamicsWorldMt.h:110
BT_OVERRIDE
#define BT_OVERRIDE
Definition: btThreads.h:28
btConstraintSolverPoolMt::getAndLockThreadSolver
ThreadSolver * getAndLockThreadSolver()
btConstraintSolverPoolMt
Definition: btDiscreteDynamicsWorldMt.cpp:115
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs...
Definition: btBroadphaseInterface.h:55
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btDiscreteDynamicsWorldMt
btDiscreteDynamicsWorldMt – a version of DiscreteDynamicsWorld with some minor changes to support s...
Definition: btDiscreteDynamicsWorldMt.h:88
btConstraintSolverPoolMt::m_solvers
btAlignedObjectArray< ThreadSolver > m_solvers
Definition: btDiscreteDynamicsWorldMt.h:69
btContactSolverInfo
Definition: btContactSolverInfo.h:69
InplaceSolverIslandCallbackMt
Definition: btDiscreteDynamicsWorldMt.cpp:53
btConstraintSolver.h
btDiscreteDynamicsWorldMt::UpdaterIntegrateTransforms::rigidBodies
btRigidBody ** rigidBodies
Definition: btDiscreteDynamicsWorldMt.h:113
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:78
btConstraintSolverPoolMt::btConstraintSolverPoolMt
btConstraintSolverPoolMt(int numSolvers)
Definition: btDiscreteDynamicsWorldMt.cpp:149
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btConstraintSolverPoolMt::m_solverType
btConstraintSolverType m_solverType
Definition: btDiscreteDynamicsWorldMt.h:70
btDiscreteDynamicsWorldMt::UpdaterCreatePredictiveContacts::forLoop
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
Definition: btDiscreteDynamicsWorldMt.h:103
btDiscreteDynamicsWorld.h
btIParallelForBody
Definition: btThreads.h:98
btDiscreteDynamicsWorld::createPredictiveContactsInternal
void createPredictiveContactsInternal(btRigidBody **bodies, int numBodies, btScalar timeStep)
Definition: btDiscreteDynamicsWorld.cpp:880
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btDiscreteDynamicsWorldMt::m_solverIslandCallbackMt
InplaceSolverIslandCallbackMt * m_solverIslandCallbackMt
Definition: btDiscreteDynamicsWorldMt.h:91
btDiscreteDynamicsWorldMt::UpdaterCreatePredictiveContacts::world
btDiscreteDynamicsWorldMt * world
Definition: btDiscreteDynamicsWorldMt.h:101
btDiscreteDynamicsWorldMt::UpdaterCreatePredictiveContacts
Definition: btDiscreteDynamicsWorldMt.h:97
btConstraintSolverPoolMt::getSolverType
virtual btConstraintSolverType getSolverType() const BT_OVERRIDE
Definition: btDiscreteDynamicsWorldMt.h:59
btConstraintSolver
Definition: btConstraintSolver.h:40