69 if (!
bodyA.internalGetInvMass().isZero())
78 btAssert(!
"dynamic body is used in 2 different batches in the same phase");
82 if (!
bodyB.internalGetInvMass().isZero())
91 btAssert(!
"dynamic body is used in 2 different batches in the same phase");
150 if (
bc &&
bc->m_debugDrawer &&
bc->m_phases.size() > 0)
163 int numPhases =
bc->m_phases.size();
180 for (
int i = 0; i < bodies.
size(); ++i)
193 while (
iSrc < numConstraints)
247 for (
int i = 0; i < numConstraints; ++i)
262 return numConstraints;
268 if (numConstraintRows > numConstraints)
275 for (
int i =
conInfo.numConstraintRows - 1; i >= 0; --i)
293 for (
int i = 0; i <
conInfo.numConstraintRows; ++i)
356 batch.numConstraints = 0;
390 BT_PROFILE(
"updateConstraintBatchIdsForMerges");
392 for (
int i = 0; i < numConstraints; ++i)
394 int iBatch = constraintBatchIds[i];
419 BT_PROFILE(
"UpdateConstraintBatchIdsForMergesLoop");
426 BT_PROFILE(
"updateConstraintBatchIdsForMergesMt");
440 const int* constraintBatchIds,
446 BT_PROFILE(
"writeOutConstraintIndicesForRangeOfBatches");
490 const int* constraintBatchIds,
493 int maxNumBatchesPerPhase,
518 int numPhases =
bc->m_phases.size();
519 bc->m_phaseGrainSize.resizeNoInitialize(numPhases);
531 const int* constraintBatchIds,
535 int maxNumBatchesPerPhase,
540 bc->m_constraintIndices.reserve(numConstraints);
541 bc->m_batches.resizeNoInitialize(0);
542 bc->m_phases.resizeNoInitialize(0);
560 if (numConstraints > 0)
574 bc->m_constraintIndices.resizeNoInitialize(numConstraints);
584 bc->m_phaseOrder.resize(
bc->m_phases.size());
585 for (
int i = 0; i <
bc->m_phases.size(); ++i)
587 bc->m_phaseOrder[i] = i;
655 bool* bodyDynamicFlags,
670 if (bodyDynamicFlags[
iBody0] && bodyDynamicFlags[
iBody1])
701 memset(
this, 0,
sizeof(*
this));
723 for (
int i = 0; i < 3; ++i)
752 for (
int i = 0; i < 3; ++i)
761 for (
int i = 0; i < 3; ++i)
826 const int numPhases = 8;
836 bool* bodyDynamicFlags =
NULL;
841 int* constraintBatchIds =
NULL;
846 memHelper.addChunk((
void**)&bodyDynamicFlags,
sizeof(
bool) * bodies.
size());
851 memHelper.addChunk((
void**)&constraintBatchIds,
sizeof(
int) * numConstraints);
872 for (
int i = 0; i < bodies.
size(); ++i)
910 for (
int i = 0; i < 3; ++i)
933 numGridChunks = gridChunkDim[0] * gridChunkDim[1] * gridChunkDim[2];
950 if (bodyDynamicFlags[
iBody])
982 params.bodyGridCoords = bodyGridCoords;
984 params.conInfos = conInfos;
985 params.constraintBatchIds = constraintBatchIds;
986 params.gridChunkDim = gridChunkDim;
987 params.maxNumBatchesPerPhase = maxNumBatchesPerPhase;
988 params.numPhases = numPhases;
989 params.phaseMask = phaseMask;
1023 if (numConstraintRows > numConstraints)
1043 bc->m_constraintIndices.resize(numConstraints);
1044 for (
int i = 0; i < numConstraints; ++i)
1046 bc->m_constraintIndices[i] = i;
1049 bc->m_batches.resizeNoInitialize(0);
1050 bc->m_phases.resizeNoInitialize(0);
1051 bc->m_phaseOrder.resizeNoInitialize(0);
1052 bc->m_phaseGrainSize.resizeNoInitialize(0);
1054 if (numConstraints > 0)
1056 bc->m_batches.push_back(Range(0, numConstraints));
1057 bc->m_phases.push_back(Range(0, 1));
1058 bc->m_phaseOrder.push_back(0);
1059 bc->m_phaseGrainSize.push_back(1);
static void writeGrainSizes(btBatchedConstraints *bc)
static void updateConstraintBatchIdsForMergesMt(int *constraintBatchIds, int numConstraints, const btBatchInfo *batches, int numBatches)
static void initBatchedConstraintInfoArray(btAlignedObjectArray< btBatchedConstraintInfo > *outConInfos, btConstraintArray *constraints)
static void debugDrawAllBatches(const btBatchedConstraints *bc, btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies)
static void updateConstraintBatchIdsForMerges(int *constraintBatchIds, int numConstraints, const btBatchInfo *batches, int numBatches)
static void expandConstraintRowsInPlace(int *constraintBatchIds, const btBatchedConstraintInfo *conInfos, int numConstraints, int numConstraintRows)
static void setupSingleBatch(btBatchedConstraints *bc, int numConstraints)
static void writeOutConstraintIndicesMt(btBatchedConstraints *bc, const int *constraintBatchIds, int numConstraints, int *constraintIdPerBatch, int maxNumBatchesPerPhase, int numPhases)
static int runLengthEncodeConstraintInfo(btBatchedConstraintInfo *outConInfos, int numConstraints)
static void debugDrawPhase(const btBatchedConstraints *bc, btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies, int iPhase, const btVector3 &color0, const btVector3 &color1, const btVector3 &offset)
bool BatchCompare(const btBatchedConstraints::Range &a, const btBatchedConstraints::Range &b)
static void mergeSmallBatches(btBatchInfo *batches, int iBeginBatch, int iEndBatch, int minBatchSize, int maxBatchSize)
static void writeOutConstraintIndicesForRangeOfBatches(btBatchedConstraints *bc, const int *constraintBatchIds, int numConstraints, int *constraintIdPerBatch, int batchBegin, int batchEnd)
static void expandConstraintRowsMt(int *destConstraintBatchIds, const int *srcConstraintBatchIds, const btBatchedConstraintInfo *conInfos, int numConstraints, int numConstraintRows)
static void setupSpatialGridBatchesMt(btBatchedConstraints *batchedConstraints, btAlignedObjectArray< char > *scratchMemory, btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies, int minBatchSize, int maxBatchSize, bool use2DGrid)
static btVector3 findMaxDynamicConstraintExtent(btVector3 *bodyPositions, bool *bodyDynamicFlags, btBatchedConstraintInfo *conInfos, int numConstraints, int numBodies)
static void initBatchedBodyDynamicFlags(btAlignedObjectArray< bool > *outBodyDynamicFlags, const btAlignedObjectArray< btSolverBody > &bodies)
static void expandConstraintRows(int *destConstraintBatchIds, const int *srcConstraintBatchIds, const btBatchedConstraintInfo *conInfos, int numConstraints, int numConstraintRows)
static int initBatchedConstraintInfo(btBatchedConstraintInfo *outConInfos, btConstraintArray *constraints)
static void debugDrawSingleBatch(const btBatchedConstraints *bc, btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies, int iBatch, const btVector3 &color, const btVector3 &offset)
static void writeOutBatches(btBatchedConstraints *bc, const int *constraintBatchIds, int numConstraints, const btBatchInfo *batches, int *batchWork, int maxNumBatchesPerPhase, int numPhases)
static void assignConstraintsToGridBatches(const AssignConstraintsToGridBatchesParams ¶ms, int iConBegin, int iConEnd)
void btClamp(T &a, const T &lb, const T &ub)
const T & btMax(const T &a, const T &b)
const T & btMin(const T &a, const T &b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define SIMD_FORCE_INLINE
btITaskScheduler * btGetTaskScheduler()
void btParallelFor(int iBegin, int iEnd, int grainSize, const btIParallelForBody &body)
btVector3 lerp(const btVector3 &v1, const btVector3 &v2, const btScalar &t)
Return the linear interpolation between two vectors.
void addChunk(void **ptr, size_t sz)
size_t getSizeToAllocate() const
void setChunkPointers(void *mem) const
PreallocatedMemoryHelper()
void resizeNoInitialize(int newsize)
resize changes the number of elements in the array.
int size() const
return the number of elements in the array
const T & at(int n) const
virtual int getNumThreads() const =0
btVector3 can be used to represent 3D points and vectors.
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
const btScalar & z() const
Return the z value.
const btScalar & x() const
Return the x value.
void setMin(const btVector3 &other)
Set each element to the min of the current values and the values of another btVector3.
const btScalar & y() const
Return the y value.
AssignConstraintsToGridBatchesLoop(const AssignConstraintsToGridBatchesParams ¶ms)
const AssignConstraintsToGridBatchesParams * m_params
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
btBatchedConstraintInfo * conInfos
btIntVec3 * bodyGridCoords
AssignConstraintsToGridBatchesParams()
int maxNumBatchesPerPhase
const btBatchedConstraintInfo * m_conInfos
int * m_destConstraintBatchIds
const int * m_srcConstraintBatchIds
ExpandConstraintRowsLoop(int *destConstraintBatchIds, const int *srcConstraintBatchIds, const btBatchedConstraintInfo *conInfos, int numConstraintRows)
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
btBatchedConstraintInfo * m_outConInfos
ReadSolverConstraintsLoop(btBatchedConstraintInfo *outConInfos, btConstraintArray *constraints)
btConstraintArray * m_constraints
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
int m_maxNumBatchesPerPhase
WriteOutConstraintIndicesLoop(btBatchedConstraints *bc, const int *constraintBatchIds, int numConstraints, int *constraintIdPerBatch, int maxNumBatchesPerPhase)
btBatchedConstraints * m_batchedConstraints
void forLoop(int iBegin, int iEnd) const BT_OVERRIDE
int * m_constraintIdPerBatch
const int * m_constraintBatchIds
bool validate(btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies) const
static bool s_debugDrawBatches
btAlignedObjectArray< Range > m_batches
btAlignedObjectArray< int > m_constraintIndices
void setup(btConstraintArray *constraints, const btAlignedObjectArray< btSolverBody > &bodies, BatchingMethod batchingMethod, int minBatchSize, int maxBatchSize, btAlignedObjectArray< char > *scratchMemory)
btAlignedObjectArray< Range > m_phases
@ BATCHING_METHOD_SPATIAL_GRID_2D
const int & operator[](int i) const
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
const btTransform & getWorldTransform() const
const btVector3 & internalGetInvMass() const
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...