protected override JobHandle OnUpdate(JobHandle inputDeps) { SimulationCallbacks.Callback testTriggerEventsCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyTriggerEventsJob { NumEvents = NumEvents, VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true) }.Schedule(simulation, ref world, inDeps)); }; SimulationCallbacks.Callback testTriggerEventsPostCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyTriggerEventsPostJob { NumEvents = NumEvents, SimulationType = simulation.Type, VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true) }.Schedule(inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsCallback, inputDeps); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsPostCallback, inputDeps); return(inputDeps); }
protected override void OnUpdate() { SimulationCallbacks.Callback testTriggerEventsCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyTriggerEventsJob { NumEvents = NumEvents, VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true) }.Schedule(simulation, ref world, inDeps)); }; SimulationCallbacks.Callback testTriggerEventsPostCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyTriggerEventsPostJob { NumEvents = NumEvents, SimulationType = simulation.Type, VerificationData = GetComponentDataFromEntity <VerifyTriggerEventsData>(true), Entities = m_VerificationGroup.ToEntityArray(Allocator.TempJob) }.Schedule(inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsCallback, Dependency); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventsPostCallback, Dependency); }
protected override void OnUpdate() { if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics) { return; } SimulationCallbacks.Callback preparationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new SetContactFlagsJob { modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true) }.Schedule(simulation, ref world, inDeps)); }; SimulationCallbacks.Callback jacobianModificationCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new ModifyJacobiansJob { modificationData = GetComponentDataFromEntity <ModifyContactJacobians>(true) }.Schedule(simulation, ref world, inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, preparationCallback, Dependency); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContactJacobians, jacobianModificationCallback, Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { SimulationCallbacks.Callback verifyContactsIteratorJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyContactsIteratorJob { CurrentManifoldNumContacts = CurrentManifoldNumContacts, Bodies = world.Bodies, VerificationData = GetComponentDataFromEntity <VerifyContactsIteratorData>(true) }.Schedule(simulation, ref world, inDeps)); }; SimulationCallbacks.Callback verifyNumContactsJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyNumContactsJob { CurrentManifoldNumContacts = CurrentManifoldNumContacts, VerificationData = GetComponentDataFromEntity <VerifyContactsIteratorData>(true) }.Schedule(inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, verifyContactsIteratorJobCallback, inputDeps); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContactJacobians, verifyNumContactsJobCallback, inputDeps); return(inputDeps); }
protected override void OnUpdate() { if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics) { return; } m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, m_PreparationCallback, Dependency); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContactJacobians, m_JacobianModificationCallback, Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawContacts != 0)) { return(inputDeps); } SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) => { inDeps.Complete(); //<todo Necessary to initialize the modifier SimulationData.Contacts contacts = simulation.Contacts; int numWorkItems = contacts.NumWorkItems; if (numWorkItems > 0) { return(new DisplayContactsJob { ManifoldIterator = contacts.GetIterator(), OutputStream = m_DebugStreamSystem.GetContext(numWorkItems) }.Schedule(numWorkItems, 1, inDeps)); } return(inDeps); }; m_StepWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_passThroughQuery.CalculateChunkCount() == 0) { return(inputDeps); } if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics) { return(inputDeps); } // Add a custom callback to the simulation, which will inject our custom job after the body pairs have been created SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { inDeps.Complete(); //<todo Needed to initialize our modifier return(new PassThroughFilterPairsSystemJob { Bodies = m_PhysicsWorld.PhysicsWorld.Bodies, PassThroughGroup = GetComponentDataFromEntity <PassThrough>(true) }.Schedule(simulation, ref world, inputDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_ContactModifierGroup.CalculateLength() == 0) { return(inputDeps); } if (m_StepPhysicsWorld.Simulation.Type == SimulationType.NoPhysics) { return(inputDeps); } var modifiers = m_ContactModifierGroup.ToComponentDataArray <ModifyNarrowphaseContacts>(Allocator.TempJob); var surfaceNormal = modifiers[0].surfaceNormal; var surfaceRBIdx = m_BuildPhysicsWorld.PhysicsWorld.GetRigidBodyIndex(modifiers[0].surfaceEntity); SimulationCallbacks.Callback callback = (ref ISimulation simulation, JobHandle inDeps) => { inDeps.Complete(); // TODO: shouldn't be needed (jobify the below) SimulationData.Contacts.Iterator iterator = simulation.Contacts.GetIterator(); while (iterator.HasItemsLeft()) { ContactHeader manifold = iterator.GetNextContactHeader(); bool bUpdateNormal = (manifold.BodyPair.BodyAIndex == surfaceRBIdx) || (manifold.BodyPair.BodyBIndex == surfaceRBIdx); float distanceScale = 1; if (bUpdateNormal) { var newNormal = surfaceNormal; distanceScale = math.dot(newNormal, manifold.Normal); //<todo.eoin.hpi Feels pretty weird. //<todo.eoin.hp Need to make this work if user has read a contact iterator.SetManifoldNormal(newNormal); } for (int i = 0; i < manifold.NumContacts; i++) { ContactPoint cp = iterator.GetNextContact(); if (bUpdateNormal) { cp.Distance *= distanceScale; iterator.UpdatePreviousContact(cp); } } } return(inDeps); }; modifiers.Dispose(); m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback); return(inputDeps); }
protected override void OnUpdate() { SimulationCallbacks.Callback verifyBodyPairsIteratorJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyBodyPairsIteratorJob { Bodies = world.Bodies, VerificationData = GetComponentDataFromEntity <VerifyBodyPairsIteratorData>(true) }.Schedule(simulation, ref world, inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, verifyBodyPairsIteratorJobCallback, Dependency); }
protected override void OnUpdate() { SimulationCallbacks.Callback testTriggerEventCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyTriggerEventDataJob { Bodies = world.Bodies, VerificationData = GetComponentDataFromEntity <VerifyTriggerEventDataData>(true) }.Schedule(simulation, ref world, inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventCallback, Dependency); }
protected override void OnUpdate() { SimulationCallbacks.Callback verifyPhasedDispatchPairsJobCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyPhasedDispatchPairsJob { VerificationData = GetComponentDataFromEntity <VerifyPhasedDispatchPairsData>(true), LastStaticPairPerDynamicBody = new NativeArray <int>(world.NumDynamicBodies, Allocator.TempJob), IsUnityPhysics = simulation.Type == SimulationType.UnityPhysics }.Schedule(simulation, ref world, inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, verifyPhasedDispatchPairsJobCallback, Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { SimulationCallbacks.Callback testCollisionEventCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) => { return(new VerifyCollisionEventDataJob { World = world, Bodies = world.Bodies, VerificationData = GetComponentDataFromEntity <VerifyCollisionEventDataData>(true) }.Schedule(simulation, ref world, inDeps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testCollisionEventCallback, inputDeps); return(inputDeps); }
protected override void OnUpdate() { if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawColliderAabbs != 0)) { return; } if (m_BuildPhysicsWorldSystem.PhysicsWorld.NumBodies == 0) { return; } SimulationCallbacks.Callback callback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle deps) => { return(new DisplayColliderAabbsJob { OutputStream = m_DebugStreamSystem.GetContext(1), Bodies = m_BuildPhysicsWorldSystem.PhysicsWorld.Bodies }.Schedule(deps)); }; m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateDispatchPairs, callback); }
protected override JobHandle OnUpdate(JobHandle handle) { // delegate for physics to add my jobs to its pipeline SimulationCallbacks.Callback callback = (ref ISimulation sim, ref PhysicsWorld world, JobHandle deps) => { // delete containers from previous frame DisposeContainers(); JobHandle playerToBulletCollect = InitCollectBulletDataJob(ref sim, ref world, deps, ObjectType.Player, ObjectType.EnemyBullet); JobHandle enemyToBulletCollect = InitCollectBulletDataJob(ref sim, ref world, deps, ObjectType.Enemy, ObjectType.PlayerBullet); JobHandle processJob = InitProcessJobs(playerToBulletCollect, enemyToBulletCollect); job = processJob; return(processJob); }; stepPhysWorld.EnqueueCallback(SimulationCallbacks.Phase.PostCreateContacts, callback); return(handle); }