示例#1
0
        public void ForceRun(int realIndex)
        {
            order1_ = Regenerate(null);
            order2_ = new List <int>();

            active_  = TickInfo.Empty();
            overlap_ = TickInfo.Empty();

            for (int i = 0; i < order1_.Count; ++i)
            {
                var ri = GetRealIndex(i, true);
                Reset(ri);

                if (ri == realIndex)
                {
                    active_.orderIndex = i;
                }
            }

            if (active_.orderIndex == -1)
            {
                LogError($"item {realIndex} not found");
                return;
            }

            Resume(realIndex);
        }
示例#2
0
        public void ItemsChanged()
        {
            Log("items changed, regenerating");

            active_  = TickInfo.Empty();
            overlap_ = TickInfo.Empty();

            order1_ = new List <int>();
            order2_ = new List <int>();
        }
示例#3
0
        private void NextActive()
        {
            Log("\nin NextActive");

            if (order1_.Count == 0)
            {
                Log("NextActive: no elements");
                active_.orderIndex = -1;
                return;
            }

            if (overlap_.orderIndex == -1)
            {
                Log(
                    $"NextActive: initial fwd={active_.forwards} i={active_.orderIndex}");

                int initial = active_.orderIndex;
                if (initial < 0)
                {
                    initial = 0;
                }

                bool reversedDir = false;

                bool atOneEnd = (
                    active_.orderIndex == 0 ||
                    active_.orderIndex == order1_.Count - 1);

                for (; ;)
                {
                    if (active_.orderIndex == initial && reversedDir)
                    {
                        Log(
                            "NextActive: looped around, no valid " +
                            "element, bailing out");

                        active_.orderIndex = -1;
                        break;
                    }

                    if (active_.forwards)
                    {
                        ++active_.orderIndex;
                        Log($"NextActive: checking {active_.orderIndex}");

                        if (active_.orderIndex >= order1_.Count)
                        {
                            Log($"NextActive: {active_.orderIndex} past end, reversing");

                            active_.forwards   = false;
                            active_.orderIndex = order1_.Count - 1;

                            if (atOneEnd)
                            {
                                atOneEnd = false;
                            }
                            else
                            {
                                reversedDir = true;
                            }
                        }

                        Log($"NextActive: i now {active_.orderIndex}");
                    }
                    else
                    {
                        if (active_.orderIndex == 0)
                        {
                            Log($"NextActive: at beginning, going forwards");

                            active_.forwards = true;
                            order1_          = new List <int>(order2_);
                            order2_          = Regenerate(order2_);

                            if (atOneEnd)
                            {
                                atOneEnd = false;
                            }
                            else
                            {
                                reversedDir = true;
                            }
                        }
                        else
                        {
                            --active_.orderIndex;

                            Log($"NextActive: i now {active_.orderIndex}");
                        }
                    }

                    var realIndex = GetRealIndex(active_.orderIndex, true);

                    if (realIndex == -1)
                    {
                        Log("NextActive: GetRealIndex says it's -1, continuing");
                    }
                    else if (!CanRun(realIndex))
                    {
                        Log("NextActive: but it's disabled, continuing");
                    }
                    else if (!active_.forwards && !CanRunBackwards(realIndex))
                    {
                        Log(
                            $"NextActive: index {active_.orderIndex} " +
                            $"enabled but not half move, so doesn't need " +
                            $"ticking; continuing");
                    }
                    else
                    {
                        Log("NextActive: looks good, taking it");
                        break;
                    }
                }
            }
            else
            {
                Log("NextActive: overlap already active, taking over");

                // already an overlap, take it over
                active_ = overlap_;

                if (active_.mustWait)
                {
                    Log("NextActive: overlap was waiting, resuming");

                    var ri = GetRealIndex(active_.orderIndex, true);
                    if (ri == -1)
                    {
                        LogError(
                            $"NextActive: element {active_.orderIndex} not " +
                            $"found while trying to resume a mustWait " +
                            $"overlap");
                    }
                    else
                    {
                        Resume(ri);
                    }

                    active_.mustWait = false;
                }

                Log($"NextActive: i={active_.orderIndex}");

                if (!active_.order1)
                {
                    Log($"NextActive: was in order2, swapping");
                    order1_        = new List <int>(order2_);
                    order2_        = Regenerate(order2_);
                    active_.order1 = true;
                }

                overlap_ = TickInfo.Empty();

                return;
            }


            var newRealIndex = GetRealIndex(active_.orderIndex, true);

            if (newRealIndex != -1)
            {
                overlap_.mustWait = false;

                Log(
                    $"NextActive: resuming {active_.orderIndex}");

                Resume(newRealIndex);
            }
        }