2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
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:
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.
16 #ifndef BT_SIMULATION_ISLAND_MANAGER_MT_H
17 #define BT_SIMULATION_ISLAND_MANAGER_MT_H
19 #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
21 class btTypedConstraint;
22 class btConstraintSolver;
23 struct btContactSolverInfo;
27 /// SimulationIslandManagerMt -- Multithread capable version of SimulationIslandManager
28 /// Splits the world up into islands which can be solved in parallel.
29 /// In order to solve islands in parallel, an IslandDispatch function
30 /// must be provided which will dispatch calls to multiple threads.
31 /// The amount of parallelism that can be achieved depends on the number
32 /// of islands. If only a single island exists, then no parallelism is
35 class btSimulationIslandManagerMt : public btSimulationIslandManager
40 // a simulation island consisting of bodies, manifolds and constraints,
41 // to be passed into a constraint solver.
42 btAlignedObjectArray<btCollisionObject*> bodyArray;
43 btAlignedObjectArray<btPersistentManifold*> manifoldArray;
44 btAlignedObjectArray<btTypedConstraint*> constraintArray;
48 void append(const Island& other); // add bodies, manifolds, constraints to my own
52 btConstraintSolver* m_solverPool;
53 btConstraintSolver* m_solverMt;
54 btContactSolverInfo* m_solverInfo;
55 btIDebugDraw* m_debugDrawer;
56 btDispatcher* m_dispatcher;
58 static void solveIsland(btConstraintSolver* solver, Island& island, const SolverParams& solverParams);
60 typedef void (*IslandDispatchFunc)(btAlignedObjectArray<Island*>* islands, const SolverParams& solverParams);
61 static void serialIslandDispatch(btAlignedObjectArray<Island*>* islandsPtr, const SolverParams& solverParams);
62 static void parallelIslandDispatch(btAlignedObjectArray<Island*>* islandsPtr, const SolverParams& solverParams);
65 btAlignedObjectArray<Island*> m_allocatedIslands; // owner of all Islands
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
69 Island* m_batchIsland;
70 int m_minimumSolverBatchSize;
71 int m_batchIslandMinBodyCount;
72 IslandDispatchFunc m_islandDispatch;
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);
79 virtual void addConstraintsToIslands(btAlignedObjectArray<btTypedConstraint*>& constraints);
80 virtual void mergeIslands();
83 btSimulationIslandManagerMt();
84 virtual ~btSimulationIslandManagerMt();
86 virtual void buildAndProcessIslands(btDispatcher* dispatcher,
87 btCollisionWorld* collisionWorld,
88 btAlignedObjectArray<btTypedConstraint*>& constraints,
89 const SolverParams& solverParams);
91 virtual void buildIslands(btDispatcher* dispatcher, btCollisionWorld* colWorld);
93 int getMinimumSolverBatchSize() const
95 return m_minimumSolverBatchSize;
97 void setMinimumSolverBatchSize(int sz)
99 m_minimumSolverBatchSize = sz;
101 IslandDispatchFunc getIslandDispatchFunction() const
103 return m_islandDispatch;
105 // allow users to set their own dispatch function for multithreaded dispatch
106 void setIslandDispatchFunction(IslandDispatchFunc func)
108 m_islandDispatch = func;
112 #endif //BT_SIMULATION_ISLAND_MANAGER_H