/// <summary> /// Stops all coroutines that are running in the specified update loop. /// </summary> public static void StopAll(UpdateLoop updateLoop) { var coroutines = GetList(updateLoop); var isInUpdate = _current != null && _current.Value.UpdateLoop == updateLoop; var current = coroutines.First; while (current != null) { var next = current.Next; var routine = current.Value; Stop(routine); if (!isInUpdate) { IdToCoroutine.Remove(routine.Id); PoolHelper <BetterCoroutine> .Despawn(routine); coroutines.Remove(current); } current = next; } }
private List <long> FindGarbageCollectables() { var visited = new HashSet <long>(); _color = !_color; var toVisit = new Queue <Node>(); toVisit.Enqueue(_nodes[0]); while (toVisit.Count > 0) { var node = toVisit.Dequeue(); if (visited.Contains(node.Id)) { continue; } visited.Add(node.Id); node.Color = _color; foreach (var neighbor in node.References.Values) { toVisit.Enqueue(neighbor); } } var garbageCollectables = _nodes.Values.Where(n => n.Color != _color).Select(n => n.Id).ToList(); foreach (var gc in garbageCollectables) { _nodes.Remove(gc); } return(garbageCollectables); }
private static void Start(BetterCoroutine coroutine) { var scaledTime = GetTime(coroutine.UpdateLoopId, false); var unscaledTime = GetTime(coroutine.UpdateLoopId, true); IdToCoroutine[coroutine.Id] = coroutine; var list = GetList(coroutine.UpdateLoopId); if (list == null) { UpdateLoopToCoroutines[coroutine.UpdateLoopId] = list = new PooledLinkedList <BetterCoroutine>(SharedNodePool); ManagedUpdate.AddListener(coroutine.UpdateLoopId, Instance); } var node = list.AddFirst(coroutine); var prevCurrent = _current; _current = node; var continueRunning = UpdateCoroutine(scaledTime, unscaledTime, coroutine); if (!continueRunning) { IdToCoroutine.Remove(coroutine.Id); list.Remove(coroutine); if (coroutine.Parent != null) { coroutine.Parent.Child = null; } PoolHelper <BetterCoroutine> .Despawn(coroutine); } _current = prevCurrent; }