//physicScheduler -> updateScheduler -> coroutineScheduler -> lateScheduler internal static void KillSchedulers() { if (_multiThreadScheduler != null) { _multiThreadScheduler.Dispose(); } _multiThreadScheduler = null; #if UNITY_5 || UNITY_5_3_OR_NEWER if (_coroutineScheduler != null) { _coroutineScheduler.StopAllCoroutines(); } if (_physicScheduler != null) { _physicScheduler.StopAllCoroutines(); } if (_lateScheduler != null) { _lateScheduler.StopAllCoroutines(); } if (_updateScheduler != null) { _updateScheduler.StopAllCoroutines(); } _coroutineScheduler = null; _physicScheduler = null; _lateScheduler = null; _updateScheduler = null; #endif }
public IEnumerator TestSimpleTaskRoutineStopStartUnity() { yield return(null); using (var runner = new UpdateMonoRunner("TestSimpleTaskRoutineStartStart")) { var taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(runner); taskRoutine. SetEnumeratorProvider(() => LongTermEnumeratorUnity()); int test = 0; var continuator = taskRoutine.Start(onStop: () => OnStop(ref test)); yield return(null); taskRoutine.Stop(); while ((continuator as IEnumerator).MoveNext()) { yield return(null); } var continuator2 = taskRoutine.Start(); Assert.That(test, Is.EqualTo(1)); while ((continuator2 as IEnumerator).MoveNext()) { yield return(null); } Assert.Pass(); } }
public IEnumerator TestContinuatorSimple() { yield return(null); //careful, runners can be garbage collected if they are not referenced somewhere and the //framework does not keep a reference using (var updateMonoRunner = new UpdateMonoRunner("update")) { var cont = new Enumerator(1).RunOnScheduler(updateMonoRunner); Assert.That((cont as IEnumerator).MoveNext(), Is.True); updateMonoRunner.Step(); Assert.That((cont as IEnumerator).MoveNext(), Is.True); updateMonoRunner.Step(); Assert.That((cont as IEnumerator).MoveNext(), Is.False); } }
public IEnumerator TestUnityWaitInParallel() { var updateMonoRunner = new UpdateMonoRunner("test1"); ITaskRoutine <IEnumerator> taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(updateMonoRunner); ParallelTaskCollection pt = new ParallelTaskCollection(); pt.Add(new WaitForSecondsUnity().GetEnumerator()); pt.Add(new WaitForSecondsUnity().GetEnumerator()); taskRoutine.SetEnumerator(pt); taskRoutine.Start(); DateTime then = DateTime.Now; while (taskRoutine.isRunning == true) { yield return(null); } updateMonoRunner.Dispose(); var totalSeconds = (DateTime.Now - then).TotalSeconds; Assert.That(totalSeconds, Is.InRange(0.9, 1.1)); }
// Use this for initialization void OnEnable() { _unityThreadRunner = new UpdateMonoRunner <LocalFunctionEnumerator <int> >("SpawnObjectsMT"); #if UNITY_EDITOR EditorApplication.pauseStateChanged += LogPauseState; #endif Application.targetFrameRate = -1; QualitySettings.vSyncCount = 0; for (int i = 0; i < 150; i++) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); Destroy(sphere.GetComponent <SphereCollider>()); sphere.transform.parent = this.transform; // //queue and run tasks on the standard multi thread runner // UpdateIt(sphere.transform).RunOn(StandardSchedulers.updateScheduler); CalculateAndShowNumber(sphere.GetComponent <Renderer>()).RunOn(StandardSchedulers.multiThreadScheduler); } }
public IEnumerator TestSimpleTaskRoutineStartStartUnity() { yield return(null); using (var runner = new UpdateMonoRunner("TestSimpleTaskRoutineStartStart")) { var taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(runner); taskRoutine. SetEnumeratorProvider(() => LongTermEnumeratorUnity()); taskRoutine.Start(); taskRoutine.Start(); taskRoutine.Start(); taskRoutine.Start(); var continuator = taskRoutine.Start(); while ((continuator as IEnumerator).MoveNext()) { yield return(null); } Assert.Pass(); } }
void OnEnable() { _fastRunner = new UpdateMonoRunner <UpdateItStruct>("SpawnObject"); }
public IEnumerator TestParallelWithMixedYield() { yield return(null); using (var runner = new UpdateMonoRunner("test2")) { var enumerator = new Enumerator(1); _parallelTasks1.Add(enumerator); var enumerator1 = new Enumerator(2); _parallelTasks1.Add(enumerator1); var enumerator2 = new Enumerator(3); _parallelTasks1.Add(enumerator2); var enumerator3 = new Enumerator(4); _parallelTasks1.Add(enumerator3); var enumerator4 = new Enumerator(5); _parallelTasks1.Add(enumerator4); var enumerator5 = new Enumerator(6); _parallelTasks1.Add(enumerator5); _parallelTasks1.RunOnScheduler(runner); Assert.IsFalse(enumerator.AllRight); Assert.IsFalse(enumerator1.AllRight); Assert.IsFalse(enumerator2.AllRight); Assert.IsFalse(enumerator3.AllRight); Assert.IsFalse(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsFalse(enumerator1.AllRight); Assert.IsFalse(enumerator2.AllRight); Assert.IsFalse(enumerator3.AllRight); Assert.IsFalse(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsTrue(enumerator1.AllRight); Assert.IsFalse(enumerator2.AllRight); Assert.IsFalse(enumerator3.AllRight); Assert.IsFalse(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsTrue(enumerator1.AllRight); Assert.IsTrue(enumerator2.AllRight); Assert.IsFalse(enumerator3.AllRight); Assert.IsFalse(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsTrue(enumerator1.AllRight); Assert.IsTrue(enumerator2.AllRight); Assert.IsTrue(enumerator3.AllRight); Assert.IsFalse(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsTrue(enumerator1.AllRight); Assert.IsTrue(enumerator2.AllRight); Assert.IsTrue(enumerator3.AllRight); Assert.IsTrue(enumerator4.AllRight); Assert.IsFalse(enumerator5.AllRight); runner.Step(); Assert.IsTrue(enumerator.AllRight); Assert.IsTrue(enumerator1.AllRight); Assert.IsTrue(enumerator2.AllRight); Assert.IsTrue(enumerator3.AllRight); Assert.IsTrue(enumerator4.AllRight); Assert.IsTrue(enumerator5.AllRight); } }