internal static void ProcessCoroutines(CoroutineGroup group) { runningGroup = group; insideMainCoroutineLoop = true; for (int i = coroutines.Count - 1; i >= 0; --i) { Coroutine coroutine = coroutines[i]; Debug.Assert(coroutine.mainCollectionIndex == i, "Coroutine main collection index is invalid"); if (coroutine.CurrentGroup == group && !coroutine.Complete) { coroutine.Process(group); } if (coroutine.Complete) { CoroutineRemoveAtSwap(coroutine, true); } } insideMainCoroutineLoop = false; // Do we need some kind of while loop here? If a coroutine has been processed here // and gets added to a different comparable collection it wont be processed until // the next frame even if it would be completed in this frame. Possibly return // a bool in Process if it an item was removed from the collection and keep running // this loop until all Process calls return false? for (int i = comparableCollections.Count - 1; i >= 0; --i) { IComparableYieldInstructionCollection collection = comparableCollections[i]; collection.Process(group); } runningGroup = CoroutineGroup.None; }
internal static void ComparableEnd(Coroutine coroutine) { System.Diagnostics.Debug.Assert(coroutine.mainCollectionIndex == -1, "Coroutine already inside main collection"); coroutine.mainCollectionIndex = coroutines.Count; coroutines.Add(coroutine); if (!insideMainCoroutineLoop) { // Comparables are processed individually. We need to manaully continue processing to ensure // that as much is processed each tick as possible until complete or KeepWaiting state. if (coroutine.CurrentGroup == runningGroup && !coroutine.Complete) { coroutine.Process(runningGroup); } if (coroutine.Complete) { CoroutineRemoveAtSwap(coroutine, true); } } }
internal static void ComparableEnd(Coroutine coroutine) { Debug.Assert(coroutine.mainCollectionIndex == -1, "Coroutine already inside main collection"); coroutine.mainCollectionIndex = coroutines.Count; coroutines.Add(coroutine); if (!insideMainCoroutineLoop) { // Comparables are processed individually. We need to manaully continue processing to ensure // that as much is processed each tick as possible until complete or KeepWaiting state. if (coroutine.CurrentGroup == runningGroup && !coroutine.Complete) { coroutine.Process(runningGroup); } if (coroutine.Complete) { Debug.Assert(coroutine.mainCollectionIndex != -1, "Defer CoroutineRemoveAtSwap so that the main ProcessCoroutines function cleans the coroutine up. " + "This allows coroutines to have .Stop() calls whilst itterating over collections"); //CoroutineRemoveAtSwap(coroutine, true); } } }