Esempio n. 1
0
        /// <summary>
        /// 物理接口,如果要更新物理数据,需要在里面填入相关的信息
        /// </summary>
        /// <param name="deltaTime"></param>
        /// <param name="scale"></param>
        /// <param name="iteration"></param>
        /// <param name="addForce"></param>
        /// <param name="colliderCollisionType"></param>
        /// <param name="isOptimize"></param>
        /// <param name="detectAsync"></param>
        /// <param name="isFuzzyCompute"></param>
        /// <returns></returns>
        internal bool SetRuntimeData(float deltaTime, float scale, ref int iteration, Vector3 addForce, ColliderCollisionType colliderCollisionType, bool isOptimize, bool detectAsync, bool isFuzzyCompute)
        {
            if (!Hjob.IsCompleted)
            {
                if (!detectAsync)
                {
                    iteration = Mathf.CeilToInt(iteration * 0.99f);
                    Debug.Log("检测到发生异步,自动修正迭代次数到 " + iteration);
                }

                return(false);
            }

            //OYM:当我用ADBRunTimeJobsTable.returnHJob时候,任务会在我调用的时候被强制完成,当我用本地的Hjob的时候,任务会在异步进行
            //OYM:  注意,JH底层很可能也是单例

            //OYM:  赋参
            constraintUpdates1.oneDivideIteration = pointUpdate.oneDivideIteration = colliderGet.oneDivideIteration = pointGet.oneDivideIteration = 1.0f / iteration;
            pointUpdate.deltaTime     = deltaTime;
            pointUpdate.globalScale   = scale;
            pointUpdate.isOptimize    = isOptimize;
            pointUpdate.addForcePower = addForce;
            pointUpdate.isCollision   = (colliderCollisionType == ColliderCollisionType.Both || colliderCollisionType == ColliderCollisionType.Point);

            //OYM:  上面这个是防迭代顺序错乱而设置强制顺序
            for (int i = 0; i < constraintUpdates.Length; i++)
            {
                constraintUpdates[i].globalScale = scale;
                constraintUpdates[i].isCollision = (colliderCollisionType == ColliderCollisionType.Both || colliderCollisionType == ColliderCollisionType.Constraint);
            }
            //OYM:  下面就是随机顺序了
            constraintUpdates1.globalScale = scale;
            constraintUpdates1.isCollision = (colliderCollisionType == ColliderCollisionType.Both || colliderCollisionType == ColliderCollisionType.Constraint);;

            #region LifeCycle

#if ADB_DEBUG
            pointGet.TryExecute(pointTransformsList, Hjob);
#else
            Hjob = colliderGet.Schedule(colliderTransformsList);
            Hjob = pointGet.Schedule(pointTransformsList);
#endif

            for (int i = 0; i < iteration; i++)
            {
#if ADB_DEBUG
                colliderUpdate.TryExecute(collidersReadList.Length, batchLength, Hjob);

                pointUpdate.TryExecute(pointReadList.Length, batchLength, Hjob);
                for (int j0 = 0; j0 < constraintUpdates.Length; j0++)
                {
                    constraintUpdates[j0].TryExecute(constraintReadList[j0].Length, batchLength, Hjob);
                }
#else
                if (isFuzzyCompute)
                {
                    Hjob = colliderUpdate.Schedule(collidersReadList.Length, batchLength);
                    Hjob = pointUpdate.Schedule(pointReadList.Length, batchLength);
                    Hjob = constraintUpdates1.Schedule(constraintReadList1.Length, batchLength);
                }
                else
                {
                    Hjob = colliderUpdate.Schedule(collidersReadList.Length, batchLength, Hjob);
                    Hjob = pointUpdate.Schedule(pointReadList.Length, batchLength, Hjob);
                    Hjob = constraintUpdates1.Schedule(constraintReadList1.Length, batchLength, Hjob);
                }
#endif
            }

#if ADB_DEBUG
            pointToTransform.TryExecute(pointTransformsList, Hjob);
#else
            Hjob = pointToTransform.Schedule(pointTransformsList);
#endif
            #endregion

            return(true);
        }
Esempio n. 2
0
        internal bool SetRuntimeData(float deltaTime, float scale, int iteration, Vector3 addForceForce, ColliderCollisionType colliderCollisionType, bool isOptimize)
        {
            int batchLength = isTryExcute ? 1 : 64;

            iteration = isTryExcute ? 1 : iteration;

            JobHandle Hjob = ADBRunTimeJobsTable.returnHJob;

            if (!Hjob.IsCompleted)
            {
                return(false);
            }

            constraintUpdates1.oneDivideIteration = pointUpdate.oneDivideIteration = colliderGet.oneDivideIteration = pointGet.oneDivideIteration = 1.0f / iteration;

            pointUpdate.deltaTime     = deltaTime;
            pointUpdate.globalScale   = scale;
            pointUpdate.isOptimize    = isOptimize;
            pointUpdate.addForcePower = addForceForce;
            pointUpdate.isCollision   = (colliderCollisionType == ColliderCollisionType.Fast);

            for (int i = 0; i < constraintUpdates.Length; i++)
            {
                constraintUpdates[i].globalScale = scale;
                constraintUpdates[i].isCollision = (colliderCollisionType == ColliderCollisionType.Accuate);
            }
            constraintUpdates1.globalScale = scale;
            constraintUpdates1.isCollision = (colliderCollisionType == ColliderCollisionType.Accuate);

            #region LifeCycle
            Hjob = colliderGet.Schedule(colliderTransformsList);
            Hjob = pointGet.Schedule(pointTransformsList);

            //pointGet.TryExecute(pointTransformsList, Hjob);

            for (int i = 0; i < iteration; i++)
            {
                if (isTryExcute)
                {
                    colliderUpdate.TryExecute(collidersReadList.Length, batchLength, Hjob);

                    pointUpdate.TryExecute(pointReadList.Length, batchLength, Hjob);
                    for (int j0 = 0; j0 < constraintUpdates.Length; j0++)
                    {
                        constraintUpdates[j0].TryExecute(constraintReadList[j0].Length, batchLength, Hjob);
                    }
                }
                else
                {
                    Hjob = colliderUpdate.Schedule(collidersReadList.Length, batchLength);
                    //Hjob = fixedPointUpdate.Schedule(pointReadList.Length, batchLength);
                    Hjob = pointUpdate.Schedule(pointReadList.Length, batchLength);
                    Hjob = constraintUpdates1.Schedule(constraintReadList1.Length, batchLength);
                }
            }

            Hjob = pointToTransform.Schedule(pointTransformsList);
            #endregion
            // pointToTransform.TryExecute(pointTransformsList, Hjob);

            return(true);
        }