| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Constraints/Constraint.h> |
| 8 |
#include <Jolt/Physics/PhysicsLock.h> |
| 9 |
#include <Jolt/Core/Mutex.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class IslandBuilder; |
| 14 |
class BodyManager; |
| 15 |
class StateRecorderFilter; |
| 16 |
#ifdef JPH_DEBUG_RENDERER |
| 17 |
class DebugRenderer; |
| 18 |
#endif |
| 19 |
|
| 20 |
|
| 21 |
using Constraints = Array<Ref<Constraint>>; |
| 22 |
|
| 23 |
|
| 24 |
class JPH_EXPORT ConstraintManager : public NonCopyable |
| 25 |
{ |
| 26 |
public: |
| 27 |
JPH_OVERRIDE_NEW_DELETE |
| 28 |
|
| 29 |
#ifdef JPH_ENABLE_ASSERTS |
| 30 |
|
| 31 |
ConstraintManager(PhysicsLockContext inContext) : mLockContext(inContext) { } |
| 32 |
#endif |
| 33 |
|
| 34 |
|
| 35 |
void Add(Constraint **inConstraints, int inNumber); |
| 36 |
|
| 37 |
|
| 38 |
void Remove(Constraint **inConstraint, int inNumber); |
| 39 |
|
| 40 |
|
| 41 |
Constraints GetConstraints() const; |
| 42 |
|
| 43 |
|
| 44 |
inline uint32 GetNumConstraints() const { return uint32(mConstraints.size()); } |
| 45 |
|
| 46 |
|
| 47 |
void GetActiveConstraints(uint32 inStartConstraintIdx, uint32 inEndConstraintIdx, Constraint **outActiveConstraints, uint32 &outNumActiveConstraints) const; |
| 48 |
|
| 49 |
|
| 50 |
static void sBuildIslands(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, IslandBuilder &ioBuilder, BodyManager &inBodyManager); |
| 51 |
|
| 52 |
|
| 53 |
static void sSortConstraints(Constraint **inActiveConstraints, uint32 *inConstraintIdxBegin, uint32 *inConstraintIdxEnd); |
| 54 |
|
| 55 |
|
| 56 |
static void sSetupVelocityConstraints(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, float inDeltaTime); |
| 57 |
|
| 58 |
|
| 59 |
template <class ConstraintCallback> |
| 60 |
static void sWarmStartVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inWarmStartImpulseRatio, ConstraintCallback &ioCallback); |
| 61 |
|
| 62 |
|
| 63 |
static bool sSolveVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime); |
| 64 |
|
| 65 |
|
| 66 |
static bool sSolvePositionConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime, float inBaumgarte); |
| 67 |
|
| 68 |
#ifdef JPH_DEBUG_RENDERER |
| 69 |
|
| 70 |
void DrawConstraints(DebugRenderer *inRenderer) const; |
| 71 |
|
| 72 |
|
| 73 |
void DrawConstraintLimits(DebugRenderer *inRenderer) const; |
| 74 |
|
| 75 |
|
| 76 |
void DrawConstraintReferenceFrame(DebugRenderer *inRenderer) const; |
| 77 |
#endif |
| 78 |
|
| 79 |
|
| 80 |
void SaveState(StateRecorder &inStream, const StateRecorderFilter *inFilter) const; |
| 81 |
|
| 82 |
|
| 83 |
bool RestoreState(StateRecorder &inStream); |
| 84 |
|
| 85 |
|
| 86 |
void LockAllConstraints() { PhysicsLock::sLock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); } |
| 87 |
void UnlockAllConstraints() { PhysicsLock::sUnlock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); } |
| 88 |
|
| 89 |
private: |
| 90 |
#ifdef JPH_ENABLE_ASSERTS |
| 91 |
PhysicsLockContext mLockContext; |
| 92 |
#endif |
| 93 |
Constraints mConstraints; |
| 94 |
mutable Mutex mConstraintsMutex; |
| 95 |
}; |
| 96 |
|
| 97 |
JPH_NAMESPACE_END |