Exemplo n.º 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (!PhysicsSystem.CollisionManifoldsArray.IsCreated)
            {
                return(inputDeps);
            }

            inputDeps.Complete();


            var buildConstraints = new BuildSystemConstraints
            {
                ConstraintsQueue        = ConstraintsQueue,
                CollisionManifoldsArray = PhysicsSystem.CollisionManifoldsArray,
                RigidBodyFromEntity     = RigidBodyFromEntity,
            }.Schedule(inputDeps);

            buildConstraints.Complete();

            if (PhysicsSystem.ConstraintsArray.IsCreated)
            {
                PhysicsSystem.ConstraintsArray.Dispose();
            }
            PhysicsSystem.ConstraintsArray = new NativeArray <Constraint>(ConstraintsQueue.Count, Allocator.TempJob);
            DequeueIntoArray <Constraint> dequeueManifoldsJob = new DequeueIntoArray <Constraint>()
            {
                InputQueue  = ConstraintsQueue,
                OutputArray = PhysicsSystem.ConstraintsArray,
            };
            JobHandle dequeueCollisionManifolds = dequeueManifoldsJob.Schedule(buildConstraints);

            // Need to complete jobs here because counter will be read in the next system
            dequeueCollisionManifolds.Complete();

            var solveConstraints = new SolveConstraintsSequentialImpulses
            {
                IterationsCount           = PhysicsSystem.Settings.ConstraintSolverIterations,
                DeltaTime                 = PhysicsSystem.DeltaTime,
                BaumgarteBias             = PhysicsSystem.Settings.BaumgarteBias,
                RigidBodyFromEntity       = RigidBodyFromEntity,
                VelocityFromEntity        = VelocityFromEntity,
                AngularVelocityFromEntity = AngularVelocityFromEntity,
                ConstraintsArray          = PhysicsSystem.ConstraintsArray,
            }.Schedule(buildConstraints);

            solveConstraints.Complete();

            return(solveConstraints);
        }
Exemplo n.º 2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (!PhysicsSystem.CollisionManifoldsArray.IsCreated)
            {
                return(inputDeps);
            }

            if (!PhysicsSystem.ConstraintsArray.IsCreated)
            {
                PhysicsSystem.ConstraintsArray = new NativeArray <Constraint>(1000000, Allocator.Persistent);
            }

            if (!PhysicsSystem.ConstraintsCounter.IsCreated)
            {
                PhysicsSystem.ConstraintsCounter = new NativeCounter(Allocator.Persistent);
            }

            PhysicsSystem.ConstraintsCounter.Count = 0;

            inputDeps.Complete();

            var buildConstraints = new BuildSystemConstraints
            {
                ConstraintsCounter      = PhysicsSystem.ConstraintsCounter,
                ConstraintsArray        = PhysicsSystem.ConstraintsArray,
                CollisionManifoldsArray = PhysicsSystem.CollisionManifoldsArray,
                RigidBodyFromEntity     = RigidBodyFromEntity,
            }.Schedule(inputDeps);

            buildConstraints.Complete();

            var solveConstraints = new SolveConstraintsSequentialImpulses
            {
                IterationsCount           = PhysicsSystem.Settings.ConstraintSolverIterations,
                DeltaTime                 = PhysicsSystem.DeltaTime,
                BaumgarteBias             = PhysicsSystem.Settings.BaumgarteBias,
                RigidBodyFromEntity       = RigidBodyFromEntity,
                VelocityFromEntity        = VelocityFromEntity,
                AngularVelocityFromEntity = AngularVelocityFromEntity,
                ConstraintsCounter        = PhysicsSystem.ConstraintsCounter,
                ConstraintsArray          = PhysicsSystem.ConstraintsArray,
            }.Schedule(buildConstraints);

            solveConstraints.Complete();

            return(solveConstraints);
        }