// Schedule() implementation for ITriggerEventsJob when Havok Physics is available public static unsafe JobHandle Schedule <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ITriggerEventsJob { switch (simulation.Type) { case SimulationType.UnityPhysics: // Call the scheduling method for Unity.Physics return(ITriggerEventJobExtensions.ScheduleUnityPhysicsTriggerEventsJob(jobData, simulation, ref world, inputDeps)); case SimulationType.HavokPhysics: { var data = new TriggerEventJobData <T> { UserJobData = jobData, EventReader = ((Havok.Physics.HavokSimulation)simulation).TriggerEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), TriggerEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); } default: return(inputDeps); } }
// Schedules a trigger events job only for UnityPhysics simulation internal static unsafe JobHandle ScheduleUnityPhysicsTriggerEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ITriggerEventsJobBase { if (simulation.Type != SimulationType.UnityPhysics) { throw new ArgumentException($"Simulation type {simulation.Type} is not supported! Should be called only for SimulationType.UnityPhysics."); } var data = new TriggerEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).TriggerEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), TriggerEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
// Schedules a trigger events job only for UnityPhysics simulation internal static unsafe JobHandle ScheduleUnityPhysicsTriggerEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ITriggerEventsJobBase { SafetyChecks.CheckAreEqualAndThrow(SimulationType.UnityPhysics, simulation.Type); var data = new TriggerEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).TriggerEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), TriggerEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }