示例#1
0
        private static void SortAllLists(SpriteList spriteList, SortType sortType, PositionedObjectList <Text> textList, List <IDrawableBatch> batches, bool relativeToCamera, Camera camera)
        {
            StoreOldPositionsForDistanceAlongForwardVectorSort(spriteList, sortType, textList, batches, camera);


            #region Sort the SpriteList and get the number of visible Sprites in numberOfVisibleSprites
            if (spriteList != null && spriteList.Count != 0)
            {
                lock (spriteList)
                {
                    switch (sortType)
                    {
                    case SortType.Z:
                    case SortType.DistanceAlongForwardVector:
                        // Sorting ascending means everything will be drawn back to front.  This
                        // is slower but necessary for translucent objects.
                        // Sorting descending means everything will be drawn back to front.  This
                        // is faster but will cause problems for translucency.
                        spriteList.SortZInsertionAscending();
                        break;

                    case SortType.DistanceFromCamera:
                        spriteList.SortCameraDistanceInsersionDescending(camera);
                        break;

                    case SortType.ZSecondaryParentY:
                        spriteList.SortZInsertionAscending();

                        spriteList.SortParentYInsertionDescendingOnZBreaks();

                        break;

                    case SortType.CustomComparer:

                        if (mSpriteComparer != null)
                        {
                            spriteList.Sort(mSpriteComparer);
                        }
                        else
                        {
                            spriteList.SortZInsertionAscending();
                        }

                        break;

                    case SortType.None:
                        // This will improve render times slightly...maybe?
                        spriteList.SortTextureInsertion();
                        break;

                    default:
                        break;
                    }
                }
            }
            #endregion

            #region Sort the TextList
            if (textList != null && textList.Count != 0)
            {
                switch (sortType)
                {
                case SortType.Z:
                case SortType.DistanceAlongForwardVector:
                    textList.SortZInsertionAscending();
                    break;

                case SortType.DistanceFromCamera:
                    textList.SortCameraDistanceInsersionDescending(camera);
                    break;

                case SortType.CustomComparer:
                    if (mTextComparer != null)
                    {
                        textList.Sort(mTextComparer);
                    }
                    else
                    {
                        textList.SortZInsertionAscending();
                    }


                    break;

                default:
                    break;
                }
            }
            #endregion

            #region Sort the Batches
            if (batches != null && batches.Count != 0)
            {
                switch (sortType)
                {
                case SortType.Z:
                    // Z serves as the radius if using SortType.DistanceFromCamera.
                    // If Z represents actual Z or radius, the larger the value the further
                    // away from the camera the object will be.
                    SortBatchesZInsertionAscending(batches);
                    break;

                case SortType.DistanceAlongForwardVector:
                    batches.Sort(new FlatRedBall.Graphics.BatchForwardVectorSorter(camera));
                    break;

                case SortType.ZSecondaryParentY:
                    SortBatchesZInsertionAscending(batches);

                    // Even though the sort type is by parent, IDB doesn't have a Parent object, so we'll just rely on Y.
                    // May need to revisit this if it causes problems
                    SortBatchesYInsertionDescendingOnZBreaks(batches);

                    break;

                case SortType.CustomComparer:

                    if (mDrawableBatchComparer != null)
                    {
                        batches.Sort(mDrawableBatchComparer);
                    }
                    else
                    {
                        SortBatchesZInsertionAscending(batches);
                    }

                    break;
                }
            }
            #endregion
        }
示例#2
0
        private static void SortAllLists(SpriteList spriteList, SortType sortType, PositionedObjectList<Text> textList, List<IDrawableBatch> batches, bool relativeToCamera, Camera camera)
        {
            StoreOldPositionsForDistanceAlongForwardVectorSort(spriteList, sortType, textList, batches, camera);


            #region Sort the SpriteList and get the number of visible Sprites in numberOfVisibleSprites
            if (spriteList != null && spriteList.Count != 0)
            {
                lock (spriteList)
                {
                    switch (sortType)
                    {
                        case SortType.Z:
                        case SortType.DistanceAlongForwardVector:
                            // Sorting ascending means everything will be drawn back to front.  This
                            // is slower but necessary for translucent objects.
                            // Sorting descending means everything will be drawn back to front.  This
                            // is faster but will cause problems for translucency.
                            spriteList.SortZInsertionAscending();
                            break;
                        case SortType.DistanceFromCamera:
                            spriteList.SortCameraDistanceInsersionDescending(camera);
                            break;
                        case SortType.ZSecondaryParentY:
                            spriteList.SortZInsertionAscending();

                            spriteList.SortParentYInsertionDescendingOnZBreaks();

                            break;
                        case SortType.CustomComparer:

                            if (mSpriteComparer != null)
                            {
                                spriteList.Sort(mSpriteComparer);
                            }
                            else
                            {
                                spriteList.SortZInsertionAscending();
                            }

                            break;
                        case SortType.None:
                            // This will improve render times slightly...maybe?
                            spriteList.SortTextureInsertion();
                            break;
                        default:
                            break;
                    }
                }
            }
            #endregion

            #region Sort the TextList
            if (textList != null && textList.Count != 0)
            {
                switch (sortType)
                {
                    case SortType.Z:
                    case SortType.DistanceAlongForwardVector:
                        textList.SortZInsertionAscending();
                        break;
                    case SortType.DistanceFromCamera:
                        textList.SortCameraDistanceInsersionDescending(camera);
                        break;
                    case SortType.CustomComparer:
                        if (mTextComparer != null)
                        {
                            textList.Sort(mTextComparer);
                        }
                        else
                        {
                            textList.SortZInsertionAscending();
                        }


                        break;
                    default:
                        break;
                }
            }
            #endregion

            #region Sort the Batches
            if (batches != null && batches.Count != 0)
            {
                switch (sortType)
                {
                    case SortType.Z:
                        // Z serves as the radius if using SortType.DistanceFromCamera.
                        // If Z represents actual Z or radius, the larger the value the further
                        // away from the camera the object will be.
                        SortBatchesZInsertionAscending(batches);
                        break;
                    case SortType.DistanceAlongForwardVector:
                        batches.Sort(new FlatRedBall.Graphics.BatchForwardVectorSorter(camera));
                        break;

                    case SortType.CustomComparer:

                        if (mDrawableBatchComparer != null)
                        {
                            batches.Sort(mDrawableBatchComparer);
                        }
                        else
                        {
                            SortBatchesZInsertionAscending(batches);
                        }

                        break;

                }
            }
            #endregion
        }