public Process(ThreadSafeQueue <IPausableTask> newTaskRoutines, FasterList <IPausableTask> coroutines, FlushingOperation flushingOperation, RunningTasksInfo info, FlushTasksDel flushTaskDel, RunnerBehaviour runnerBehaviourForUnityCoroutine = null, Action <IPausableTask> resumeOperation = null) { _newTaskRoutines = newTaskRoutines; _coroutines = coroutines; _flushingOperation = flushingOperation; _info = info; _flushTaskDel = flushTaskDel; _runnerBehaviourForUnityCoroutine = runnerBehaviourForUnityCoroutine; _resumeOperation = resumeOperation; _platformProfiler = new Svelto.Common.PlatformProfiler(_info.runnerName); }
public CoroutineMonoRunner(string name, bool mustSurvive = false) { _platformProfiler = new Svelto.Common.PlatformProfiler(name); UnityCoroutineRunner.InitializeGameObject(name, ref _go, mustSurvive); RunnerBehaviour runnerBehaviour = _go.AddComponent <RunnerBehaviour>(); _runnerBehaviourForUnityCoroutine = _go.AddComponent <RunnerBehaviour>(); _info = new UnityCoroutineRunner.StandardRunningTaskInfo { runnerName = name }; runnerBehaviour.StartCoroutine(new UnityCoroutineRunner.Process( _newTaskRoutines, _coroutines, _flushingOperation, _info, UnityCoroutineRunner.StandardTasksFlushing, _runnerBehaviourForUnityCoroutine, StartCoroutine)); }
public bool MoveNext() { if (_flushingOperation.kill) { return(false); } #if ENABLE_PLATFORM_PROFILER var _platformProfiler = new Svelto.Common.PlatformProfiler(); using (_platformProfiler.StartNewSession(_info.runnerName)) #endif { //don't start anything while flushing if (_newTaskRoutines.Count > 0 && false == _flushingOperation.stopped) { _newTaskRoutines.DequeueAllInto(_coroutines); } if (_coroutines.Count == 0 || _flushingOperation.paused == true) { return(true); } _info.Reset(); int index = _flushingOperation.immediate == true ? _coroutines.Count - 1 : 0; bool mustExit; do { if (_info.CanProcessThis(ref index) == false) { break; } var coroutines = _coroutines.ToArrayFast(); bool result; if (_flushingOperation.stopped) { coroutines[index].Stop(); } #if ENABLE_PLATFORM_PROFILER using (_platformProfiler.Sample(coroutines[index].ToString())) #endif { #if TASKS_PROFILER_ENABLED result = Profiler.TaskProfiler.MonitorUpdateDuration(coroutines[index], _info.runnerName); #else result = coroutines[index].MoveNext(); #endif } var current = coroutines[index].Current; if (result == false) { _coroutines.UnorderedRemoveAt(index); } else { index++; } var coroutinesCount = _coroutines.Count; mustExit = (coroutinesCount == 0 || _info.CanMoveNext(ref index, current) == false || index >= coroutinesCount); }while (!mustExit); } if (_flushingOperation.stopped == true && _coroutines.Count == 0) { //once all the coroutines are flushed the loop can return accepting new tasks _flushingOperation.stopped = false; } return(true); }
public bool MoveNext() { #if ENABLE_PLATFORM_PROFILER using (var _platformProfiler = new Svelto.Common.PlatformProfiler(_info.runnerName)) #endif { if (_newTaskRoutines.Count > 0 && false == _flushingOperation.stopped) //don't start anything while flushing { _newTaskRoutines.DequeueAllInto(_coroutines); } if (_coroutines.Count == 0) { return(true); } _info.Reset(); int index = _flushingOperation.immediate == true ? _coroutines.Count - 1 : 0; while (true) { if (_info.CanProcessThis(ref index) == false) { break; } var pausableTask = _coroutines[index]; bool result; #if ENABLE_PLATFORM_PROFILER using (_platformProfiler.Sample(_coroutines[index].ToString())) #endif { #if TASKS_PROFILER_ENABLED result = Svelto.Tasks.Profiler.TaskProfiler.MonitorUpdateDuration(pausableTask, _info.runnerName); #else result = pausableTask.MoveNext(); #endif } if (result == false) { _coroutines.UnorderedRemoveAt(index); } else { index++; } if (_coroutines.Count == 0 || _info.CanMoveNext(ref index, pausableTask.Current) == false || index >= _coroutines.Count) { break; } } } if (_flushingOperation.stopped == true && _coroutines.Count == 0) { //once all the coroutines are flushed the loop can return accepting new tasks _flushingOperation.stopped = false; } return(true); }