19#ifdef JPH_DEBUG_RENDERER
24#ifdef JPH_DEBUG_RENDERER
58 uint GetNumBodies()
const;
71 uint mNumBodiesDynamic = 0;
72 uint mNumActiveBodiesDynamic = 0;
74 uint mNumBodiesKinematic = 0;
75 uint mNumActiveBodiesKinematic = 0;
78 uint mNumActiveSoftBodies = 0;
91 void FreeBody(
Body *inBody)
const;
94 bool AddBody(
Body *ioBody);
97 bool AddBodyWithCustomID(
Body *ioBody,
const BodyID &inBodyID);
100 void RemoveBodies(
const BodyID *inBodyIDs,
int inNumber,
Body **outBodies);
103 void DestroyBodies(
const BodyID *inBodyIDs,
int inNumber);
107 void ActivateBodies(
const BodyID *inBodyIDs,
int inNumber);
111 void DeactivateBodies(
const BodyID *inBodyIDs,
int inNumber);
154 if (idx >= mBodies.size())
157 const Body *body = mBodies[idx];
158 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
168 if (idx >= mBodies.size())
171 Body *body = mBodies[idx];
172 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
187 MutexMask GetMutexMask(
const BodyID *inBodies,
int inNumber)
const;
188 void LockRead(MutexMask inMutexMask)
const;
189 void UnlockRead(MutexMask inMutexMask)
const;
190 void LockWrite(MutexMask inMutexMask)
const;
191 void UnlockWrite(MutexMask inMutexMask)
const;
195 void LockAllBodies()
const;
198 void UnlockAllBodies()
const;
204 void InvalidateContactCacheForBody(
Body &ioBody);
207 void ValidateContactCacheForAllBodies();
221#ifdef JPH_DEBUG_RENDERER
235 bool mDrawGetSupportFunction =
false;
236 bool mDrawSupportDirection =
false;
237 bool mDrawGetSupportingFace =
false;
238 bool mDrawShape =
true;
239 bool mDrawShapeWireframe =
false;
241 bool mDrawBoundingBox =
false;
242 bool mDrawCenterOfMassTransform =
false;
243 bool mDrawWorldTransform =
false;
244 bool mDrawVelocity =
false;
245 bool mDrawMassAndInertia =
false;
246 bool mDrawSleepStats =
false;
247 bool mDrawSoftBodyVertices =
false;
248 bool mDrawSoftBodyVertexVelocities =
false;
249 bool mDrawSoftBodyEdgeConstraints =
false;
250 bool mDrawSoftBodyBendConstraints =
false;
251 bool mDrawSoftBodyVolumeConstraints =
false;
252 bool mDrawSoftBodySkinConstraints =
false;
253 bool mDrawSoftBodyLRAConstraints =
false;
254 bool mDrawSoftBodyRods =
false;
255 bool mDrawSoftBodyRodStates =
false;
256 bool mDrawSoftBodyRodBendTwistConstraints =
false;
257 bool mDrawSoftBodyPredictedBounds =
false;
265#ifdef JPH_ENABLE_ASSERTS
267 void SetActiveBodiesLocked(
bool inLocked) { mActiveBodiesLocked = inLocked; }
270 class GrantActiveBodiesAccess
273 inline GrantActiveBodiesAccess(
bool inAllowActivation,
bool inAllowDeactivation)
276 sSetOverrideAllowActivation(inAllowActivation);
279 sSetOverrideAllowDeactivation(inAllowDeactivation);
282 inline ~GrantActiveBodiesAccess()
284 sSetOverrideAllowActivation(
false);
285 sSetOverrideAllowDeactivation(
false);
292 void ValidateActiveBodyBounds();
295#ifdef JPH_TRACK_SIMULATION_STATS
297 void ResetSimulationStats();
299#ifdef JPH_PROFILE_ENABLED
301 void ReportSimulationStats();
307#ifdef JPH_COMPILER_CLANG
308 __attribute__((no_sanitize(
"implicit-conversion")))
310 inline uint8 GetNextSequenceNumber(
int inBodyIndex) {
return ++mBodySequenceNumbers[inBodyIndex]; }
313 inline void AddBodyToActiveBodies(
Body &ioBody);
316 inline void RemoveBodyFromActiveBodies(
Body &ioBody);
319 JPH_INLINE
Body * RemoveBodyInternal(
const BodyID &inBodyID);
322 inline static void sDeleteBody(
Body *inBody);
324#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
326 void ValidateFreeList()
const;
336 static constexpr uintptr_t cBodyIDFreeListEnd = ~uintptr_t(0);
339 static constexpr uintptr_t cIsFreedBody = uintptr_t(1);
342 static constexpr uint cFreedBodyIndexShift = 1;
345 uintptr_t mBodyIDFreeListStart = cBodyIDFreeListEnd;
348 mutable Mutex mBodiesMutex;
352 mutable BodyMutexes mBodyMutexes;
358 mutable Mutex mActiveBodiesMutex;
361 BodyID * mActiveBodies[cBodyTypeCount] = { };
364 atomic<uint32> mNumActiveBodies[cBodyTypeCount] = { };
367 uint32 mNumActiveCCDBodies = 0;
370 mutable Mutex mBodiesCacheInvalidMutex;
381#ifdef JPH_ENABLE_ASSERTS
382 static bool sGetOverrideAllowActivation();
383 static void sSetOverrideAllowActivation(
bool inValue);
385 static bool sGetOverrideAllowDeactivation();
386 static void sSetOverrideAllowDeactivation(
bool inValue);
389 bool mActiveBodiesLocked =
false;
ESoftBodyConstraintColor
Defines how to color soft body constraints.
Definition BodyManager.h:28
@ ConstraintGroup
Draw different types of constraints in different colors.
@ ConstraintOrder
Draw constraints in the same group in the same color, non-parallel group will be red.
EBodyType
Type of body.
Definition BodyType.h:11
std::uint8_t uint8
Definition Core.h:493
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:496
unsigned int uint
Definition Core.h:492
#define JPH_NAMESPACE_END
Definition Core.h:419
std::uint32_t uint32
Definition Core.h:495
#define JPH_NAMESPACE_BEGIN
Definition Core.h:413
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:43
EMotionQuality
Motion quality, or how well it detects collisions when it has a high velocity.
Definition MotionQuality.h:11
uint16 ObjectLayer
Definition ObjectLayer.h:16
Definition BodyActivationListener.h:14
Settings for constructing a rigid body.
Definition BodyCreationSettings.h:31
Class function to filter out bodies for debug rendering, returns true if body should be rendered.
Definition BodyFilter.h:117
JPH_OVERRIDE_NEW_DELETE const BodyID & GetID() const
Get the id of this body.
Definition Body.h:44
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
uint32 GetIndex() const
Get index in body array.
Definition BodyID.h:44
Definition BodyManager.h:47
static bool sIsValidBodyPointer(const Body *inBody)
Check if this is a valid body pointer. When a body is freed the memory that the pointer occupies is r...
Definition BodyManager.h:133
Body & GetBody(const BodyID &inID)
Access a body (not protected by lock)
Definition BodyManager.h:148
BodyActivationListener * GetBodyActivationListener() const
Definition BodyManager.h:130
uint32 GetNumActiveCCDBodies() const
Get the number of active bodies that are using continuous collision detection.
Definition BodyManager.h:126
MutexMask GetAllBodiesMutexMask() const
Definition BodyManager.h:186
Body * TryGetBody(const BodyID &inID)
Access a body, will return a nullptr if the body ID is no longer valid (not protected by lock)
Definition BodyManager.h:165
SharedMutex & GetMutexForBody(const BodyID &inID) const
Access the mutex for a single body.
Definition BodyManager.h:179
const Body * TryGetBody(const BodyID &inID) const
Access a body, will return a nullptr if the body ID is no longer valid (not protected by lock)
Definition BodyManager.h:151
const BodyID * GetActiveBodiesUnsafe(EBodyType inType) const
Get the list of active bodies. Note: Not thread safe. The active bodies list can change at any moment...
Definition BodyManager.h:120
const BodyVector & GetBodies() const
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition BodyManager.h:136
BodyVector & GetBodies()
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition BodyManager.h:139
uint GetMaxBodies() const
Gets the max bodies that we can support.
Definition BodyManager.h:61
EShapeColor
Definition BodyManager.h:223
void SetBodyObjectLayerInternal(Body &ioBody, ObjectLayer inLayer) const
Function to update body's layer (should only be called by the BodyInterface since it also requires up...
Definition BodyManager.h:201
const Body & GetBody(const BodyID &inID) const
Access a body (not protected by lock)
Definition BodyManager.h:145
uint64 MutexMask
Bodies are protected using an array of mutexes (so a fixed number, not 1 per body)....
Definition BodyManager.h:182
uint32 GetNumActiveBodies(EBodyType inType) const
Get the number of active bodies.
Definition BodyManager.h:123
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition BroadPhaseLayer.h:61
Definition DebugRenderer.h:47
Definition MutexArray.h:17
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition SoftBodyCreationSettings.h:18
User callbacks that allow determining which parts of the simulation should be saved by a StateRecorde...
Definition StateRecorder.h:79
Definition StateRecorder.h:110
Helper struct that counts the number of bodies of each type.
Definition BodyManager.h:65
Draw settings.
Definition BodyManager.h:234
Definition PhysicsSettings.h:28