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
25{
26public:
28
29#ifdef JPH_ENABLE_ASSERTS
31 ConstraintManager(PhysicsLockContext inContext) : mLockContext(inContext) { }
32#endif // JPH_ENABLE_ASSERTS
33
36 void Add(Constraint **inConstraints, int inNumber);
37
40 void Remove(Constraint **inConstraint, int inNumber);
41
43 Constraints GetConstraints() const;
44
46 inline uint32 GetNumConstraints() const { return uint32(mConstraints.size()); }
47
49 void GetActiveConstraints(uint32 inStartConstraintIdx, uint32 inEndConstraintIdx, Constraint **outActiveConstraints, uint32 &outNumActiveConstraints) const;
50
52 static void sBuildIslands(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, IslandBuilder &ioBuilder, BodyManager &inBodyManager);
53
55 static void sSortConstraints(Constraint **inActiveConstraints, uint32 *inConstraintIdxBegin, uint32 *inConstraintIdxEnd);
56
58 static void sSetupVelocityConstraints(Constraint **inActiveConstraints, uint32 inNumActiveConstraints, float inDeltaTime);
59
61 template <class ConstraintCallback>
62 static void sWarmStartVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inWarmStartImpulseRatio, ConstraintCallback &ioCallback);
63
65 static bool sSolveVelocityConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime);
66
68 static bool sSolvePositionConstraints(Constraint **inActiveConstraints, const uint32 *inConstraintIdxBegin, const uint32 *inConstraintIdxEnd, float inDeltaTime, float inBaumgarte);
69
70#ifdef JPH_DEBUG_RENDERER
72 void DrawConstraints(DebugRenderer *inRenderer) const;
73
75 void DrawConstraintLimits(DebugRenderer *inRenderer) const;
76
78 void DrawConstraintReferenceFrame(DebugRenderer *inRenderer) const;
79#endif // JPH_DEBUG_RENDERER
80
82 void SaveState(StateRecorder &inStream, const StateRecorderFilter *inFilter) const;
83
85 bool RestoreState(StateRecorder &inStream);
86
88 void LockAllConstraints() { PhysicsLock::sLock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); }
89 void UnlockAllConstraints() { PhysicsLock::sUnlock(mConstraintsMutex JPH_IF_ENABLE_ASSERTS(, mLockContext, EPhysicsLockTypes::ConstraintsList)); }
90
91private:
92#ifdef JPH_ENABLE_ASSERTS
93 PhysicsLockContext mLockContext;
94#endif // JPH_ENABLE_ASSERTS
95 Constraints mConstraints;
96 mutable Mutex mConstraintsMutex;
97};
98
Array< Ref< Constraint > > Constraints
A list of constraints.
Definition: ConstraintManager.h:21
#define JPH_EXPORT
Definition: Core.h:227
#define JPH_NAMESPACE_END
Definition: Core.h:367
std::uint32_t uint32
Definition: Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#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:29
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
Class that contains all bodies.
Definition: BodyManager.h:32
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rig...
Definition: Constraint.h:103
A constraint manager manages all constraints of the same type.
Definition: ConstraintManager.h:25
uint32 GetNumConstraints() const
Get total number of constraints.
Definition: ConstraintManager.h:46
void LockAllConstraints()
Lock all constraints. This should only be done during PhysicsSystem::Update().
Definition: ConstraintManager.h:88
void UnlockAllConstraints()
Definition: ConstraintManager.h:89
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:29
Definition: StateRecorder.h:48