Skip to content

Commit

Permalink
Renaming Body::ResetSleepTestSpheres to ResetSleepTimer and making it…
Browse files Browse the repository at this point in the history
… public. (#814)

This allows more fine grained control over when an object goes to sleep.
  • Loading branch information
jrouwe authored Dec 21, 2023
1 parent 19eba95 commit 38e6435
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Jolt/Physics/Body/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Body::SetAllowSleeping(bool inAllow)
{
mMotionProperties->mAllowSleeping = inAllow;
if (inAllow)
ResetSleepTestSpheres();
ResetSleepTimer();
}

void Body::MoveKinematic(RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime)
Expand All @@ -99,7 +99,7 @@ void Body::CalculateWorldSpaceBoundsInternal()
mBounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sReplicate(1.0f));
}

void Body::SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTestSpheres)
void Body::SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTimer)
{
JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sPositionAccess, BodyAccess::EAccess::ReadWrite));

Expand All @@ -110,8 +110,8 @@ void Body::SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotatio
CalculateWorldSpaceBoundsInternal();

// Reset sleeping test
if (inResetSleepTestSpheres && mMotionProperties != nullptr)
ResetSleepTestSpheres();
if (inResetSleepTimer && mMotionProperties != nullptr)
ResetSleepTimer();
}

void Body::UpdateCenterOfMassInternal(Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties)
Expand Down
6 changes: 4 additions & 2 deletions Jolt/Physics/Body/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
bool GetAllowSleeping() const { return mMotionProperties->mAllowSleeping; }
void SetAllowSleeping(bool inAllow);

/// Resets the sleep timer. This does not wake up the body if it is sleeping, but allows resetting the system that detects when a body is sleeping.
inline void ResetSleepTimer();

/// Friction (dimensionless number, usually between 0 and 1, 0 = no friction, 1 = friction force equals force that presses the two bodies together). Note that bodies can have negative friction but the combined friction (see PhysicsSystem::SetCombineFriction) should never go below zero.
inline float GetFriction() const { return mFriction; }
void SetFriction(float inFriction) { mFriction = inFriction; }
Expand Down Expand Up @@ -289,7 +292,7 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
void CalculateWorldSpaceBoundsInternal();

/// Function to update body's position (should only be called by the BodyInterface since it also requires updating the broadphase)
void SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTestSpheres = true);
void SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTimer = true);

/// Updates the center of mass and optionally mass propertes after shifting the center of mass or changes to the shape (should only be called by the BodyInterface since it also requires updating the broadphase)
/// @param inPreviousCenterOfMass Center of mass of the shape before the alterations
Expand Down Expand Up @@ -323,7 +326,6 @@ class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public
explicit Body(bool); ///< Alternative constructor that initializes all members

inline void GetSleepTestPoints(RVec3 *outPoints) const; ///< Determine points to test for checking if body is sleeping: COM, COM + largest bounding box axis, COM + second largest bounding box axis
inline void ResetSleepTestSpheres(); ///< Reset spheres to current position as returned by GetSleepTestPoints

enum class EFlags : uint8
{
Expand Down
2 changes: 1 addition & 1 deletion Jolt/Physics/Body/Body.inl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Body::GetSleepTestPoints(RVec3 *outPoints) const
}
}

void Body::ResetSleepTestSpheres()
void Body::ResetSleepTimer()
{
RVec3 points[3];
GetSleepTestPoints(points);
Expand Down
2 changes: 1 addition & 1 deletion Jolt/Physics/Body/BodyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ void BodyManager::ActivateBodies(const BodyID *inBodyIDs, int inNumber)
&& body.mMotionProperties->mIndexInActiveBodies == Body::cInactiveIndex)
{
// Reset sleeping
body.ResetSleepTestSpheres();
body.ResetSleepTimer();

AddBodyToActiveBodies(body);

Expand Down

0 comments on commit 38e6435

Please sign in to comment.