Exemplo n.º 1
0
        // Schedule a set of jobs to synchronize the collision world with the dynamics world.
        internal JobHandle ScheduleUpdateDynamicTree(ref PhysicsWorld world, JobHandle inputDeps)
        {
            if (world.Settings.NumberOfThreadsHint <= 1)
            {
                return(new UpdateDynamicLayerJob
                {
                    World = world,
                    TimeStep = world.TimeStep,
                    Gravity = world.Settings.Gravity
                }.Schedule(inputDeps));
            }

            // Synchronize transforms
            var handle = new UpdatePhysicsBodyTransformsJob
            {
                MotionDatas   = world.BodyMotionData,
                PhysicsBodies = m_PhysicsBodies
            }.Schedule(world.BodyMotionData.Length, 32, inputDeps);

            // Update broadphase
            return(Broadphase.ScheduleDynamicTreeBuildJobs(ref world, handle));
        }
Exemplo n.º 2
0
        // Schedule all the jobs for the simulation step.
        public SimulationJobHandles ScheduleStepJobs(PhysicsWorld physicsWorld, PhysicsCallbacks physicsCallbacks, JobHandle inputDeps)
        {
            var physicsSettings = physicsWorld.Settings;

            SafetyChecks.IsFalse(physicsWorld.TimeStep < 0f);

            SimulationContext.Reset(ref physicsWorld, false);
            SimulationContext.TimeStep = physicsWorld.TimeStep;

            if (physicsWorld.DynamicBodyCount == 0)
            {
                // No need to do anything, since nothing can move
                m_StepHandles = new SimulationJobHandles(inputDeps);
                return(m_StepHandles);
            }

            // Execute phase callback.
            var handle = physicsCallbacks.ScheduleCallbacksForPhase(PhysicsCallbacks.Phase.PreStepSimulation, ref physicsWorld, inputDeps);

            // Apply gravity and copy input velocities at this point (in parallel with the scheduler, but before the callbacks)
            handle = Solver.ScheduleApplyGravityAndCopyInputVelocitiesJob(
                ref physicsWorld.DynamicsWorld, SimulationContext.InputVelocities, physicsWorld.TimeStep * physicsSettings.Gravity, handle, physicsSettings.NumberOfThreadsHint);

            handle = physicsCallbacks.ScheduleCallbacksForPhase(PhysicsCallbacks.Phase.PostCreateOverlapBodies, ref physicsWorld, handle);
            handle = physicsCallbacks.ScheduleCallbacksForPhase(PhysicsCallbacks.Phase.PostCreateContacts, ref physicsWorld, handle);
            handle = physicsCallbacks.ScheduleCallbacksForPhase(PhysicsCallbacks.Phase.PostCreateConstraints, ref physicsWorld, handle);

            // Integrate motions.
            handle = Integrator.ScheduleIntegrateJobs(ref physicsWorld, handle, physicsSettings.NumberOfThreadsHint);

            // Schedule phase callback.
            handle = physicsCallbacks.ScheduleCallbacksForPhase(PhysicsCallbacks.Phase.PostIntegrate, ref physicsWorld, handle);

            m_StepHandles.FinalExecutionHandle = handle;
            m_StepHandles.FinalDisposeHandle   = handle;

            return(m_StepHandles);
        }
Exemplo n.º 3
0
 internal JobHandle ScheduleCallbacksForPhase(Phase phase, ref PhysicsWorld physicsWorld, JobHandle inputDeps)
 {
     ref var callbacks     = ref m_Callbacks[(int)phase];
Exemplo n.º 4
0
 // Schedule a set of jobs to build the broadphase based on the given world.
 internal JobHandle ScheduleBuildBroadphaseJobs(ref PhysicsWorld world, NativeArray <int> buildStaticTree, JobHandle inputDeps)
 {
     return(Broadphase.ScheduleBuildJobs(ref world, buildStaticTree, inputDeps));
 }
Exemplo n.º 5
0
 public SimulationJobHandles ScheduleStepJobs(PhysicsWorld physicsWorld, PhysicsCallbacks callbacks, JobHandle inputDeps) => new SimulationJobHandles(inputDeps);