Przeglądaj źródła

Add a helper to manually invalidate contact cache (#109)

Joshie 3 lat temu
rodzic
commit
2567681e4d

+ 7 - 0
Jolt/Physics/Body/BodyInterface.cpp

@@ -811,4 +811,11 @@ const PhysicsMaterial *BodyInterface::GetMaterial(const BodyID &inBodyID, const
 		return PhysicsMaterial::sDefault;
 }
 
+void BodyInterface::InvalidateContactCache(const BodyID &inBodyID)
+{
+	BodyLockWrite lock(*mBodyLockInterface, inBodyID);
+	if (lock.Succeeded())
+		mBodyManager->InvalidateContactCacheForBody(lock.GetBody());
+}
+
 JPH_NAMESPACE_END

+ 3 - 0
Jolt/Physics/Body/BodyInterface.h

@@ -186,6 +186,9 @@ public:
 	/// Get the material for a particular sub shape
 	const PhysicsMaterial *		GetMaterial(const BodyID &inBodyID, const SubShapeID &inSubShapeID) const;
 
+	/// Set the Body::EFlags::InvalidateContactCache flag for the specified body. This means that the collision cache is invalid for any body pair involving that body until the next physics step.
+	void						InvalidateContactCache(const BodyID &inBodyID);
+
 private:
 	BodyLockInterface *			mBodyLockInterface = nullptr;
 	BodyManager *				mBodyManager = nullptr;