19#ifdef JPH_DEBUG_RENDERER
24#ifdef JPH_DEBUG_RENDERER
55 uint GetNumBodies()
const;
68 uint mNumBodiesDynamic = 0;
69 uint mNumActiveBodiesDynamic = 0;
71 uint mNumBodiesKinematic = 0;
72 uint mNumActiveBodiesKinematic = 0;
75 uint mNumActiveSoftBodies = 0;
88 void FreeBody(
Body *inBody)
const;
91 bool AddBody(
Body *ioBody);
94 bool AddBodyWithCustomID(
Body *ioBody,
const BodyID &inBodyID);
97 void RemoveBodies(
const BodyID *inBodyIDs,
int inNumber,
Body **outBodies);
100 void DestroyBodies(
const BodyID *inBodyIDs,
int inNumber);
104 void ActivateBodies(
const BodyID *inBodyIDs,
int inNumber);
108 void DeactivateBodies(
const BodyID *inBodyIDs,
int inNumber);
151 if (idx >= mBodies.size())
154 const Body *body = mBodies[idx];
155 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
165 if (idx >= mBodies.size())
168 Body *body = mBodies[idx];
169 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
184 MutexMask GetMutexMask(
const BodyID *inBodies,
int inNumber)
const;
185 void LockRead(MutexMask inMutexMask)
const;
186 void UnlockRead(MutexMask inMutexMask)
const;
187 void LockWrite(MutexMask inMutexMask)
const;
188 void UnlockWrite(MutexMask inMutexMask)
const;
192 void LockAllBodies()
const;
195 void UnlockAllBodies()
const;
201 void InvalidateContactCacheForBody(
Body &ioBody);
204 void ValidateContactCacheForAllBodies();
218#ifdef JPH_DEBUG_RENDERER
232 bool mDrawGetSupportFunction =
false;
233 bool mDrawSupportDirection =
false;
234 bool mDrawGetSupportingFace =
false;
235 bool mDrawShape =
true;
236 bool mDrawShapeWireframe =
false;
238 bool mDrawBoundingBox =
false;
239 bool mDrawCenterOfMassTransform =
false;
240 bool mDrawWorldTransform =
false;
241 bool mDrawVelocity =
false;
242 bool mDrawMassAndInertia =
false;
243 bool mDrawSleepStats =
false;
244 bool mDrawSoftBodyVertices =
false;
245 bool mDrawSoftBodyVertexVelocities =
false;
246 bool mDrawSoftBodyEdgeConstraints =
false;
247 bool mDrawSoftBodyBendConstraints =
false;
248 bool mDrawSoftBodyVolumeConstraints =
false;
249 bool mDrawSoftBodySkinConstraints =
false;
250 bool mDrawSoftBodyLRAConstraints =
false;
251 bool mDrawSoftBodyPredictedBounds =
false;
259#ifdef JPH_ENABLE_ASSERTS
261 void SetActiveBodiesLocked(
bool inLocked) { mActiveBodiesLocked = inLocked; }
264 class GrantActiveBodiesAccess
267 inline GrantActiveBodiesAccess(
bool inAllowActivation,
bool inAllowDeactivation)
270 sSetOverrideAllowActivation(inAllowActivation);
273 sSetOverrideAllowDeactivation(inAllowDeactivation);
276 inline ~GrantActiveBodiesAccess()
278 sSetOverrideAllowActivation(
false);
279 sSetOverrideAllowDeactivation(
false);
286 void ValidateActiveBodyBounds();
291#ifdef JPH_COMPILER_CLANG
292 __attribute__((no_sanitize(
"implicit-conversion")))
294 inline uint8 GetNextSequenceNumber(
int inBodyIndex) {
return ++mBodySequenceNumbers[inBodyIndex]; }
297 inline void AddBodyToActiveBodies(
Body &ioBody);
300 inline void RemoveBodyFromActiveBodies(
Body &ioBody);
303 JPH_INLINE
Body * RemoveBodyInternal(
const BodyID &inBodyID);
306 inline static void sDeleteBody(
Body *inBody);
308#if defined(JPH_DEBUG) && defined(JPH_ENABLE_ASSERTS)
310 void ValidateFreeList()
const;
320 static constexpr uintptr_t cBodyIDFreeListEnd = ~uintptr_t(0);
323 static constexpr uintptr_t cIsFreedBody = uintptr_t(1);
326 static constexpr uint cFreedBodyIndexShift = 1;
329 uintptr_t mBodyIDFreeListStart = cBodyIDFreeListEnd;
332 mutable Mutex mBodiesMutex;
336 mutable BodyMutexes mBodyMutexes;
342 mutable Mutex mActiveBodiesMutex;
345 BodyID * mActiveBodies[cBodyTypeCount] = { };
348 atomic<uint32> mNumActiveBodies[cBodyTypeCount] = { };
351 uint32 mNumActiveCCDBodies = 0;
354 mutable Mutex mBodiesCacheInvalidMutex;
365#ifdef JPH_ENABLE_ASSERTS
366 static bool sGetOverrideAllowActivation();
367 static void sSetOverrideAllowActivation(
bool inValue);
369 static bool sGetOverrideAllowDeactivation();
370 static void sSetOverrideAllowDeactivation(
bool inValue);
373 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:453
#define JPH_EXPORT
Definition: Core.h:236
std::uint64_t uint64
Definition: Core.h:456
unsigned int uint
Definition: Core.h:452
#define JPH_NAMESPACE_END
Definition: Core.h:378
std::uint32_t uint32
Definition: Core.h:455
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:31
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:40
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:43
Class that contains all bodies.
Definition: BodyManager.h:44
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:130
Body & GetBody(const BodyID &inID)
Access a body (not protected by lock)
Definition: BodyManager.h:145
BodyActivationListener * GetBodyActivationListener() const
Definition: BodyManager.h:127
uint32 GetNumActiveCCDBodies() const
Get the number of active bodies that are using continuous collision detection.
Definition: BodyManager.h:123
MutexMask GetAllBodiesMutexMask() const
Definition: BodyManager.h:183
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:162
SharedMutex & GetMutexForBody(const BodyID &inID) const
Access the mutex for a single body.
Definition: BodyManager.h:176
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:148
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:117
const BodyVector & GetBodies() const
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition: BodyManager.h:133
BodyVector & GetBodies()
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition: BodyManager.h:136
uint GetMaxBodies() const
Gets the max bodies that we can support.
Definition: BodyManager.h:58
EShapeColor
Definition: BodyManager.h:220
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:198
const Body & GetBody(const BodyID &inID) const
Access a body (not protected by lock)
Definition: BodyManager.h:142
uint64 MutexMask
Bodies are protected using an array of mutexes (so a fixed number, not 1 per body)....
Definition: BodyManager.h:179
uint32 GetNumActiveBodies(EBodyType inType) const
Get the number of active bodies.
Definition: BodyManager.h:120
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:74
Definition: StateRecorder.h:105
Helper struct that counts the number of bodies of each type.
Definition: BodyManager.h:62
Draw settings.
Definition: BodyManager.h:231
Definition: PhysicsSettings.h:28