Beispiel #1
0
 void Apply(MeshManager manager, DeltaDoneDelegate onDone, bool undo)
 {
     if (m_co != null)
     {
         m_co.done = true;
     }
     m_co = Scheduler.StartCoroutine(DoApply(manager, onDone, undo));
 }
Beispiel #2
0
    /// <summary>
    /// The non-static version of StartCoroutine.
    /// </summary>
    RCECoroutine StartCoroutineInstance(IEnumerator method, System.Object source)
    {
        if (method == null)
        {
            return(null);
        }
        RCECoroutine fib = new RCECoroutine(method, source);

        m_newCoroutines.Add(fib);
        return(fib);
    }
Beispiel #3
0
    void UpdateCoroutine(RCECoroutine co, float timeAllowed)
    {
        m_currentCoroutine = co;
        co.allowedTime     = timeAllowed;

        if (!co.Update())
        {
            m_deadCoroutines.Add(co);
        }

        --m_coroutinesRemaining;
        m_timeRemaining -= co.lastElapsedTime;
    }
Beispiel #4
0
    public static void StopCoroutines(System.Object source)
    {
        for (int i = 0; i < instance.m_coroutines.Count; i++)
        {
            RCECoroutine c = instance.m_coroutines[i];
            if (c.originator == source)
            {
                c.done = true;
            }
        }

        for (int i = 0; i < instance.m_newCoroutines.Count; i++)
        {
            RCECoroutine c = instance.m_newCoroutines[i];
            if (c.originator == source)
            {
                c.done = true;
            }
        }
    }
Beispiel #5
0
    void Update()
    {
        //calculate our time slice by creating a weighted average of the estimated time we have left in the frames
        m_timeSlice = m_timeSlice * 0.8f + Mathf.Max(m_actualTargetTime - (Time.realtimeSinceStartup - m_lastUpdateTime), 0f) * 0.2f;

        //every time our time slice is low increase our target time a bit; if we're high enough try to give back time
        if (m_timeSlice < kLowerSliceThreshold)
        {
            m_actualTargetTime *= 1.01f;
        }
        else if (m_timeSlice > kUpperSliceThreshold)
        {
            m_actualTargetTime = Mathf.Max(kTargetTime, m_actualTargetTime * 0.99f);
        }

        for (int i = 0; i < m_newCoroutines.Count; i++)
        {
            m_coroutines.Add(m_newCoroutines[i]);
        }
        m_newCoroutines.Clear();

        m_timeRemaining       = m_timeSlice;
        m_coroutinesRemaining = m_coroutines.Count;

        if (m_timeRemaining > 0f)
        {
            //pass to weed out the paused and underutilizing threads
            for (int i = 0; i < m_coroutines.Count; i++)
            {
                RCECoroutine co = m_coroutines[i];

                if (!co.ShouldUpdate())
                {
                    --m_coroutinesRemaining;
                    co.updatedThisFrame = true;
                }
                else if (co.underTime && co.lastElapsedTime < m_timeRemaining / m_coroutinesRemaining)
                {
                    UpdateCoroutine(co, co.lastElapsedTime);
                    co.updatedThisFrame = true;
                }
                else
                {
                    co.updatedThisFrame = false;
                }
            }

            //do the rest
            //TODO: Right now everyone gets a more-or-less equal share; In the future certain coroutines
            //may have a higher priority and thus need more time
            for (int i = 0; i < m_coroutines.Count; i++)
            {
                RCECoroutine co = m_coroutines[i];

                if (!co.updatedThisFrame && co.ShouldUpdate())
                {
                    if (m_coroutinesRemaining == 0)
                    {
                        throw new System.Exception("Div zero");
                    }
                    UpdateCoroutine(co, m_timeRemaining / m_coroutinesRemaining);
                    co.updatedThisFrame = true;
                }
            }
        }
        else
        {
            //everyone gets zero time, which means they will run one "loop" and stop
            //potential TODO: starve the coroutines entirely if we drop below a minimum threshold
            for (int i = 0; i < m_coroutines.Count; i++)
            {
                RCECoroutine co = m_coroutines[i];

                if (!co.updatedThisFrame && co.ShouldUpdate())
                {
                    UpdateCoroutine(co, 0f);
                    co.updatedThisFrame = true;
                }
            }
        }

        //remove the dead
        for (int i = 0; i < m_deadCoroutines.Count; i++)
        {
            m_coroutines.Remove(m_deadCoroutines[i]);
        }
        m_deadCoroutines.Clear();

        m_currentCoroutine = null;
        m_lastUpdateTime   = Time.realtimeSinceStartup;
    }
Beispiel #6
0
 public WaitCoroutine(RCECoroutine co)
 {
     m_coroutine = co;
 }