public unsafe static void Execute(ref BodyPairsJobData <T> jobData, IntPtr additionalData, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex) { for (int currentIdx = 0; currentIdx < jobData.PhasedDispatchPairs.Length; currentIdx++) { // Skip joint pairs if (jobData.PhasedDispatchPairs[currentIdx].IsJoint) { continue; } DispatchPairSequencer.DispatchPair dispatchPair = jobData.PhasedDispatchPairs[currentIdx]; var pair = new ModifiableBodyPair { BodyIndexPair = new BodyIndexPair { BodyIndexA = dispatchPair.BodyIndexA, BodyIndexB = dispatchPair.BodyIndexB }, EntityPair = new EntityPair { EntityA = jobData.Bodies[dispatchPair.BodyIndexA].Entity, EntityB = jobData.Bodies[dispatchPair.BodyIndexB].Entity } }; jobData.UserJobData.Execute(ref pair); if (pair.BodyIndexA == -1 || pair.BodyIndexB == -1) { jobData.PhasedDispatchPairs[currentIdx] = DispatchPairSequencer.DispatchPair.Invalid; } } }
internal static unsafe void ExecuteImpl(ref PhysicsWorld world, float timeStep, NativeArray <DispatchPairSequencer.DispatchPair> dispatchPairs, int dispatchPairReadOffset, int numPairsToRead, ref NativeStream.Writer contactWriter) { for (int i = 0; i < numPairsToRead; i++) { DispatchPairSequencer.DispatchPair dispatchPair = dispatchPairs[dispatchPairReadOffset + i]; // Invalid pairs can exist by being disabled by users if (dispatchPair.IsValid) { if (dispatchPair.IsContact) { // Create contact manifolds for this pair of bodies var pair = new BodyIndexPair { BodyIndexA = dispatchPair.BodyIndexA, BodyIndexB = dispatchPair.BodyIndexB }; RigidBody rigidBodyA = world.Bodies[pair.BodyIndexA]; RigidBody rigidBodyB = world.Bodies[pair.BodyIndexB]; MotionVelocity motionVelocityA = pair.BodyIndexA < world.MotionVelocities.Length ? world.MotionVelocities[pair.BodyIndexA] : MotionVelocity.Zero; MotionVelocity motionVelocityB = pair.BodyIndexB < world.MotionVelocities.Length ? world.MotionVelocities[pair.BodyIndexB] : MotionVelocity.Zero; ManifoldQueries.BodyBody(rigidBodyA, rigidBodyB, motionVelocityA, motionVelocityB, world.CollisionWorld.CollisionTolerance, timeStep, pair, ref contactWriter); } } } }
public unsafe static void Execute(ref BodyPairsJobData <T> jobData, IntPtr additionalData, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex) { int currentIdx = 0; while (currentIdx < jobData.PhasedDispatchPairs.Length) { DispatchPairSequencer.DispatchPair dispatchPair = jobData.PhasedDispatchPairs[currentIdx]; var pair = new ModifiableBodyPair { BodyIndices = new BodyIndexPair { BodyAIndex = dispatchPair.BodyAIndex, BodyBIndex = dispatchPair.BodyBIndex }, Entities = new EntityPair { EntityA = jobData.Bodies[dispatchPair.BodyAIndex].Entity, EntityB = jobData.Bodies[dispatchPair.BodyBIndex].Entity } }; jobData.UserJobData.Execute(ref pair); if (pair.BodyIndices.BodyAIndex == -1 || pair.BodyIndices.BodyBIndex == -1) { jobData.PhasedDispatchPairs[currentIdx] = DispatchPairSequencer.DispatchPair.Invalid; } do { currentIdx++; } while (currentIdx < jobData.PhasedDispatchPairs.Length && jobData.PhasedDispatchPairs[currentIdx].IsJoint); } }