Bullet Collision Detection & Physics Library
btSimulationIslandManagerMt.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_SIMULATION_ISLAND_MANAGER_MT_H
17 #define BT_SIMULATION_ISLAND_MANAGER_MT_H
18 
20 
21 class btTypedConstraint;
22 
23 
34 {
35 public:
36  struct Island
37  {
38  // a simulation island consisting of bodies, manifolds and constraints,
39  // to be passed into a constraint solver.
43  int id; // island id
44  bool isSleeping;
45 
46  void append( const Island& other ); // add bodies, manifolds, constraints to my own
47  };
49  {
50  virtual ~IslandCallback() {};
51 
52  virtual void processIsland( btCollisionObject** bodies,
53  int numBodies,
54  btPersistentManifold** manifolds,
55  int numManifolds,
56  btTypedConstraint** constraints,
57  int numConstraints,
58  int islandId
59  ) = 0;
60  };
61  typedef void( *IslandDispatchFunc ) ( btAlignedObjectArray<Island*>* islands, IslandCallback* callback );
62  static void serialIslandDispatch( btAlignedObjectArray<Island*>* islandsPtr, IslandCallback* callback );
63  static void parallelIslandDispatch( btAlignedObjectArray<Island*>* islandsPtr, IslandCallback* callback );
64 protected:
66  btAlignedObjectArray<Island*> m_activeIslands; // islands actively in use
67  btAlignedObjectArray<Island*> m_freeIslands; // islands ready to be reused
68  btAlignedObjectArray<Island*> m_lookupIslandFromId; // big lookup table to map islandId to Island pointer
73 
74  Island* getIsland( int id );
75  virtual Island* allocateIsland( int id, int numBodies );
76  virtual void initIslandPools();
77  virtual void addBodiesToIslands( btCollisionWorld* collisionWorld );
78  virtual void addManifoldsToIslands( btDispatcher* dispatcher );
80  virtual void mergeIslands();
81 
82 public:
85 
86  virtual void buildAndProcessIslands( btDispatcher* dispatcher, btCollisionWorld* collisionWorld, btAlignedObjectArray<btTypedConstraint*>& constraints, IslandCallback* callback );
87 
88  virtual void buildIslands(btDispatcher* dispatcher,btCollisionWorld* colWorld);
89 
91  {
93  }
95  {
96  m_minimumSolverBatchSize = sz;
97  }
99  {
100  return m_islandDispatch;
101  }
102  // allow users to set their own dispatch function for multithreaded dispatch
104  {
105  m_islandDispatch = func;
106  }
107 };
108 
109 #endif //BT_SIMULATION_ISLAND_MANAGER_H
110 
virtual Island * allocateIsland(int id, int numBodies)
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
static void serialIslandDispatch(btAlignedObjectArray< Island *> *islandsPtr, IslandCallback *callback)
void setIslandDispatchFunction(IslandDispatchFunc func)
btAlignedObjectArray< btPersistentManifold * > manifoldArray
btAlignedObjectArray< Island * > m_freeIslands
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btAlignedObjectArray< Island * > m_lookupIslandFromId
virtual void buildAndProcessIslands(btDispatcher *dispatcher, btCollisionWorld *collisionWorld, btAlignedObjectArray< btTypedConstraint *> &constraints, IslandCallback *callback)
SimulationIslandManager creates and handles simulation islands, using btUnionFind.
virtual void addBodiesToIslands(btCollisionWorld *collisionWorld)
btAlignedObjectArray< Island * > m_activeIslands
btAlignedObjectArray< Island * > m_allocatedIslands
btCollisionObject can be used to manage collision detection objects.
btAlignedObjectArray< btTypedConstraint * > constraintArray
CollisionWorld is interface and container for the collision detection.
virtual void addConstraintsToIslands(btAlignedObjectArray< btTypedConstraint *> &constraints)
TypedConstraint is the baseclass for Bullet constraints and vehicles.
void(* IslandDispatchFunc)(btAlignedObjectArray< Island *> *islands, IslandCallback *callback)
static void parallelIslandDispatch(btAlignedObjectArray< Island *> *islandsPtr, IslandCallback *callback)
virtual void buildIslands(btDispatcher *dispatcher, btCollisionWorld *colWorld)
btAlignedObjectArray< btCollisionObject * > bodyArray
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
IslandDispatchFunc getIslandDispatchFunction() const
virtual void addManifoldsToIslands(btDispatcher *dispatcher)
SimulationIslandManagerMt – Multithread capable version of SimulationIslandManager Splits the world...