private void RemoveCoroutine(CoroutineNode coroutine)
 {
     if (this.first == coroutine)
     {
         // remove first
         this.first = coroutine.listNext;
     }
     else
     {
         // not head of list
         if (coroutine.listNext != null)
         {
             // remove between
             coroutine.listPrevious.listNext = coroutine.listNext;
             coroutine.listNext.listPrevious = coroutine.listPrevious;
         }
         else if (coroutine.listPrevious != null)
         {
             // and listNext is null
             coroutine.listPrevious.listNext = null;
             // remove last
         }
     }
     coroutine.listPrevious = null;
     coroutine.listNext     = null;
 }
示例#2
0
        private void RemoveCoroutine(CoroutineNode coroutine)
        {
            bool flag = this.first == coroutine;

            if (flag)
            {
                this.first = coroutine.listNext;
            }
            else
            {
                bool flag2 = coroutine.listNext != null;
                if (flag2)
                {
                    coroutine.listPrevious.listNext = coroutine.listNext;
                    coroutine.listNext.listPrevious = coroutine.listPrevious;
                }
                else
                {
                    bool flag3 = coroutine.listPrevious != null;
                    if (flag3)
                    {
                        coroutine.listPrevious.listNext = null;
                    }
                }
            }
            coroutine.listPrevious = null;
            coroutine.listNext     = null;
        }
        /**
         * Runs all active coroutines until their next yield. Caller must provide
         * the current frame and time. This allows for schedulers to run under
         * frame and time regimes other than the Unity's main game loop.
         */
        public void UpdateAllCoroutines(int frame, FP time)
        {
            currentTime = time;
            CoroutineNode coroutine = this.first;

            while (coroutine != null)
            {
                // store listNext before coroutine finishes and is removed from the list
                CoroutineNode listNext = coroutine.listNext;

                if (coroutine.waitForFrame > 0 && frame >= coroutine.waitForFrame)
                {
                    coroutine.waitForFrame = -1;
                    UpdateCoroutine(coroutine);
                }
                else if (coroutine.waitForTime > 0.0f && time >= coroutine.waitForTime)
                {
                    coroutine.waitForTime = -1.0f;
                    UpdateCoroutine(coroutine);
                }
                else if (coroutine.waitForCoroutine != null && coroutine.waitForCoroutine.finished)
                {
                    coroutine.waitForCoroutine = null;
                    UpdateCoroutine(coroutine);
                }
                else if (coroutine.waitForFrame == -1 && coroutine.waitForTime == -1.0f && coroutine.waitForCoroutine == null)
                {
                    // initial update
                    UpdateCoroutine(coroutine);
                }
                coroutine = listNext;
            }
        }
 private void AddCoroutine(CoroutineNode coroutine)
 {
     if (this.first != null)
     {
         coroutine.listNext = this.first;
         first.listPrevious = coroutine;
     }
     first = coroutine;
 }
示例#5
0
        private void UpdateCoroutine(CoroutineNode coroutine)
        {
            IEnumerator fiber = coroutine.fiber;
            bool        flag  = coroutine.playerId > -1;

            if (flag)
            {
                TrueSyncInput.CurrentSimulationData = this.lockStep.GetInputData(coroutine.playerId);
            }
            bool flag2 = coroutine.fiber.MoveNext();

            if (flag2)
            {
                object obj   = (fiber.Current == null) ? 1 : fiber.Current;
                bool   flag3 = obj.GetType() == typeof(int);
                if (flag3)
                {
                    coroutine.waitForTime  = (int)obj;
                    coroutine.waitForTime += this.currentTime;
                }
                else
                {
                    bool flag4 = obj.GetType() == typeof(float);
                    if (flag4)
                    {
                        coroutine.waitForTime  = (float)obj;
                        coroutine.waitForTime += this.currentTime;
                    }
                    else
                    {
                        bool flag5 = obj.GetType() == typeof(FP);
                        if (flag5)
                        {
                            coroutine.waitForTime  = (FP)obj;
                            coroutine.waitForTime += this.currentTime;
                        }
                        else
                        {
                            bool flag6 = obj.GetType() == typeof(CoroutineNode);
                            if (!flag6)
                            {
                                throw new ArgumentException("CoroutineScheduler: Unexpected coroutine yield type: " + obj.GetType());
                            }
                            coroutine.waitForCoroutine = (CoroutineNode)obj;
                        }
                    }
                }
            }
            else
            {
                coroutine.finished = true;
                this.RemoveCoroutine(coroutine);
            }
        }
示例#6
0
        private void AddCoroutine(CoroutineNode coroutine)
        {
            bool flag = this.first != null;

            if (flag)
            {
                coroutine.listNext      = this.first;
                this.first.listPrevious = coroutine;
            }
            this.first = coroutine;
        }
        /**
         * Starts a coroutine, the coroutine does not run immediately but on the
         * next call to UpdateAllCoroutines. The execution of a coroutine can
         * be paused at any point using the yield statement. The yield return value
         * specifies when the coroutine is resumed.
         */

        public CoroutineNode StartCoroutine(IEnumerator fiber)
        {
            // if function does not have a yield, fiber will be null and we no-op
            if (fiber == null)
            {
                return(null);
            }
            // create coroutine node and run until we reach first yield
            CoroutineNode coroutine = new CoroutineNode(fiber);

            AddCoroutine(coroutine);

            return(coroutine);
        }
示例#8
0
        public CoroutineNode StartCoroutine(IEnumerator fiber)
        {
            bool          flag = fiber == null;
            CoroutineNode result;

            if (flag)
            {
                result = null;
            }
            else
            {
                CoroutineNode coroutineNode = new CoroutineNode(fiber);
                this.AddCoroutine(coroutineNode);
                result = coroutineNode;
            }
            return(result);
        }
        /**
         * Executes coroutine until next yield. If coroutine has finished, flags
         * it as finished and removes it from scheduler list.
         */
        private void UpdateCoroutine(CoroutineNode coroutine)
        {
            IEnumerator fiber = coroutine.fiber;

            if (coroutine.playerId > -1)
            {
                TrueSyncInput.CurrentSimulationData = (InputData)lockStep.GetInputData(coroutine.playerId);
            }

            if (coroutine.fiber.MoveNext())
            {
                System.Object yieldCommand = fiber.Current == null ? (System.Object) 1 : fiber.Current;

                if (yieldCommand.GetType() == typeof(int))
                {
                    coroutine.waitForTime  = (FP)((int)yieldCommand);
                    coroutine.waitForTime += (FP)currentTime;
                }
                else if (yieldCommand.GetType() == typeof(float))
                {
                    coroutine.waitForTime  = (FP)((float)yieldCommand);
                    coroutine.waitForTime += (FP)currentTime;
                }
                else if (yieldCommand.GetType() == typeof(FP))
                {
                    coroutine.waitForTime  = (FP)yieldCommand;
                    coroutine.waitForTime += (FP)currentTime;
                }
                else if (yieldCommand.GetType() == typeof(CoroutineNode))
                {
                    coroutine.waitForCoroutine = (CoroutineNode)yieldCommand;
                }
                else
                {
                    throw new System.ArgumentException("CoroutineScheduler: Unexpected coroutine yield type: " + yieldCommand.GetType());
                }
            }
            else
            {
                // coroutine finished
                coroutine.finished = true;
                RemoveCoroutine(coroutine);
            }
        }
示例#10
0
        public void UpdateAllCoroutines(int frame, FP time)
        {
            this.currentTime = time;
            CoroutineNode listNext;

            for (CoroutineNode coroutineNode = this.first; coroutineNode != null; coroutineNode = listNext)
            {
                listNext = coroutineNode.listNext;
                bool flag = coroutineNode.waitForFrame > 0 && frame >= coroutineNode.waitForFrame;
                if (flag)
                {
                    coroutineNode.waitForFrame = -1;
                    this.UpdateCoroutine(coroutineNode);
                }
                else
                {
                    bool flag2 = coroutineNode.waitForTime > 0f && time >= coroutineNode.waitForTime;
                    if (flag2)
                    {
                        coroutineNode.waitForTime = -1f;
                        this.UpdateCoroutine(coroutineNode);
                    }
                    else
                    {
                        bool flag3 = coroutineNode.waitForCoroutine != null && coroutineNode.waitForCoroutine.finished;
                        if (flag3)
                        {
                            coroutineNode.waitForCoroutine = null;
                            this.UpdateCoroutine(coroutineNode);
                        }
                        else
                        {
                            bool flag4 = coroutineNode.waitForFrame == -1 && coroutineNode.waitForTime == -1f && coroutineNode.waitForCoroutine == null;
                            if (flag4)
                            {
                                this.UpdateCoroutine(coroutineNode);
                            }
                        }
                    }
                }
            }
        }
示例#11
0
 public void StopAllCoroutines()
 {
     this.first = null;
 }