Ver código fonte

Moved sFinalizeContactAllocator to PhysicsSystem to avoid having to include PhysicsUpdateContext

Jorrit Rouwe 2 anos atrás
pai
commit
a468ac0e34

+ 0 - 10
Jolt/Physics/Constraints/ContactConstraintManager.cpp

@@ -620,16 +620,6 @@ void ContactConstraintManager::PrepareConstraintBuffer(PhysicsUpdateContext *inC
 	mConstraints = (ContactConstraint *)inContext->mTempAllocator->Allocate(mMaxConstraints * sizeof(ContactConstraint));
 }
 
-void ContactConstraintManager::sFinalizeContactAllocator(PhysicsUpdateContext::Step &ioStep, const ContactAllocator &inAllocator)
-{
-	// Atomically accumulate the number of found manifolds and body pairs
-	ioStep.mNumBodyPairs += inAllocator.mNumBodyPairs;
-	ioStep.mNumManifolds += inAllocator.mNumManifolds;
-
-	// Combine update errors
-	ioStep.mContext->mErrors.fetch_or((uint32)inAllocator.mErrors, memory_order_relaxed);
-}
-
 template <EMotionType Type1, EMotionType Type2>
 JPH_INLINE void ContactConstraintManager::TemplatedCalculateFrictionAndNonPenetrationConstraintProperties(ContactConstraint &ioConstraint, float inDeltaTime, RMat44Arg inTransformBody1, RMat44Arg inTransformBody2, const Body &inBody1, const Body &inBody2, Mat44Arg inInvI1, Mat44Arg inInvI2)
 {

+ 0 - 4
Jolt/Physics/Constraints/ContactConstraintManager.h

@@ -7,7 +7,6 @@
 #include <Jolt/Core/StaticArray.h>
 #include <Jolt/Core/LockFreeHashMap.h>
 #include <Jolt/Physics/EPhysicsUpdateError.h>
-#include <Jolt/Physics/PhysicsUpdateContext.h>
 #include <Jolt/Physics/Body/BodyPair.h>
 #include <Jolt/Physics/Collision/Shape/SubShapeIDPair.h>
 #include <Jolt/Physics/Collision/ManifoldBetweenTwoFaces.h>
@@ -88,9 +87,6 @@ public:
 	/// Get a new allocator context for storing contacts. Note that you should call this once and then add multiple contacts using the context.
 	ContactAllocator			GetContactAllocator()												{ return mCache[mCacheWriteIdx].GetContactAllocator(); }
 
-	/// Collect information from the contact allocator and accumulate it in the step.
-	static void					sFinalizeContactAllocator(PhysicsUpdateContext::Step &ioStep, const ContactAllocator &inAllocator);
-
 	/// Check if the contact points from the previous frame are reusable and if so copy them.
 	/// When the cache was usable and the pair has been handled: outPairHandled = true.
 	/// When a contact constraint was produced: outConstraintCreated = true.

+ 12 - 2
Jolt/Physics/PhysicsSystem.cpp

@@ -811,6 +811,16 @@ void PhysicsSystem::TrySpawnJobFindCollisions(PhysicsUpdateContext::Step *ioStep
 	}
 }
 
+static void sFinalizeContactAllocator(PhysicsUpdateContext::Step &ioStep, const ContactConstraintManager::ContactAllocator &inAllocator)
+{
+	// Atomically accumulate the number of found manifolds and body pairs
+	ioStep.mNumBodyPairs.fetch_add(inAllocator.mNumBodyPairs, memory_order_relaxed);
+	ioStep.mNumManifolds.fetch_add(inAllocator.mNumManifolds, memory_order_relaxed);
+
+	// Combine update errors
+	ioStep.mContext->mErrors.fetch_or((uint32)inAllocator.mErrors, memory_order_relaxed);
+}
+
 void PhysicsSystem::JobFindCollisions(PhysicsUpdateContext::Step *ioStep, int inJobIndex)
 {
 #ifdef JPH_ENABLE_ASSERTS
@@ -914,7 +924,7 @@ void PhysicsSystem::JobFindCollisions(PhysicsUpdateContext::Step *ioStep, int in
 					if (read_queue_idx == first_read_queue_idx)
 					{
 						// Collect information from the contact allocator and accumulate it in the step.
-						ContactConstraintManager::sFinalizeContactAllocator(*ioStep, contact_allocator);
+						sFinalizeContactAllocator(*ioStep, contact_allocator);
 
 						// Mark this job as inactive
 						ioStep->mActiveFindCollisionJobs.fetch_and(~PhysicsUpdateContext::JobMask(1 << inJobIndex));
@@ -1919,7 +1929,7 @@ void PhysicsSystem::JobFindCCDContacts(const PhysicsUpdateContext *ioContext, Ph
 	}
 
 	// Collect information from the contact allocator and accumulate it in the step.
-	ContactConstraintManager::sFinalizeContactAllocator(*ioSubStep->mStep, contact_allocator);
+	sFinalizeContactAllocator(*ioSubStep->mStep, contact_allocator);
 }
 
 void PhysicsSystem::JobResolveCCDContacts(PhysicsUpdateContext *ioContext, PhysicsUpdateContext::SubStep *ioSubStep)