// Update is called once per frame public void OnUpdate() { while (_ready[_currentReadyIndex].Count > 0) { int nextTaskId = _ready[_currentReadyIndex].Dequeue(); CoroutineTask task = null; if (_taskMap.ContainsKey(nextTaskId)) { task = _taskMap[nextTaskId]; } else { continue; } try{ SystemTask result = task.Run(); if (result != null) { result.task = task; result.Handle(); continue; } } catch (StopIteration e) { Exit(task); continue; } Schedule(task.taskId); } _currentReadyIndex = 1 - _currentReadyIndex; }
// Use this for initialization CoroutineDecorator() { _ready = new Queue <int> [2]; _ready [0] = new Queue <int> (); _ready [1] = new Queue <int> (); _taskMap = new Dictionary <int, CoroutineTask> (); _exitWaiting = new Dictionary <int, List <int> > (); _lockMap = new Dictionary <int, LockInfo> (); nop = new SystemTask(); returnValueRegister = null; }