Exemple #1
0
        /// <summary>
        /// Sets up a Fiber to run with the given host and routine.
        /// </summary>
        public Routine Initialize(MonoBehaviour inHost, IEnumerator inStart, bool inChained)
        {
            if (Manager.DebugMode && !(inStart is IDisposable))
            {
                throw new ArgumentException("IEnumerators must also implement IDisposable.");
            }

            m_Counter = (byte)(m_Counter == byte.MaxValue ? 1 : m_Counter + 1);

            m_Handle = (Routine)Table.GenerateID(Index, m_Counter);
            m_Host   = inHost;

            m_HostIdentity = RoutineIdentity.Find(m_Host.gameObject);

            m_WaitTime = 0;

            m_UnityWait = null;
            m_Name      = null;
            Priority    = 0;

            m_GroupMask = ReferenceEquals(m_HostIdentity, null) ? 0 : 1 << m_HostIdentity.Group;

            // Chained routines are always hosted on the manager
            if (inChained)
            {
                m_Chained = m_HostedByManager = true;
            }

            if (!inChained && ReferenceEquals(inHost, Manager))
            {
                m_HostedByManager = true;
            }

            if (!ReferenceEquals(m_HostIdentity, null))
            {
                m_HasIdentity = true;
            }

            m_TimeScale = 1.0f;

            m_RootFunction = inStart;
            m_Stack[m_StackPosition = 0] = inStart;

            IRoutineEnumerator callback = inStart as IRoutineEnumerator;

            if (callback != null)
            {
                if (!callback.OnRoutineStart())
                {
                    ClearStack();
                    Stop();
                }
            }

            return(m_Handle);
        }
Exemple #2
0
        /// <summary>
        /// Cleans up the Fiber.
        /// </summary>
        public void Dispose()
        {
            if ((uint)m_Handle == 0)
            {
                return;
            }

            if (m_UnityWait != null)
            {
                Manager.Host.StopCoroutine(m_UnityWait);
                m_UnityWait = null;
            }

            bool bKilled  = m_StackPosition >= 0;
            bool bChained = m_Chained;

            ClearStack();

            m_Handle       = Routine.Null;
            m_Host         = null;
            m_HostIdentity = null;

            m_Chained = m_Disposing = m_HasIdentity = m_Paused = m_IgnoreObjectTimescale = m_HostedByManager = false;

            m_WaitTime  = 0;
            m_GroupMask = 0;
            m_Name      = null;
            Priority    = 0;

            m_TimeScale = 1.0f;

            Manager.RecycleFiber(this, bChained);

            if (bKilled)
            {
                m_OnComplete = null;
                Action onStop = m_OnStop;
                m_OnStop = null;
                if (onStop != null)
                {
                    onStop();
                }
            }
            else
            {
                m_OnStop = null;
                Action onComplete = m_OnComplete;
                m_OnComplete = null;
                if (onComplete != null)
                {
                    onComplete();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets up a Fiber to run with the given host and routine.
        /// </summary>
        public Routine Initialize(MonoBehaviour inHost, IEnumerator inStart, bool inChained)
        {
            #if DEVELOPMENT
            if (Manager.DebugMode && !(inStart is IDisposable))
            {
                throw new ArgumentException("IEnumerators must also implement IDisposable.");
            }
            #endif // DEVELOPMENT

            m_Counter = (byte)(m_Counter == byte.MaxValue ? 1 : m_Counter + 1);

            m_Handle = (Routine)Table.GenerateID(Index, m_Counter);
            m_Host   = inHost;

            m_HostIdentity = RoutineIdentity.Find(m_Host.gameObject);

            m_WaitTime  = 0;
            m_LockCount = 0;

            m_UnityWait = null;
            m_Name      = null;
            Priority    = 0;

            // Chained routines are always hosted on the manager
            if (inChained)
            {
                m_Chained = m_HostedByManager = true;
            }

            if (!inChained && ReferenceEquals(inHost, Manager.Host))
            {
                m_HostedByManager = true;
            }

            if (!ReferenceEquals(m_HostIdentity, null))
            {
                m_HasIdentity = true;
            }

            m_TimeScale = 1.0f;

            m_RootFunction = inStart;
            m_Stack[m_StackPosition = 0] = inStart;

            CheckForNesting(inStart);

            if (!m_Chained)
            {
                m_UpdatePhase = Manager.DefaultPhase;
                Manager.Fibers.AddFiberToUpdateList(this, m_UpdatePhase);
            }

            return(m_Handle);
        }
        private IEnumerator Start()
        {
            yield return(null);

#if REQUIRE_MAX_SAMPLE_ADJUST
            Profiler.maxNumberOfSamplesPerFrame = 8000000;
#endif

            Application.targetFrameRate = -1;

            Routine.Initialize();
            Routine.Settings.DebugMode       = false;
            Routine.Settings.SnapshotEnabled = false;
            RoutineIdentity.Require(this);

            yield return(null);

            yield return(null);

            for (int i = 0; i < ROUTINE_COUNTS.Length; ++i)
            {
                float timeAccumulation = 0;
                for (int j = 0; j < SAMPLE_COUNT; ++j)
                {
                    Routine.Settings.SetCapacity(ROUTINE_COUNTS[i]);
                    yield return(null);

                    timeAccumulation += MeasureStartupTime(ROUTINE_COUNTS[i]);
                    yield return(new WaitForSeconds(5f));

                    Routine.StopAll();
                    yield return(null);
                }
                float avgTime = timeAccumulation / SAMPLE_COUNT;
                print("[" + ROUTINE_COUNTS[i].ToString() + ", startup]: " + avgTime.ToString() + "ms");
            }

#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
Exemple #5
0
        /// <summary>
        /// Cleans up the Fiber.
        /// </summary>
        public void Dispose()
        {
            if ((uint)m_Handle == 0)
            {
                return;
            }

            if (m_UnityWait != null)
            {
                Manager.Host.StopCoroutine(m_UnityWait);
                m_UnityWait = null;
            }

            bool bKilled  = m_StackPosition >= 0;
            bool bChained = m_Chained;

            ClearStack();

            m_Handle       = Routine.Null;
            m_Host         = null;
            m_HostIdentity = null;

            // If this is chained and we have a parallel
            if (bChained && m_Container != null)
            {
                m_Container.RemoveFiber(this);
            }

            m_Chained = m_Disposing = m_HasIdentity = m_Paused = m_IgnoreObjectTimescale = m_HostedByManager = m_IgnoreObjectActive = m_Executing = false;

            m_WaitTime  = 0;
            m_LockCount = 0;
            m_Name      = null;
            Priority    = 0;

            m_Container = null;
            m_RootFiber = null;

            m_TimeScale       = 1.0f;
            m_YieldFrameDelay = 0;

            if (m_YieldPhase != YieldPhase.None)
            {
                Manager.Fibers.RemoveFiberFromYieldList(this, m_YieldPhase);
                m_YieldPhase = YieldPhase.None;
            }

            if (!bChained)
            {
                Manager.Fibers.RemoveFiberFromUpdateList(this, m_UpdatePhase);
            }
            Manager.RecycleFiber(this, bChained);

            m_UpdatePhase      = Manager.DefaultPhase;
            m_OnException      = null;
            m_HandleExceptions = false;

            if (bKilled)
            {
                m_OnComplete = null;
                Action onStop = m_OnStop;
                m_OnStop = null;
                if (onStop != null)
                {
                    onStop();
                }
            }
            else
            {
                m_OnStop = null;
                Action onComplete = m_OnComplete;
                m_OnComplete = null;
                if (onComplete != null)
                {
                    onComplete();
                }
            }
        }