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
245 bool mDrawGetSupportFunction =
false;
246 bool mDrawSupportDirection =
false;
247 bool mDrawGetSupportingFace =
false;
248 bool mDrawShape =
true;
249 bool mDrawShapeWireframe =
false;
251 bool mDrawBoundingBox =
false;
252 bool mDrawCenterOfMassTransform =
false;
253 bool mDrawWorldTransform =
false;
254 bool mDrawVelocity =
false;
255 bool mDrawMassAndInertia =
false;
256 bool mDrawSleepStats =
false;
257 bool mDrawSoftBodyVertices =
false;
258 bool mDrawSoftBodyVertexVelocities =
false;
259 bool mDrawSoftBodyEdgeConstraints =
false;
260 bool mDrawSoftBodyBendConstraints =
false;
261 bool mDrawSoftBodyVolumeConstraints =
false;
262 bool mDrawSoftBodySkinConstraints =
false;
263 bool mDrawSoftBodyLRAConstraints =
false;
264 bool mDrawSoftBodyRods =
false;
265 bool mDrawSoftBodyRodStates =
false;
266 bool mDrawSoftBodyRodBendTwistConstraints =
false;
267 bool mDrawSoftBodyPredictedBounds =
false;
275#ifdef JPH_ENABLE_ASSERTS
277 void SetActiveBodiesLocked(
bool inLocked) { mActiveBodiesLocked = inLocked; }
280 class GrantActiveBodiesAccess
283 inline GrantActiveBodiesAccess(
bool inAllowActivation,
bool inAllowDeactivation)
286 sSetOverrideAllowActivation(inAllowActivation);
289 sSetOverrideAllowDeactivation(inAllowDeactivation);
292 inline ~GrantActiveBodiesAccess()
294 sSetOverrideAllowActivation(
false);
295 sSetOverrideAllowDeactivation(
false);
302 void ValidateActiveBodyBounds();
305#ifdef JPH_TRACK_SIMULATION_STATS
307 void ResetSimulationStats();
309#ifdef JPH_PROFILE_ENABLED
311 void ReportSimulationStats();
317#ifdef JPH_COMPILER_CLANG
318 __attribute__((no_sanitize(
"implicit-conversion")))
320 inline uint8 GetNextSequenceNumber(
int inBodyIndex) {
return ++mBodySequenceNumbers[inBodyIndex]; }
323 inline void AddBodyToActiveBodies(
Body &ioBody);
326 inline void RemoveBodyFromActiveBodies(
Body &ioBody);
329 JPH_INLINE
Body * RemoveBodyInternal(
const BodyID &inBodyID);
332 inline static void sDeleteBody(
Body *inBody);
334#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
336 void ValidateFreeList()
const;
346 static constexpr uintptr_t cBodyIDFreeListEnd = ~uintptr_t(0);
349 static constexpr uintptr_t cIsFreedBody = uintptr_t(1);
352 static constexpr uint cFreedBodyIndexShift = 1;
355 uintptr_t mBodyIDFreeListStart = cBodyIDFreeListEnd;
358 mutable Mutex mBodiesMutex;
362 mutable BodyMutexes mBodyMutexes;
368 mutable Mutex mActiveBodiesMutex;
371 BodyID * mActiveBodies[cBodyTypeCount] = { };
374 atomic<uint32> mNumActiveBodies[cBodyTypeCount] = { };
377 uint32 mNumActiveCCDBodies = 0;
380 mutable Mutex mBodiesCacheInvalidMutex;
391#ifdef JPH_ENABLE_ASSERTS
392 static bool sGetOverrideAllowActivation();
393 static void sSetOverrideAllowActivation(
bool inValue);
395 static bool sGetOverrideAllowDeactivation();
396 static void sSetOverrideAllowDeactivation(
bool inValue);
399 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:500
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:503
unsigned int uint
Definition Core.h:499
#define JPH_NAMESPACE_END
Definition Core.h:425
std::uint32_t uint32
Definition Core.h:502
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:49
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
Definition BodyManager.h:244
Definition PhysicsSettings.h:28