Пример #1
0
        // Removes the first Fiber from the given list.
        private Fiber RemoveFirst(ref YieldList ioList)
        {
            int fiberIndex = ioList.Head;

            if (fiberIndex == -1)
            {
                return(null);
            }

            int nextIndex = m_Entries[fiberIndex].YieldNext;
            int prevIndex = m_Entries[fiberIndex].YieldPrev;

            // If the table only has one entry,
            // just remove it and set the table to empty.
            if (nextIndex == -1)
            {
                m_Entries[fiberIndex].YieldPrev = -1;
                ioList.Head = -1;
                --ioList.Count;
                return(m_Entries[fiberIndex].Fiber);
            }

            // Point the next entry at the last entry
            m_Entries[nextIndex].YieldPrev = prevIndex;

            // Clear pointers in the current entry
            m_Entries[fiberIndex].YieldNext = -1;
            m_Entries[fiberIndex].YieldPrev = -1;

            // Point to the next entry as the first.
            ioList.Head = nextIndex;
            --ioList.Count;

            return(m_Entries[fiberIndex].Fiber);
        }
Пример #2
0
        // Removes an entry from the Fiber list.
        private void RemoveEntry(Fiber inFiber, ref YieldList ioList)
        {
            int fiberIndex = (int)inFiber.Index;
            int nextIndex  = m_Entries[fiberIndex].YieldNext;
            int prevIndex  = m_Entries[fiberIndex].YieldPrev;

            // If the list is already empty, we can't do anything about it
            if (ioList.Head == -1)
            {
                return;
            }

            // Ensure the next entry is pointing back to our previous index.
            m_Entries[nextIndex == -1 ? ioList.Head : nextIndex].YieldPrev = prevIndex;

            // If we're the first entry, the first entry is now our last
            if (fiberIndex == ioList.Head)
            {
                ioList.Head = nextIndex;
            }
            else
            {
                // Previous entry should point back to our next entry
                m_Entries[prevIndex].YieldNext = nextIndex;
            }

            m_Entries[fiberIndex].YieldNext = -1;
            m_Entries[fiberIndex].YieldPrev = -1;

            --ioList.Count;
        }
Пример #3
0
        // Adds the Fiber to the end of the given list
        private void AddLast(Fiber inFiber, ref YieldList ioList)
        {
            int fiberIndex = (int)inFiber.Index;

            // If there are no free fibers currently,
            // we can just add this as the first and only entry.
            if (ioList.Head == -1)
            {
                ioList.Head = fiberIndex;
                m_Entries[fiberIndex].YieldNext = -1;
                m_Entries[fiberIndex].YieldPrev = fiberIndex;
            }
            else
            {
                Entry firstEntry = m_Entries[ioList.Head];

                // Point the old last entry to this one
                m_Entries[firstEntry.YieldPrev].YieldNext = fiberIndex;

                // Point the new last entry at the previous one
                m_Entries[fiberIndex].YieldPrev = firstEntry.YieldPrev;

                // Point the new last entry at nothing
                m_Entries[fiberIndex].YieldNext = -1;

                // Point the first entry at this one
                m_Entries[ioList.Head].YieldPrev = fiberIndex;
            }

            ++ioList.Count;
        }
Пример #4
0
        // Adds the Fiber to the start of the given list
        private void AddFirst(Fiber inFiber, ref YieldList ioList)
        {
            int fiberIndex = (int)inFiber.Index;

            // If there are no free fibers currently,
            // we can just add this as the first and only entry.
            if (ioList.Head == -1)
            {
                ioList.Head = fiberIndex;
                m_Entries[fiberIndex].YieldNext = -1;
                m_Entries[fiberIndex].YieldPrev = fiberIndex;
            }
            else
            {
                Entry firstEntry = m_Entries[ioList.Head];

                // Point back at the current last entry
                m_Entries[fiberIndex].YieldPrev = firstEntry.YieldPrev;

                // Point at the old first free entry
                m_Entries[fiberIndex].YieldNext = ioList.Head;

                // Point the old first entry at the new first entry
                m_Entries[ioList.Head].YieldPrev = fiberIndex;

                ioList.Head = fiberIndex;
            }

            ++ioList.Count;
        }
Пример #5
0
            public void Start(YieldPhase inYield, ref YieldList inList)
            {
                Phase = (RoutinePhase)(-1);
                Yield = inYield;

                Next    = inList.Head;
                Counter = inList.Count;
            }
Пример #6
0
        public void TestYieldList()
        {
            YieldList <int> yieldList = new YieldList <int>();

            yieldList.Add(1);
            yieldList.Add(2);
            yieldList.Add(3);
            yieldList.Add(4);
            foreach (var item in yieldList)
            {
                Console.WriteLine(item);
            }
            foreach (var item in yieldList)
            {
                Console.WriteLine(item);
            }
        }
Пример #7
0
        private void RunYieldUpdate(YieldPhase inUpdate, ref YieldList ioList)
        {
            if (ioList.Dirty)
            {
                SortYieldList(ref ioList);
                ioList.Dirty = false;
            }

            m_MainUpdate.Start(inUpdate, ref ioList);

            ioList.Updating = true;
            {
                while (m_MainUpdate.Next != -1 && m_MainUpdate.Counter-- > 0)
                {
                    Entry e = m_Entries[m_MainUpdate.Next];
                    m_MainUpdate.Next = e.YieldNext;
                    e.Fiber.Update(inUpdate);
                }
            }
            ioList.Updating = false;

            m_MainUpdate.Clear();
        }
Пример #8
0
 private void SortYieldList(ref YieldList ioList)
 {
     MergeSort_YieldList(ref ioList.Head);
 }