コード例 #1
0
        // Schedule() implementation for ICollisionEventsJob when Havok Physics is available
        public static unsafe JobHandle Schedule <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps)
            where T : struct, ICollisionEventsJobBase
        {
            switch (simulation.Type)
            {
            case SimulationType.UnityPhysics:
                // Call the scheduling method for Unity.Physics
                return(ICollisionEventJobExtensions.ScheduleUnityPhysicsCollisionEventsJob(jobData, simulation, ref world, inputDeps));

            case SimulationType.HavokPhysics:
            {
                var data = new CollisionEventJobData <T>
                {
                    UserJobData = jobData,
                    EventReader = ((Havok.Physics.HavokSimulation)simulation).CollisionEvents
                };

                // 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),
                    CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched);
                return(JobsUtility.Schedule(ref parameters));
            }

            default:
                return(inputDeps);
            }
        }
コード例 #2
0
        // Schedules a collision events job only for UnityPhysics simulation
        internal static unsafe JobHandle ScheduleUnityPhysicsCollisionEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps)
            where T : struct, ICollisionEventsJobBase
        {
            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 CollisionEventJobData <T>
            {
                UserJobData = jobData,
                EventReader = ((Simulation)simulation).CollisionEvents
            };

            // 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), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched);

            return(JobsUtility.Schedule(ref parameters));
        }
コード例 #3
0
        // Schedules a collision events job only for UnityPhysics simulation
        internal static unsafe JobHandle ScheduleUnityPhysicsCollisionEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps)
            where T : struct, ICollisionEventsJobBase
        {
            SafetyChecks.CheckAreEqualAndThrow(SimulationType.UnityPhysics, simulation.Type);

            var data = new CollisionEventJobData <T>
            {
                UserJobData = jobData,
                EventReader = ((Simulation)simulation).CollisionEvents
            };

            // Ensure the input dependencies include the end-of-simulation job, so events will have been generated
            inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle);
#if UNITY_2020_2_OR_NEWER
            var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Single);
#else
            var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched);
#endif
            return(JobsUtility.Schedule(ref parameters));
        }
コード例 #4
0
        internal static unsafe JobHandle ScheduleImpl <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps)
            where T : struct, ICollisionEventsJob
        {
            if (simulation.Type == SimulationType.UnityPhysics)
            {
                var data = new CollisionEventJobData <T>
                {
                    UserJobData     = jobData,
                    EventReader     = ((Simulation)simulation).CollisionEvents,
                    Bodies          = world.Bodies,
                    TimeStep        = ((Simulation)simulation).m_Context.TimeStep,
                    InputVelocities = ((Simulation)simulation).m_Context.InputVelocities
                };

                // 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), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched);
                return(JobsUtility.Schedule(ref parameters));
            }
            return(inputDeps);
        }