19#ifdef JPH_DEBUG_RENDERER
43 uint GetNumBodies()
const;
56 uint mNumBodiesDynamic = 0;
57 uint mNumActiveBodiesDynamic = 0;
59 uint mNumBodiesKinematic = 0;
60 uint mNumActiveBodiesKinematic = 0;
63 uint mNumActiveSoftBodies = 0;
76 void FreeBody(
Body *inBody)
const;
79 bool AddBody(
Body *ioBody);
82 bool AddBodyWithCustomID(
Body *ioBody,
const BodyID &inBodyID);
85 void RemoveBodies(
const BodyID *inBodyIDs,
int inNumber,
Body **outBodies);
88 void DestroyBodies(
const BodyID *inBodyIDs,
int inNumber);
92 void ActivateBodies(
const BodyID *inBodyIDs,
int inNumber);
96 void DeactivateBodies(
const BodyID *inBodyIDs,
int inNumber);
139 if (idx >= mBodies.size())
142 const Body *body = mBodies[idx];
143 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
153 if (idx >= mBodies.size())
156 Body *body = mBodies[idx];
157 if (sIsValidBodyPointer(body) && body->
GetID() == inID)
172 MutexMask GetMutexMask(
const BodyID *inBodies,
int inNumber)
const;
173 void LockRead(MutexMask inMutexMask)
const;
174 void UnlockRead(MutexMask inMutexMask)
const;
175 void LockWrite(MutexMask inMutexMask)
const;
176 void UnlockWrite(MutexMask inMutexMask)
const;
180 void LockAllBodies()
const;
183 void UnlockAllBodies()
const;
189 void InvalidateContactCacheForBody(
Body &ioBody);
192 void ValidateContactCacheForAllBodies();
216#ifdef JPH_DEBUG_RENDERER
220 bool mDrawGetSupportFunction =
false;
221 bool mDrawSupportDirection =
false;
222 bool mDrawGetSupportingFace =
false;
223 bool mDrawShape =
true;
224 bool mDrawShapeWireframe =
false;
226 bool mDrawBoundingBox =
false;
227 bool mDrawCenterOfMassTransform =
false;
228 bool mDrawWorldTransform =
false;
229 bool mDrawVelocity =
false;
230 bool mDrawMassAndInertia =
false;
231 bool mDrawSleepStats =
false;
232 bool mDrawSoftBodyVertices =
false;
233 bool mDrawSoftBodyVertexVelocities =
false;
234 bool mDrawSoftBodyEdgeConstraints =
false;
235 bool mDrawSoftBodyBendConstraints =
false;
236 bool mDrawSoftBodyVolumeConstraints =
false;
237 bool mDrawSoftBodySkinConstraints =
false;
238 bool mDrawSoftBodyLRAConstraints =
false;
239 bool mDrawSoftBodyPredictedBounds =
false;
246#ifdef JPH_ENABLE_ASSERTS
248 void SetActiveBodiesLocked(
bool inLocked) { mActiveBodiesLocked = inLocked; }
251 class GrantActiveBodiesAccess
254 inline GrantActiveBodiesAccess(
bool inAllowActivation,
bool inAllowDeactivation)
257 sSetOverrideAllowActivation(inAllowActivation);
260 sSetOverrideAllowDeactivation(inAllowDeactivation);
263 inline ~GrantActiveBodiesAccess()
265 sSetOverrideAllowActivation(
false);
266 sSetOverrideAllowDeactivation(
false);
273 void ValidateActiveBodyBounds();
278#ifdef JPH_COMPILER_CLANG
279 __attribute__((no_sanitize(
"implicit-conversion")))
281 inline uint8 GetNextSequenceNumber(
int inBodyIndex) {
return ++mBodySequenceNumbers[inBodyIndex]; }
284 inline void AddBodyToActiveBodies(
Body &ioBody);
287 inline void RemoveBodyFromActiveBodies(
Body &ioBody);
290 JPH_INLINE
Body * RemoveBodyInternal(
const BodyID &inBodyID);
293 inline static void sDeleteBody(
Body *inBody);
295#if defined(_DEBUG) && defined(JPH_ENABLE_ASSERTS)
297 void ValidateFreeList()
const;
307 static constexpr uintptr_t cBodyIDFreeListEnd = ~uintptr_t(0);
310 static constexpr uintptr_t cIsFreedBody = uintptr_t(1);
313 static constexpr uint cFreedBodyIndexShift = 1;
316 uintptr_t mBodyIDFreeListStart = cBodyIDFreeListEnd;
319 mutable Mutex mBodiesMutex;
323 mutable BodyMutexes mBodyMutexes;
329 mutable Mutex mActiveBodiesMutex;
332 BodyID * mActiveBodies[cBodyTypeCount] = { };
335 atomic<uint32> mNumActiveBodies[cBodyTypeCount] = { };
338 uint32 mNumActiveCCDBodies = 0;
341 mutable Mutex mBodiesCacheInvalidMutex;
352#ifdef JPH_ENABLE_ASSERTS
353 static bool sGetOverrideAllowActivation();
354 static void sSetOverrideAllowActivation(
bool inValue);
356 static bool sGetOverrideAllowDeactivation();
357 static void sSetOverrideAllowDeactivation(
bool inValue);
360 bool mActiveBodiesLocked =
false;
Array< Body * > BodyVector
Array of bodies.
Definition: BodyManager.h:25
Array< BodyID > BodyIDVector
Array of body ID's.
Definition: BodyManager.h:28
EBodyType
Type of body.
Definition: BodyType.h:11
std::uint8_t uint8
Definition: Core.h:440
#define JPH_EXPORT
Definition: Core.h:227
std::uint64_t uint64
Definition: Core.h:443
unsigned int uint
Definition: Core.h:439
#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_ASSERT(...)
Definition: IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
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
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
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:89
const BodyID & GetID() const
Get the id of this body.
Definition: Body.h:46
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:32
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:118
Body & GetBody(const BodyID &inID)
Access a body (not protected by lock)
Definition: BodyManager.h:133
BodyActivationListener * GetBodyActivationListener() const
Definition: BodyManager.h:115
uint32 GetNumActiveCCDBodies() const
Get the number of active bodies that are using continuous collision detection.
Definition: BodyManager.h:111
MutexMask GetAllBodiesMutexMask() const
Definition: BodyManager.h:171
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:150
SharedMutex & GetMutexForBody(const BodyID &inID) const
Access the mutex for a single body.
Definition: BodyManager.h:164
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:136
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:105
const BodyVector & GetBodies() const
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition: BodyManager.h:121
BodyVector & GetBodies()
Get all bodies. Note that this can contain invalid body pointers, call sIsValidBodyPointer to check.
Definition: BodyManager.h:124
uint GetMaxBodies() const
Gets the max bodies that we can support.
Definition: BodyManager.h:46
EShapeColor
Definition: BodyManager.h:207
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:186
const Body & GetBody(const BodyID &inID) const
Access a body (not protected by lock)
Definition: BodyManager.h:130
uint64 MutexMask
Bodies are protected using an array of mutexes (so a fixed number, not 1 per body)....
Definition: BodyManager.h:167
uint32 GetNumActiveBodies(EBodyType inType) const
Get the number of active bodies.
Definition: BodyManager.h:108
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:29
Definition: StateRecorder.h:48
Helper struct that counts the number of bodies of each type.
Definition: BodyManager.h:50
Draw settings.
Definition: BodyManager.h:219
Definition: PhysicsSettings.h:28