Пример #1
0
            /************************************************************************************************************************/

            /// <summary>
            /// Sorts all states so that their thresholds go from lowest to highest.
            /// <para></para>
            /// This method uses Bubble Sort which is inefficient for large numbers of states.
            /// </summary>
            public void SortByThresholds()
            {
                var thresholdCount = Thresholds.Length;

                if (thresholdCount <= 1)
                {
                    return;
                }

                var speedCount = Speeds.Length;
                var syncCount  = SynchroniseChildren.Length;

                var previousThreshold = Thresholds[0];

                for (int i = 1; i < thresholdCount; i++)
                {
                    var threshold = Thresholds[i];
                    if (threshold >= previousThreshold)
                    {
                        previousThreshold = threshold;
                        continue;
                    }

                    Thresholds.Swap(i, i - 1);
                    Clips.Swap(i, i - 1);

                    if (i < speedCount)
                    {
                        Speeds.Swap(i, i - 1);
                    }

                    if (i == syncCount && !SynchroniseChildren[i - 1])
                    {
                        var sync = SynchroniseChildren;
                        Array.Resize(ref sync, ++syncCount);
                        sync[i - 1]         = true;
                        sync[i]             = false;
                        SynchroniseChildren = sync;
                    }
                    else if (i < syncCount)
                    {
                        SynchroniseChildren.Swap(i, i - 1);
                    }

                    if (i == 1)
                    {
                        i = 0;
                        previousThreshold = float.NegativeInfinity;
                    }
                    else
                    {
                        i -= 2;
                        previousThreshold = Thresholds[i];
                    }
                }
            }