Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ConstraintManager.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9#include <Jolt/Core/Mutex.h>
10
12
13class IslandBuilder;
14class BodyManager;
16#ifdef JPH_DEBUG_RENDERER
17class DebugRenderer;
18#endif // JPH_DEBUG_RENDERER
19
22
28{
29public:
31
32#ifdef JPH_ENABLE_ASSERTS
34 ConstraintManager(PhysicsLockContext inContext) : mLockContext(inContext) { }
35#endif // JPH_ENABLE_ASSERTS
36
38 void Add(Constraint **inConstraints, int inNumber);
39
41 void Remove(Constraint **inConstraint, int inNumber);
42
44 Constraints GetConstraints() const;
45
47 inline uint32 GetNumConstraints() const { return uint32(mConstraints.size()); }
48
50 void GetActiveConstraints(uint32 inStartConstraintIdx, uint32 inEndConstraintIdx, Constraint **outActiveConstraints, uint32 &outNumActiveConstraints) const;
51
53 static void sBuildIslands(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, IslandBuilder &ioBuilder, BodyManager &inBodyManager);
54
56 static void sSortConstraints(Constraint **inActiveConstraints, uint32 *inConstraintIdxBegin, uint32 *inConstraintIdxEnd);
57
59 static void sSetupVelocityConstraints(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, float inDeltaTime);
60
62 template <class ConstraintCallback>
63 static void sWarmStartVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inWarmStartImpulseRatio, ConstraintCallback &ioCallback);
64
66 static bool sSolveVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime);
67
69 static bool sSolvePositionConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime, float inBaumgarte);
70
71#ifdef JPH_DEBUG_RENDERER
73 void DrawConstraints(DebugRenderer *inRenderer) const;
74
76 void DrawConstraintLimits(DebugRenderer *inRenderer) const;
77
79 void DrawConstraintReferenceFrame(DebugRenderer *inRenderer) const;
80#endif // JPH_DEBUG_RENDERER
81
83 void SaveState(StateRecorder &inStream, const StateRecorderFilter *inFilter) const;
84
86 bool RestoreState(StateRecorder &inStream);
87
89 void LockAllConstraints() { PhysicsLock::sLock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); }
90 void UnlockAllConstraints() { PhysicsLock::sUnlock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); }
91
92private:
93#ifdef JPH_ENABLE_ASSERTS
94 PhysicsLockContext mLockContext;
95#endif // JPH_ENABLE_ASSERTS
96 Constraints mConstraints;
97 mutable Mutex mConstraintsMutex;
98};
99
#define JPH_EXPORT
Definition Core.h:275
#define JPH_NAMESPACE_END
Definition Core.h:419
std::uint32_t uint32
Definition Core.h:496
#define JPH_NAMESPACE_BEGIN
Definition Core.h:413
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:35
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:43
Definition BodyManager.h:47
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rig...
Definition Constraint.h:108
Definition ConstraintManager.h:28
uint32 GetNumConstraints() const
Get total number of constraints.
Definition ConstraintManager.h:47
void LockAllConstraints()
Lock all constraints. This should only be done during PhysicsSystem::Update().
Definition ConstraintManager.h:89
void UnlockAllConstraints()
Definition ConstraintManager.h:90
Definition DebugRenderer.h:47
Keeps track of connected bodies and builds islands for multithreaded velocity/position update.
Definition IslandBuilder.h:19
Definition Mutex.h:122
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
static void sUnlock(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:61
static void sLock(LockType &inMutex JPH_IF_ENABLE_ASSERTS(, PhysicsLockContext inContext, EPhysicsLockTypes inType))
Definition PhysicsLock.h:54
User callbacks that allow determining which parts of the simulation should be saved by a StateRecorde...
Definition StateRecorder.h:79
Definition StateRecorder.h:110