| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Body/BodyID.h> |
| 8 |
#include <Jolt/Core/NonCopyable.h> |
| 9 |
#include <Jolt/Core/Atomics.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class TempAllocator; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class IslandBuilder : public NonCopyable |
| 19 |
{ |
| 20 |
public: |
| 21 |
|
| 22 |
~IslandBuilder(); |
| 23 |
|
| 24 |
|
| 25 |
void Init(uint32 inMaxActiveBodies); |
| 26 |
|
| 27 |
|
| 28 |
void PrepareContactConstraints(uint32 inMaxContactConstraints, TempAllocator *inTempAllocator); |
| 29 |
|
| 30 |
|
| 31 |
void PrepareNonContactConstraints(uint32 inNumConstraints, TempAllocator *inTempAllocator); |
| 32 |
|
| 33 |
|
| 34 |
void LinkBodies(uint32 inFirst, uint32 inSecond); |
| 35 |
|
| 36 |
|
| 37 |
void LinkConstraint(uint32 inConstraintIndex, uint32 inFirst, uint32 inSecond); |
| 38 |
|
| 39 |
|
| 40 |
void LinkContact(uint32 inContactIndex, uint32 inFirst, uint32 inSecond); |
| 41 |
|
| 42 |
|
| 43 |
void Finalize(const BodyID *inActiveBodies, uint32 inNumActiveBodies, uint32 inNumContacts, TempAllocator *inTempAllocator); |
| 44 |
|
| 45 |
|
| 46 |
uint32 GetNumIslands() const { return mNumIslands; } |
| 47 |
|
| 48 |
|
| 49 |
void GetBodiesInIsland(uint32 inIslandIndex, BodyID *&outBodiesBegin, BodyID *&outBodiesEnd) const; |
| 50 |
bool GetConstraintsInIsland(uint32 inIslandIndex, uint32 *&outConstraintsBegin, uint32 *&outConstraintsEnd) const; |
| 51 |
bool GetContactsInIsland(uint32 inIslandIndex, uint32 *&outContactsBegin, uint32 *&outContactsEnd) const; |
| 52 |
|
| 53 |
|
| 54 |
void SetNumPositionSteps(uint32 inIslandIndex, uint inNumPositionSteps) { JPH_ASSERT(inIslandIndex < mNumIslands); JPH_ASSERT(inNumPositionSteps < 256); mNumPositionSteps[inIslandIndex] = uint8(inNumPositionSteps); } |
| 55 |
uint GetNumPositionSteps(uint32 inIslandIndex) const { JPH_ASSERT(inIslandIndex < mNumIslands); return mNumPositionSteps[inIslandIndex]; } |
| 56 |
|
| 57 |
|
| 58 |
void ResetIslands(TempAllocator *inTempAllocator); |
| 59 |
|
| 60 |
private: |
| 61 |
|
| 62 |
uint32 GetLowestBodyIndex(uint32 inActiveBodyIndex) const; |
| 63 |
|
| 64 |
#ifdef JPH_VALIDATE_ISLAND_BUILDER |
| 65 |
|
| 66 |
void ValidateIslands(uint32 inNumActiveBodies) const; |
| 67 |
#endif |
| 68 |
|
| 69 |
|
| 70 |
void BuildBodyIslands(const BodyID *inActiveBodies, uint32 inNumActiveBodies, TempAllocator *inTempAllocator); |
| 71 |
void BuildConstraintIslands(const uint32 *inConstraintToBody, uint32 inNumConstraints, uint32 *&outConstraints, uint32 *&outConstraintsEnd, TempAllocator *inTempAllocator) const; |
| 72 |
|
| 73 |
|
| 74 |
void SortIslands(TempAllocator *inTempAllocator); |
| 75 |
|
| 76 |
|
| 77 |
struct BodyLink |
| 78 |
{ |
| 79 |
JPH_OVERRIDE_NEW_DELETE |
| 80 |
|
| 81 |
atomic<uint32> mLinkedTo; |
| 82 |
uint32 mIslandIndex; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
BodyLink * mBodyLinks = nullptr; |
| 87 |
uint32 * mConstraintLinks = nullptr; |
| 88 |
uint32 * mContactLinks = nullptr; |
| 89 |
|
| 90 |
|
| 91 |
BodyID * mBodyIslands = nullptr; |
| 92 |
uint32 * mBodyIslandEnds = nullptr; |
| 93 |
|
| 94 |
uint32 * mConstraintIslands = nullptr; |
| 95 |
uint32 * mConstraintIslandEnds = nullptr; |
| 96 |
|
| 97 |
uint32 * mContactIslands = nullptr; |
| 98 |
uint32 * mContactIslandEnds = nullptr; |
| 99 |
|
| 100 |
uint32 * mIslandsSorted = nullptr; |
| 101 |
|
| 102 |
uint8 * mNumPositionSteps = nullptr; |
| 103 |
|
| 104 |
|
| 105 |
uint32 mMaxActiveBodies; |
| 106 |
uint32 mNumActiveBodies = 0; |
| 107 |
uint32 mNumConstraints = 0; |
| 108 |
uint32 mMaxContacts = 0; |
| 109 |
uint32 mNumContacts = 0; |
| 110 |
uint32 mNumIslands = 0; |
| 111 |
|
| 112 |
#ifdef JPH_VALIDATE_ISLAND_BUILDER |
| 113 |
|
| 114 |
struct LinkValidation |
| 115 |
{ |
| 116 |
uint32 mFirst; |
| 117 |
uint32 mSecond; |
| 118 |
}; |
| 119 |
|
| 120 |
LinkValidation * mLinkValidation = nullptr; |
| 121 |
atomic<uint32> mNumLinkValidation; |
| 122 |
#endif |
| 123 |
}; |
| 124 |
|
| 125 |
JPH_NAMESPACE_END |