From 0f2565ba094f212b73d755b5696cb19cefcfd4d9 Mon Sep 17 00:00:00 2001 From: yutopp Date: Fri, 28 Dec 2018 22:28:51 +0900 Subject: [PATCH] Move DepthFirstScheduler to Assets/* --- .../DepthFirstScheduler.meta | 0 .../DepthFirstScheduler}/Editor.meta | 0 .../Editor/DepthFirstScheduler.cs | 48 +- .../Editor/DepthFirstScheduler.cs.meta | 0 .../DepthFirstScheduler}/Functor.cs | 384 +++++++------- .../DepthFirstScheduler}/Functor.cs.meta | 0 .../IEnumeratorExtensions.cs | 62 +-- .../IEnumeratorExtensions.cs.meta | 0 .../DepthFirstScheduler}/LICENSE | 0 .../DepthFirstScheduler}/LICENSE.meta | 0 .../DepthFirstScheduler}/LockQueue.cs | 190 +++---- .../DepthFirstScheduler}/LockQueue.cs.meta | 0 .../MainThreadDispatcher.cs | 300 +++++------ .../MainThreadDispatcher.cs.meta | 0 .../DepthFirstScheduler}/MonitorQueue.cs | 94 ++-- .../DepthFirstScheduler}/MonitorQueue.cs.meta | 0 .../DepthFirstScheduler}/README.md | 0 .../DepthFirstScheduler}/README.md.meta | 0 .../DepthFirstScheduler}/Schedulable.cs | 482 +++++++++--------- .../DepthFirstScheduler}/Schedulable.cs.meta | 0 .../DepthFirstScheduler}/Scheduler.cs | 18 +- .../DepthFirstScheduler}/Scheduler.cs.meta | 0 .../DepthFirstScheduler}/Scheduler.meta | 0 .../Scheduler/CurrentThreadScheduler.cs | 0 .../Scheduler/CurrentThreadScheduler.cs.meta | 0 .../Scheduler/StepScheduler.cs | 0 .../Scheduler/StepScheduler.cs.meta | 0 .../Scheduler/ThreadPoolScheduler.cs | 0 .../Scheduler/ThreadPoolScheduler.cs.meta | 0 .../Scheduler/ThreadScheduler.cs | 0 .../Scheduler/ThreadScheduler.cs.meta | 0 .../DepthFirstScheduler}/TaskChain.cs | 182 +++---- .../DepthFirstScheduler}/TaskChain.cs.meta | 0 .../DepthFirstScheduler}/Unit.cs | 82 +-- .../DepthFirstScheduler}/Unit.cs.meta | 0 35 files changed, 921 insertions(+), 921 deletions(-) rename DepthFirstScheduler.meta => Assets/DepthFirstScheduler.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Editor.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Editor/DepthFirstScheduler.cs (96%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Editor/DepthFirstScheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Functor.cs (95%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Functor.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/IEnumeratorExtensions.cs (96%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/IEnumeratorExtensions.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/LICENSE (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/LICENSE.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/LockQueue.cs (95%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/LockQueue.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/MainThreadDispatcher.cs (96%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/MainThreadDispatcher.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/MonitorQueue.cs (95%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/MonitorQueue.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/README.md (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/README.md.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Schedulable.cs (96%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Schedulable.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler.cs (94%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/CurrentThreadScheduler.cs (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/CurrentThreadScheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/StepScheduler.cs (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/StepScheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/ThreadPoolScheduler.cs (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/ThreadPoolScheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/ThreadScheduler.cs (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Scheduler/ThreadScheduler.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/TaskChain.cs (96%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/TaskChain.cs.meta (100%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Unit.cs (95%) rename {DepthFirstScheduler => Assets/DepthFirstScheduler}/Unit.cs.meta (100%) diff --git a/DepthFirstScheduler.meta b/Assets/DepthFirstScheduler.meta similarity index 100% rename from DepthFirstScheduler.meta rename to Assets/DepthFirstScheduler.meta diff --git a/DepthFirstScheduler/Editor.meta b/Assets/DepthFirstScheduler/Editor.meta similarity index 100% rename from DepthFirstScheduler/Editor.meta rename to Assets/DepthFirstScheduler/Editor.meta diff --git a/DepthFirstScheduler/Editor/DepthFirstScheduler.cs b/Assets/DepthFirstScheduler/Editor/DepthFirstScheduler.cs similarity index 96% rename from DepthFirstScheduler/Editor/DepthFirstScheduler.cs rename to Assets/DepthFirstScheduler/Editor/DepthFirstScheduler.cs index fe09df4dd..10141080b 100644 --- a/DepthFirstScheduler/Editor/DepthFirstScheduler.cs +++ b/Assets/DepthFirstScheduler/Editor/DepthFirstScheduler.cs @@ -1,24 +1,24 @@ -using NUnit.Framework; -using System.Linq; - - -namespace DepthFirstScheduler -{ - public class DepthFirstScheduler - { - [Test] - public void ScheduleTreeTest() - { - var s = Schedulable.Create(); - - var tasks = s.GetRoot().Traverse().ToArray(); - Assert.AreEqual(2, tasks.Length); - - var task_int = s.AddTask(Scheduler.CurrentThread, () => 0); - task_int = task_int.ContinueWith(Scheduler.CurrentThread, _ => 1); - - var status = s.Execute(); - Assert.AreEqual(ExecutionStatus.Done, status); - } - } -} +using NUnit.Framework; +using System.Linq; + + +namespace DepthFirstScheduler +{ + public class DepthFirstScheduler + { + [Test] + public void ScheduleTreeTest() + { + var s = Schedulable.Create(); + + var tasks = s.GetRoot().Traverse().ToArray(); + Assert.AreEqual(2, tasks.Length); + + var task_int = s.AddTask(Scheduler.CurrentThread, () => 0); + task_int = task_int.ContinueWith(Scheduler.CurrentThread, _ => 1); + + var status = s.Execute(); + Assert.AreEqual(ExecutionStatus.Done, status); + } + } +} diff --git a/DepthFirstScheduler/Editor/DepthFirstScheduler.cs.meta b/Assets/DepthFirstScheduler/Editor/DepthFirstScheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Editor/DepthFirstScheduler.cs.meta rename to Assets/DepthFirstScheduler/Editor/DepthFirstScheduler.cs.meta diff --git a/DepthFirstScheduler/Functor.cs b/Assets/DepthFirstScheduler/Functor.cs similarity index 95% rename from DepthFirstScheduler/Functor.cs rename to Assets/DepthFirstScheduler/Functor.cs index 3ddf9fd97..3f7f6a595 100644 --- a/DepthFirstScheduler/Functor.cs +++ b/Assets/DepthFirstScheduler/Functor.cs @@ -1,192 +1,192 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace DepthFirstScheduler -{ - public enum ExecutionStatus - { - Unknown, - Done, - Continue, // coroutine or schedulable - Error, - } - - public interface IFunctor - { - T GetResult(); - Exception GetError(); - ExecutionStatus Execute(); - } - - #region Functor - public class Functor : IFunctor - { - T m_result; - public T GetResult() - { - return m_result; - } - - Exception m_error; - public Exception GetError() - { - return m_error; - } - - Action m_pred; - public Functor(Func func) - { - m_pred = () => m_result = func(); - } - - public ExecutionStatus Execute() - { - try - { - m_pred(); - return ExecutionStatus.Done; - } - catch (Exception ex) - { - m_error = ex; - return ExecutionStatus.Error; - } - } - } - - public static class Functor - { - /// - /// 引数の型を隠蔽した実行器を生成する - /// - /// 引数の型 - /// 結果の型 - /// - /// - /// - public static Functor Create(Func arg, Func pred) - { - return new Functor(() => pred(arg())); - } - } - #endregion - - #region CoroutineFunctor - public class CoroutineFunctor : IFunctor - { - T m_result; - public T GetResult() - { - return m_result; - } - - Exception m_error; - public Exception GetError() - { - return m_error; - } - - Func m_arg; - Func m_starter; - Stack m_it; - public CoroutineFunctor(Func arg, Func starter) - { - m_arg = arg; - m_starter = starter; - } - - public ExecutionStatus Execute() - { - if (m_it == null) - { - m_result = m_arg(); - m_it = new Stack(); - m_it.Push(m_starter(m_result)); - } - - try - { - if (m_it.Count!=0) - { - if (m_it.Peek().MoveNext()) - { - var nested = m_it.Peek().Current as IEnumerator; - if (nested!=null) - { - m_it.Push(nested); - } - } - else - { - m_it.Pop(); - } - return ExecutionStatus.Continue; - } - else - { - return ExecutionStatus.Done; - } - - } - catch(Exception ex) - { - m_error = ex; - return ExecutionStatus.Error; - } - } - } - - public static class CoroutineFunctor - { - public static CoroutineFunctor Create(Func arg, Func starter) - { - return new CoroutineFunctor(arg, starter); - } - } - #endregion - - /* - public class SchedulableFunctor : IFunctor - { - Schedulable m_schedulable; - Func> m_starter; - TaskChain m_chain; - - public SchedulableFunctor(Func> starter) - { - m_starter = starter; - } - - public ExecutionStatus Execute() - { - if (m_chain == null) - { - m_schedulable = m_starter(); - m_chain = TaskChain.Schedule(m_schedulable, ex => m_error = ex); - } - - return m_chain.Next(); - } - - Exception m_error; - public Exception GetError() - { - return m_error; - } - - public T GetResult() - { - return m_schedulable.Func.GetResult(); - } - } - - public static class SchedulableFunctor - { - public static SchedulableFunctor Create(Func> starter) - { - return new SchedulableFunctor(starter); - } - } - */ -} +using System; +using System.Collections; +using System.Collections.Generic; + +namespace DepthFirstScheduler +{ + public enum ExecutionStatus + { + Unknown, + Done, + Continue, // coroutine or schedulable + Error, + } + + public interface IFunctor + { + T GetResult(); + Exception GetError(); + ExecutionStatus Execute(); + } + + #region Functor + public class Functor : IFunctor + { + T m_result; + public T GetResult() + { + return m_result; + } + + Exception m_error; + public Exception GetError() + { + return m_error; + } + + Action m_pred; + public Functor(Func func) + { + m_pred = () => m_result = func(); + } + + public ExecutionStatus Execute() + { + try + { + m_pred(); + return ExecutionStatus.Done; + } + catch (Exception ex) + { + m_error = ex; + return ExecutionStatus.Error; + } + } + } + + public static class Functor + { + /// + /// 引数の型を隠蔽した実行器を生成する + /// + /// 引数の型 + /// 結果の型 + /// + /// + /// + public static Functor Create(Func arg, Func pred) + { + return new Functor(() => pred(arg())); + } + } + #endregion + + #region CoroutineFunctor + public class CoroutineFunctor : IFunctor + { + T m_result; + public T GetResult() + { + return m_result; + } + + Exception m_error; + public Exception GetError() + { + return m_error; + } + + Func m_arg; + Func m_starter; + Stack m_it; + public CoroutineFunctor(Func arg, Func starter) + { + m_arg = arg; + m_starter = starter; + } + + public ExecutionStatus Execute() + { + if (m_it == null) + { + m_result = m_arg(); + m_it = new Stack(); + m_it.Push(m_starter(m_result)); + } + + try + { + if (m_it.Count!=0) + { + if (m_it.Peek().MoveNext()) + { + var nested = m_it.Peek().Current as IEnumerator; + if (nested!=null) + { + m_it.Push(nested); + } + } + else + { + m_it.Pop(); + } + return ExecutionStatus.Continue; + } + else + { + return ExecutionStatus.Done; + } + + } + catch(Exception ex) + { + m_error = ex; + return ExecutionStatus.Error; + } + } + } + + public static class CoroutineFunctor + { + public static CoroutineFunctor Create(Func arg, Func starter) + { + return new CoroutineFunctor(arg, starter); + } + } + #endregion + + /* + public class SchedulableFunctor : IFunctor + { + Schedulable m_schedulable; + Func> m_starter; + TaskChain m_chain; + + public SchedulableFunctor(Func> starter) + { + m_starter = starter; + } + + public ExecutionStatus Execute() + { + if (m_chain == null) + { + m_schedulable = m_starter(); + m_chain = TaskChain.Schedule(m_schedulable, ex => m_error = ex); + } + + return m_chain.Next(); + } + + Exception m_error; + public Exception GetError() + { + return m_error; + } + + public T GetResult() + { + return m_schedulable.Func.GetResult(); + } + } + + public static class SchedulableFunctor + { + public static SchedulableFunctor Create(Func> starter) + { + return new SchedulableFunctor(starter); + } + } + */ +} diff --git a/DepthFirstScheduler/Functor.cs.meta b/Assets/DepthFirstScheduler/Functor.cs.meta similarity index 100% rename from DepthFirstScheduler/Functor.cs.meta rename to Assets/DepthFirstScheduler/Functor.cs.meta diff --git a/DepthFirstScheduler/IEnumeratorExtensions.cs b/Assets/DepthFirstScheduler/IEnumeratorExtensions.cs similarity index 96% rename from DepthFirstScheduler/IEnumeratorExtensions.cs rename to Assets/DepthFirstScheduler/IEnumeratorExtensions.cs index 2d11c0ebc..c7b4b3cff 100644 --- a/DepthFirstScheduler/IEnumeratorExtensions.cs +++ b/Assets/DepthFirstScheduler/IEnumeratorExtensions.cs @@ -1,31 +1,31 @@ -using System.Collections; -using System.Collections.Generic; - - -namespace - DepthFirstScheduler -{ - public static class IEnumeratorExtensions - { - public static void CoroutinetoEnd(this IEnumerator coroutine) - { - var stack = new Stack(); - stack.Push(coroutine); - while (stack.Count > 0) - { - if (stack.Peek().MoveNext()) - { - var nested = stack.Peek().Current as IEnumerator; - if (nested != null) - { - stack.Push(nested); - } - } - else - { - stack.Pop(); - } - } - } - } -} +using System.Collections; +using System.Collections.Generic; + + +namespace + DepthFirstScheduler +{ + public static class IEnumeratorExtensions + { + public static void CoroutinetoEnd(this IEnumerator coroutine) + { + var stack = new Stack(); + stack.Push(coroutine); + while (stack.Count > 0) + { + if (stack.Peek().MoveNext()) + { + var nested = stack.Peek().Current as IEnumerator; + if (nested != null) + { + stack.Push(nested); + } + } + else + { + stack.Pop(); + } + } + } + } +} diff --git a/DepthFirstScheduler/IEnumeratorExtensions.cs.meta b/Assets/DepthFirstScheduler/IEnumeratorExtensions.cs.meta similarity index 100% rename from DepthFirstScheduler/IEnumeratorExtensions.cs.meta rename to Assets/DepthFirstScheduler/IEnumeratorExtensions.cs.meta diff --git a/DepthFirstScheduler/LICENSE b/Assets/DepthFirstScheduler/LICENSE similarity index 100% rename from DepthFirstScheduler/LICENSE rename to Assets/DepthFirstScheduler/LICENSE diff --git a/DepthFirstScheduler/LICENSE.meta b/Assets/DepthFirstScheduler/LICENSE.meta similarity index 100% rename from DepthFirstScheduler/LICENSE.meta rename to Assets/DepthFirstScheduler/LICENSE.meta diff --git a/DepthFirstScheduler/LockQueue.cs b/Assets/DepthFirstScheduler/LockQueue.cs similarity index 95% rename from DepthFirstScheduler/LockQueue.cs rename to Assets/DepthFirstScheduler/LockQueue.cs index 22f88ddd1..205edb0b1 100644 --- a/DepthFirstScheduler/LockQueue.cs +++ b/Assets/DepthFirstScheduler/LockQueue.cs @@ -1,95 +1,95 @@ -using System.Collections; -using System.Collections.Generic; - - -namespace DepthFirstScheduler -{ - public class LockQueue where T : class - { - List m_queue = new List(); - public int Count - { - get - { - lock (((ICollection)m_queue).SyncRoot) - { - return m_queue.Count; - } - } - } - - public void Enqueue(T t) - { - lock (((ICollection)m_queue).SyncRoot) - { - m_queue.Add(t); - } - } - - public T Dequeue(out int remain) - { - lock (((ICollection)m_queue).SyncRoot) - { - if (m_queue.Count == 0) - { - remain = 0; - return null; - } - var item = m_queue[0]; - m_queue.RemoveAt(0); - remain = m_queue.Count; - return item; - } - } - - public T Dequeue() - { - lock (((ICollection)m_queue).SyncRoot) - { - if (m_queue.Count == 0) return null; - var item = m_queue[0]; - m_queue.RemoveAt(0); - return item; - } - } - } - - public class LockQueueForValue where T : struct - { - List m_queue = new List(); - public int Count - { - get - { - lock (((ICollection)m_queue).SyncRoot) - { - return m_queue.Count; - } - } - } - - public void Enqueue(T t) - { - lock (((ICollection)m_queue).SyncRoot) - { - m_queue.Add(t); - } - } - - public bool TryDequeue(out T t) - { - lock (((ICollection)m_queue).SyncRoot) - { - if (m_queue.Count == 0) - { - t = default(T); - return false; - } - - t = m_queue[0]; - m_queue.RemoveAt(0); - return true; - } - } - } -} +using System.Collections; +using System.Collections.Generic; + + +namespace DepthFirstScheduler +{ + public class LockQueue where T : class + { + List m_queue = new List(); + public int Count + { + get + { + lock (((ICollection)m_queue).SyncRoot) + { + return m_queue.Count; + } + } + } + + public void Enqueue(T t) + { + lock (((ICollection)m_queue).SyncRoot) + { + m_queue.Add(t); + } + } + + public T Dequeue(out int remain) + { + lock (((ICollection)m_queue).SyncRoot) + { + if (m_queue.Count == 0) + { + remain = 0; + return null; + } + var item = m_queue[0]; + m_queue.RemoveAt(0); + remain = m_queue.Count; + return item; + } + } + + public T Dequeue() + { + lock (((ICollection)m_queue).SyncRoot) + { + if (m_queue.Count == 0) return null; + var item = m_queue[0]; + m_queue.RemoveAt(0); + return item; + } + } + } + + public class LockQueueForValue where T : struct + { + List m_queue = new List(); + public int Count + { + get + { + lock (((ICollection)m_queue).SyncRoot) + { + return m_queue.Count; + } + } + } + + public void Enqueue(T t) + { + lock (((ICollection)m_queue).SyncRoot) + { + m_queue.Add(t); + } + } + + public bool TryDequeue(out T t) + { + lock (((ICollection)m_queue).SyncRoot) + { + if (m_queue.Count == 0) + { + t = default(T); + return false; + } + + t = m_queue[0]; + m_queue.RemoveAt(0); + return true; + } + } + } +} diff --git a/DepthFirstScheduler/LockQueue.cs.meta b/Assets/DepthFirstScheduler/LockQueue.cs.meta similarity index 100% rename from DepthFirstScheduler/LockQueue.cs.meta rename to Assets/DepthFirstScheduler/LockQueue.cs.meta diff --git a/DepthFirstScheduler/MainThreadDispatcher.cs b/Assets/DepthFirstScheduler/MainThreadDispatcher.cs similarity index 96% rename from DepthFirstScheduler/MainThreadDispatcher.cs rename to Assets/DepthFirstScheduler/MainThreadDispatcher.cs index ee2bdcfc4..82e254efa 100644 --- a/DepthFirstScheduler/MainThreadDispatcher.cs +++ b/Assets/DepthFirstScheduler/MainThreadDispatcher.cs @@ -1,150 +1,150 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace DepthFirstScheduler -{ - /// - /// UniRxのMainThreadDispatcherを参考にした。 - /// * https://github.com/neuecc/UniRx/blob/master/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs - /// - public class MainThreadDispatcher : MonoBehaviour - { - - [Header("Debug")] - public int TaskCount; - - IEnumerable Ancestors(Transform t) - { - yield return t; - - if (t.parent != null) - { - foreach (var x in Ancestors(t.parent)) - { - yield return x; - } - } - } - - private void Update() - { - TaskCount = Scheduler.MainThread.UpdateAndGetTaskCount(); - } - - static MainThreadDispatcher instance; - static bool initialized; - static bool isQuitting = false; - - public static bool IsInitialized - { - get { return initialized && instance != null; } - } - - [ThreadStatic] - static object mainThreadToken; - - public static MainThreadDispatcher Instance - { - get - { - Initialize(); - return instance; - } - } - - public static void Initialize() - { - if (!initialized) - { -#if UNITY_EDITOR - if (!Application.isPlaying) - { - return; - } -#endif - MainThreadDispatcher dispatcher = null; - - try - { - dispatcher = GameObject.FindObjectOfType(); - } - catch - { - // Throw exception when calling from a worker thread. - var ex = new Exception( - "DepthFirstScheduler requires a MainThreadDispatcher component created on the main thread." - + " Make sure it is added to the scene before calling DepthFirstScheduler from a worker thread."); - UnityEngine.Debug.LogException(ex); - throw ex; - } - - if (isQuitting) - { - // don't create new instance after quitting - // avoid "Some objects were not cleaned up when closing the scene find target" error. - return; - } - - if (dispatcher == null) - { - // awake call immediately from UnityEngine - new GameObject("DepthFirstScheduler").AddComponent(); - } - else - { - dispatcher.Awake(); // force awake - } - } - } - - public static bool IsInMainThread - { - get - { - return (mainThreadToken != null); - } - } - - - void Awake() - { - if (instance == null) - { - Debug.Log("Initialize UniTask.MainThredDispatcher"); - - instance = this; - mainThreadToken = new object(); - initialized = true; - - DontDestroyOnLoad(gameObject); - } - else - { - if (this != instance) - { - Debug.LogWarning("There is already a MainThreadDispatcher in the scene."); - } - } - } - - void OnDestroy() - { - if (instance == this) - { - instance = GameObject.FindObjectOfType(); - initialized = instance != null; - } - - if (Scheduler.SingleWorkerThread != null) - { - Scheduler.SingleWorkerThread.Dispose(); - } - } - - void OnApplicationQuit() - { - isQuitting = true; - } - } -} +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace DepthFirstScheduler +{ + /// + /// UniRxのMainThreadDispatcherを参考にした。 + /// * https://github.com/neuecc/UniRx/blob/master/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs + /// + public class MainThreadDispatcher : MonoBehaviour + { + + [Header("Debug")] + public int TaskCount; + + IEnumerable Ancestors(Transform t) + { + yield return t; + + if (t.parent != null) + { + foreach (var x in Ancestors(t.parent)) + { + yield return x; + } + } + } + + private void Update() + { + TaskCount = Scheduler.MainThread.UpdateAndGetTaskCount(); + } + + static MainThreadDispatcher instance; + static bool initialized; + static bool isQuitting = false; + + public static bool IsInitialized + { + get { return initialized && instance != null; } + } + + [ThreadStatic] + static object mainThreadToken; + + public static MainThreadDispatcher Instance + { + get + { + Initialize(); + return instance; + } + } + + public static void Initialize() + { + if (!initialized) + { +#if UNITY_EDITOR + if (!Application.isPlaying) + { + return; + } +#endif + MainThreadDispatcher dispatcher = null; + + try + { + dispatcher = GameObject.FindObjectOfType(); + } + catch + { + // Throw exception when calling from a worker thread. + var ex = new Exception( + "DepthFirstScheduler requires a MainThreadDispatcher component created on the main thread." + + " Make sure it is added to the scene before calling DepthFirstScheduler from a worker thread."); + UnityEngine.Debug.LogException(ex); + throw ex; + } + + if (isQuitting) + { + // don't create new instance after quitting + // avoid "Some objects were not cleaned up when closing the scene find target" error. + return; + } + + if (dispatcher == null) + { + // awake call immediately from UnityEngine + new GameObject("DepthFirstScheduler").AddComponent(); + } + else + { + dispatcher.Awake(); // force awake + } + } + } + + public static bool IsInMainThread + { + get + { + return (mainThreadToken != null); + } + } + + + void Awake() + { + if (instance == null) + { + Debug.Log("Initialize UniTask.MainThredDispatcher"); + + instance = this; + mainThreadToken = new object(); + initialized = true; + + DontDestroyOnLoad(gameObject); + } + else + { + if (this != instance) + { + Debug.LogWarning("There is already a MainThreadDispatcher in the scene."); + } + } + } + + void OnDestroy() + { + if (instance == this) + { + instance = GameObject.FindObjectOfType(); + initialized = instance != null; + } + + if (Scheduler.SingleWorkerThread != null) + { + Scheduler.SingleWorkerThread.Dispose(); + } + } + + void OnApplicationQuit() + { + isQuitting = true; + } + } +} diff --git a/DepthFirstScheduler/MainThreadDispatcher.cs.meta b/Assets/DepthFirstScheduler/MainThreadDispatcher.cs.meta similarity index 100% rename from DepthFirstScheduler/MainThreadDispatcher.cs.meta rename to Assets/DepthFirstScheduler/MainThreadDispatcher.cs.meta diff --git a/DepthFirstScheduler/MonitorQueue.cs b/Assets/DepthFirstScheduler/MonitorQueue.cs similarity index 95% rename from DepthFirstScheduler/MonitorQueue.cs rename to Assets/DepthFirstScheduler/MonitorQueue.cs index ace9ef219..79bf9823a 100644 --- a/DepthFirstScheduler/MonitorQueue.cs +++ b/Assets/DepthFirstScheduler/MonitorQueue.cs @@ -1,47 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Threading; - - -namespace DepthFirstScheduler -{ - /// - /// http://blogs.msdn.com/b/toub/archive/2006/04/12/blocking-queues.aspx - /// - /// 終了を通知するにはnullを投入する手が使える - /// - /// - public class MonitorQueue - { - private Int32 _count = 0; - public Int32 Count - { - get - { - return _count; - } - } - - private Queue _queue = new Queue(); - - public T Dequeue() - { - lock (_queue) - { - while (_count <= 0) Monitor.Wait(_queue); - _count--; - return _queue.Dequeue(); - } - } - - public void Enqueue(T data) - { - lock (_queue) - { - _queue.Enqueue(data); - _count++; - Monitor.Pulse(_queue); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Threading; + + +namespace DepthFirstScheduler +{ + /// + /// http://blogs.msdn.com/b/toub/archive/2006/04/12/blocking-queues.aspx + /// + /// 終了を通知するにはnullを投入する手が使える + /// + /// + public class MonitorQueue + { + private Int32 _count = 0; + public Int32 Count + { + get + { + return _count; + } + } + + private Queue _queue = new Queue(); + + public T Dequeue() + { + lock (_queue) + { + while (_count <= 0) Monitor.Wait(_queue); + _count--; + return _queue.Dequeue(); + } + } + + public void Enqueue(T data) + { + lock (_queue) + { + _queue.Enqueue(data); + _count++; + Monitor.Pulse(_queue); + } + } + } +} diff --git a/DepthFirstScheduler/MonitorQueue.cs.meta b/Assets/DepthFirstScheduler/MonitorQueue.cs.meta similarity index 100% rename from DepthFirstScheduler/MonitorQueue.cs.meta rename to Assets/DepthFirstScheduler/MonitorQueue.cs.meta diff --git a/DepthFirstScheduler/README.md b/Assets/DepthFirstScheduler/README.md similarity index 100% rename from DepthFirstScheduler/README.md rename to Assets/DepthFirstScheduler/README.md diff --git a/DepthFirstScheduler/README.md.meta b/Assets/DepthFirstScheduler/README.md.meta similarity index 100% rename from DepthFirstScheduler/README.md.meta rename to Assets/DepthFirstScheduler/README.md.meta diff --git a/DepthFirstScheduler/Schedulable.cs b/Assets/DepthFirstScheduler/Schedulable.cs similarity index 96% rename from DepthFirstScheduler/Schedulable.cs rename to Assets/DepthFirstScheduler/Schedulable.cs index 96a198d1d..411f62975 100644 --- a/DepthFirstScheduler/Schedulable.cs +++ b/Assets/DepthFirstScheduler/Schedulable.cs @@ -1,241 +1,241 @@ -using System; -using System.Collections; -using System.Collections.Generic; -#if ((NET_4_6 || NET_STANDARD_2_0) && UNITY_2017_1_OR_NEWER) -using System.Threading.Tasks; -#endif - -namespace DepthFirstScheduler -{ - public interface ISchedulable - { - /// 実行が終了したか?Coroutineの実行が一回で終わらない場合がある - ExecutionStatus Execute(); - Exception GetError(); - IScheduler Schedulder { get; } - - ISchedulable Parent { get; set; } - void AddChild(ISchedulable child); - IEnumerable Traverse(); - } - - public static class ISchedulableExtensions - { - public static ISchedulable GetRoot(this ISchedulable self) - { - var current = self; - while (current.Parent != null) - { - current = current.Parent; - } - return current; - } - } - - public class NoParentException: Exception - { - public NoParentException():base("No parent task can't ContinueWith or OnExecute. First AddTask") - { - } - } - - public class Schedulable : ISchedulable - { - List m_children = new List(); - public void AddChild(ISchedulable child) - { - child.Parent = this; - m_children.Add(child); - } - public IEnumerable Traverse() - { - yield return this; - - foreach (var child in m_children) - { - foreach (var x in child.Traverse()) - { - yield return x; - } - } - } - - public ISchedulable Parent - { - get; - set; - } - - public IScheduler Schedulder - { - get; - private set; - } - - public IFunctor Func - { - get; - private set; - } - - public Exception GetError() - { - return Func.GetError(); - } - - public Schedulable() - { - } - - public Schedulable(IScheduler scheduler, IFunctor func) - { - Schedulder = scheduler; - Func = func; - } - - public ExecutionStatus Execute() - { - if (Func == null) - { - return ExecutionStatus.Done; - } - return Func.Execute(); - } - - /// - /// スケジュールされたタスクをすべて即時に実行する - /// - public void ExecuteAll() - { - foreach (var x in this.GetRoot().Traverse()) - { - while (true) - { - var status = x.Execute(); - if (status != ExecutionStatus.Continue) - { - if (status == ExecutionStatus.Error) - { - throw x.GetError(); - } - break; - } - // Coroutineタスクが継続している - } - } - } - - public Schedulable AddTask(IScheduler scheduler, Action pred) - { - return AddTask(scheduler, () => { pred(); return Unit.Default; }); - } - - public Schedulable AddTask(IScheduler scheduler, Func pred) - { - var schedulable = new Schedulable(scheduler, Functor.Create(() => Unit.Default, _ => pred())); - AddChild(schedulable); - return schedulable; - } - - public Schedulable AddCoroutine(IScheduler scheduler, Func starter) - { - var func = CoroutineFunctor.Create(() => default(T), _ => starter()); - var schedulable = new Schedulable(scheduler, func); - AddChild(schedulable); - return schedulable; - } - - public Schedulable ContinueWith(IScheduler scheduler, Action pred) - { - return ContinueWith(scheduler, t => { pred(t); return Unit.Default; }); - } - - public Schedulable ContinueWith(IScheduler scheduler, Func pred) - { - if (Parent == null) - { - throw new NoParentException(); - } - - Func getResult = null; - if (Func != null) - { - getResult = Func.GetResult; - } - var func = Functor.Create(getResult, pred); - var schedulable = new Schedulable(scheduler, func); - Parent.AddChild(schedulable); - return schedulable; - } - - public Schedulable ContinueWithCoroutine(IScheduler scheduler, Func starter) - { - if (Parent == null) - { - throw new NoParentException(); - } - - var func = CoroutineFunctor.Create(() => default(T), _ => starter()); - var schedulable = new Schedulable(scheduler, func); - Parent.AddChild(schedulable); - return schedulable; - } - - public Schedulable OnExecute(IScheduler scheduler, Action> pred) - { - if (Parent == null) - { - throw new NoParentException(); - } - - Func getResult = null; - if (Func != null) - { - getResult = Func.GetResult; - } - - var schedulable = new Schedulable(); - schedulable.Func = Functor.Create(getResult, _ => { pred(schedulable); return Unit.Default; }); - Parent.AddChild(schedulable); - return schedulable; - } - } - - public static class Schedulable - { - public static Schedulable Create() - { - return new Schedulable().AddTask(Scheduler.CurrentThread, () => - { - }); - } - } - - public static class SchedulableExtensions - { - public static void Subscribe( - this Schedulable schedulable, - IScheduler scheduler, - Action onCompleted, - Action onError) - { - schedulable.ContinueWith(scheduler, onCompleted); - TaskChain.Schedule(schedulable.GetRoot(), onError); - } - -#if ((NET_4_6 || NET_STANDARD_2_0) && UNITY_2017_1_OR_NEWER) - public static Task ToTask(this Schedulable schedulable) - { - return ToTask(schedulable, Scheduler.MainThread); - } - - public static Task ToTask(this Schedulable schedulable, IScheduler scheduler) - { - var tcs = new TaskCompletionSource(); - schedulable.Subscribe(scheduler, r => tcs.TrySetResult(r), ex => tcs.TrySetException(ex)); - return tcs.Task; - } -#endif - - } -} +using System; +using System.Collections; +using System.Collections.Generic; +#if ((NET_4_6 || NET_STANDARD_2_0) && UNITY_2017_1_OR_NEWER) +using System.Threading.Tasks; +#endif + +namespace DepthFirstScheduler +{ + public interface ISchedulable + { + /// 実行が終了したか?Coroutineの実行が一回で終わらない場合がある + ExecutionStatus Execute(); + Exception GetError(); + IScheduler Schedulder { get; } + + ISchedulable Parent { get; set; } + void AddChild(ISchedulable child); + IEnumerable Traverse(); + } + + public static class ISchedulableExtensions + { + public static ISchedulable GetRoot(this ISchedulable self) + { + var current = self; + while (current.Parent != null) + { + current = current.Parent; + } + return current; + } + } + + public class NoParentException: Exception + { + public NoParentException():base("No parent task can't ContinueWith or OnExecute. First AddTask") + { + } + } + + public class Schedulable : ISchedulable + { + List m_children = new List(); + public void AddChild(ISchedulable child) + { + child.Parent = this; + m_children.Add(child); + } + public IEnumerable Traverse() + { + yield return this; + + foreach (var child in m_children) + { + foreach (var x in child.Traverse()) + { + yield return x; + } + } + } + + public ISchedulable Parent + { + get; + set; + } + + public IScheduler Schedulder + { + get; + private set; + } + + public IFunctor Func + { + get; + private set; + } + + public Exception GetError() + { + return Func.GetError(); + } + + public Schedulable() + { + } + + public Schedulable(IScheduler scheduler, IFunctor func) + { + Schedulder = scheduler; + Func = func; + } + + public ExecutionStatus Execute() + { + if (Func == null) + { + return ExecutionStatus.Done; + } + return Func.Execute(); + } + + /// + /// スケジュールされたタスクをすべて即時に実行する + /// + public void ExecuteAll() + { + foreach (var x in this.GetRoot().Traverse()) + { + while (true) + { + var status = x.Execute(); + if (status != ExecutionStatus.Continue) + { + if (status == ExecutionStatus.Error) + { + throw x.GetError(); + } + break; + } + // Coroutineタスクが継続している + } + } + } + + public Schedulable AddTask(IScheduler scheduler, Action pred) + { + return AddTask(scheduler, () => { pred(); return Unit.Default; }); + } + + public Schedulable AddTask(IScheduler scheduler, Func pred) + { + var schedulable = new Schedulable(scheduler, Functor.Create(() => Unit.Default, _ => pred())); + AddChild(schedulable); + return schedulable; + } + + public Schedulable AddCoroutine(IScheduler scheduler, Func starter) + { + var func = CoroutineFunctor.Create(() => default(T), _ => starter()); + var schedulable = new Schedulable(scheduler, func); + AddChild(schedulable); + return schedulable; + } + + public Schedulable ContinueWith(IScheduler scheduler, Action pred) + { + return ContinueWith(scheduler, t => { pred(t); return Unit.Default; }); + } + + public Schedulable ContinueWith(IScheduler scheduler, Func pred) + { + if (Parent == null) + { + throw new NoParentException(); + } + + Func getResult = null; + if (Func != null) + { + getResult = Func.GetResult; + } + var func = Functor.Create(getResult, pred); + var schedulable = new Schedulable(scheduler, func); + Parent.AddChild(schedulable); + return schedulable; + } + + public Schedulable ContinueWithCoroutine(IScheduler scheduler, Func starter) + { + if (Parent == null) + { + throw new NoParentException(); + } + + var func = CoroutineFunctor.Create(() => default(T), _ => starter()); + var schedulable = new Schedulable(scheduler, func); + Parent.AddChild(schedulable); + return schedulable; + } + + public Schedulable OnExecute(IScheduler scheduler, Action> pred) + { + if (Parent == null) + { + throw new NoParentException(); + } + + Func getResult = null; + if (Func != null) + { + getResult = Func.GetResult; + } + + var schedulable = new Schedulable(); + schedulable.Func = Functor.Create(getResult, _ => { pred(schedulable); return Unit.Default; }); + Parent.AddChild(schedulable); + return schedulable; + } + } + + public static class Schedulable + { + public static Schedulable Create() + { + return new Schedulable().AddTask(Scheduler.CurrentThread, () => + { + }); + } + } + + public static class SchedulableExtensions + { + public static void Subscribe( + this Schedulable schedulable, + IScheduler scheduler, + Action onCompleted, + Action onError) + { + schedulable.ContinueWith(scheduler, onCompleted); + TaskChain.Schedule(schedulable.GetRoot(), onError); + } + +#if ((NET_4_6 || NET_STANDARD_2_0) && UNITY_2017_1_OR_NEWER) + public static Task ToTask(this Schedulable schedulable) + { + return ToTask(schedulable, Scheduler.MainThread); + } + + public static Task ToTask(this Schedulable schedulable, IScheduler scheduler) + { + var tcs = new TaskCompletionSource(); + schedulable.Subscribe(scheduler, r => tcs.TrySetResult(r), ex => tcs.TrySetException(ex)); + return tcs.Task; + } +#endif + + } +} diff --git a/DepthFirstScheduler/Schedulable.cs.meta b/Assets/DepthFirstScheduler/Schedulable.cs.meta similarity index 100% rename from DepthFirstScheduler/Schedulable.cs.meta rename to Assets/DepthFirstScheduler/Schedulable.cs.meta diff --git a/DepthFirstScheduler/Scheduler.cs b/Assets/DepthFirstScheduler/Scheduler.cs similarity index 94% rename from DepthFirstScheduler/Scheduler.cs rename to Assets/DepthFirstScheduler/Scheduler.cs index 20ae4d4a1..41d898fe8 100644 --- a/DepthFirstScheduler/Scheduler.cs +++ b/Assets/DepthFirstScheduler/Scheduler.cs @@ -1,9 +1,9 @@ -using System; - -namespace DepthFirstScheduler -{ - public interface IScheduler : IDisposable - { - void Enqueue(TaskChain item); - } -} +using System; + +namespace DepthFirstScheduler +{ + public interface IScheduler : IDisposable + { + void Enqueue(TaskChain item); + } +} diff --git a/DepthFirstScheduler/Scheduler.cs.meta b/Assets/DepthFirstScheduler/Scheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Scheduler.cs.meta rename to Assets/DepthFirstScheduler/Scheduler.cs.meta diff --git a/DepthFirstScheduler/Scheduler.meta b/Assets/DepthFirstScheduler/Scheduler.meta similarity index 100% rename from DepthFirstScheduler/Scheduler.meta rename to Assets/DepthFirstScheduler/Scheduler.meta diff --git a/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs b/Assets/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs similarity index 100% rename from DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs rename to Assets/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs diff --git a/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs.meta b/Assets/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs.meta rename to Assets/DepthFirstScheduler/Scheduler/CurrentThreadScheduler.cs.meta diff --git a/DepthFirstScheduler/Scheduler/StepScheduler.cs b/Assets/DepthFirstScheduler/Scheduler/StepScheduler.cs similarity index 100% rename from DepthFirstScheduler/Scheduler/StepScheduler.cs rename to Assets/DepthFirstScheduler/Scheduler/StepScheduler.cs diff --git a/DepthFirstScheduler/Scheduler/StepScheduler.cs.meta b/Assets/DepthFirstScheduler/Scheduler/StepScheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Scheduler/StepScheduler.cs.meta rename to Assets/DepthFirstScheduler/Scheduler/StepScheduler.cs.meta diff --git a/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs b/Assets/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs similarity index 100% rename from DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs rename to Assets/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs diff --git a/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs.meta b/Assets/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs.meta rename to Assets/DepthFirstScheduler/Scheduler/ThreadPoolScheduler.cs.meta diff --git a/DepthFirstScheduler/Scheduler/ThreadScheduler.cs b/Assets/DepthFirstScheduler/Scheduler/ThreadScheduler.cs similarity index 100% rename from DepthFirstScheduler/Scheduler/ThreadScheduler.cs rename to Assets/DepthFirstScheduler/Scheduler/ThreadScheduler.cs diff --git a/DepthFirstScheduler/Scheduler/ThreadScheduler.cs.meta b/Assets/DepthFirstScheduler/Scheduler/ThreadScheduler.cs.meta similarity index 100% rename from DepthFirstScheduler/Scheduler/ThreadScheduler.cs.meta rename to Assets/DepthFirstScheduler/Scheduler/ThreadScheduler.cs.meta diff --git a/DepthFirstScheduler/TaskChain.cs b/Assets/DepthFirstScheduler/TaskChain.cs similarity index 96% rename from DepthFirstScheduler/TaskChain.cs rename to Assets/DepthFirstScheduler/TaskChain.cs index 7928e5bd6..f5a05ebb5 100644 --- a/DepthFirstScheduler/TaskChain.cs +++ b/Assets/DepthFirstScheduler/TaskChain.cs @@ -1,91 +1,91 @@ -using System; -using System.Linq; -using System.Collections.Generic; - - -namespace DepthFirstScheduler -{ - public enum ChainStatus - { - Unknown, - Continue, - Done, - Error, - } - - public class TaskChain - { - public IEnumerator Enumerator; - public Action OnError; - public ChainStatus ChainStatus; - - public static TaskChain Schedule(ISchedulable schedulable, Action onError) - { - var item = new TaskChain - { - Enumerator = schedulable.Traverse().GetEnumerator(), - OnError = onError - }; - - if (item.Enumerator.MoveNext()) - { - if (item.Enumerator.Current.Schedulder == null) - { - // default - Scheduler.MainThread.Enqueue(item); - } - else - { - item.Enumerator.Current.Schedulder.Enqueue(item); - } - } - - return item; - } - - /// - /// - /// - /// - public ExecutionStatus Next() - { - if (this.ChainStatus == ChainStatus.Done - || this.ChainStatus== ChainStatus.Error) - { - return ExecutionStatus.Done; - } - - { - var status = Enumerator.Current.Execute(); - if (status == ExecutionStatus.Error) - { - ChainStatus = ChainStatus.Error; - OnError(Enumerator.Current.GetError()); - } - if (status == ExecutionStatus.Continue) - { - // 中断(coroutine) - ChainStatus = ChainStatus.Continue; - return ExecutionStatus.Continue; - } - } - - if (!Enumerator.MoveNext()) - { - // 終了 - ChainStatus = ChainStatus.Done; - return ExecutionStatus.Done; - } - - if (Enumerator.Current.Schedulder != null) - { - // Scheduleして中断 - ChainStatus = ChainStatus.Continue; - Enumerator.Current.Schedulder.Enqueue(this); - return ExecutionStatus.Done; - } - - return Next(); - } - } -} +using System; +using System.Linq; +using System.Collections.Generic; + + +namespace DepthFirstScheduler +{ + public enum ChainStatus + { + Unknown, + Continue, + Done, + Error, + } + + public class TaskChain + { + public IEnumerator Enumerator; + public Action OnError; + public ChainStatus ChainStatus; + + public static TaskChain Schedule(ISchedulable schedulable, Action onError) + { + var item = new TaskChain + { + Enumerator = schedulable.Traverse().GetEnumerator(), + OnError = onError + }; + + if (item.Enumerator.MoveNext()) + { + if (item.Enumerator.Current.Schedulder == null) + { + // default + Scheduler.MainThread.Enqueue(item); + } + else + { + item.Enumerator.Current.Schedulder.Enqueue(item); + } + } + + return item; + } + + /// + /// + /// + /// + public ExecutionStatus Next() + { + if (this.ChainStatus == ChainStatus.Done + || this.ChainStatus== ChainStatus.Error) + { + return ExecutionStatus.Done; + } + + { + var status = Enumerator.Current.Execute(); + if (status == ExecutionStatus.Error) + { + ChainStatus = ChainStatus.Error; + OnError(Enumerator.Current.GetError()); + } + if (status == ExecutionStatus.Continue) + { + // 中断(coroutine) + ChainStatus = ChainStatus.Continue; + return ExecutionStatus.Continue; + } + } + + if (!Enumerator.MoveNext()) + { + // 終了 + ChainStatus = ChainStatus.Done; + return ExecutionStatus.Done; + } + + if (Enumerator.Current.Schedulder != null) + { + // Scheduleして中断 + ChainStatus = ChainStatus.Continue; + Enumerator.Current.Schedulder.Enqueue(this); + return ExecutionStatus.Done; + } + + return Next(); + } + } +} diff --git a/DepthFirstScheduler/TaskChain.cs.meta b/Assets/DepthFirstScheduler/TaskChain.cs.meta similarity index 100% rename from DepthFirstScheduler/TaskChain.cs.meta rename to Assets/DepthFirstScheduler/TaskChain.cs.meta diff --git a/DepthFirstScheduler/Unit.cs b/Assets/DepthFirstScheduler/Unit.cs similarity index 95% rename from DepthFirstScheduler/Unit.cs rename to Assets/DepthFirstScheduler/Unit.cs index c3a041d1e..fed9eb64c 100644 --- a/DepthFirstScheduler/Unit.cs +++ b/Assets/DepthFirstScheduler/Unit.cs @@ -1,41 +1,41 @@ -using System; - -namespace DepthFirstScheduler -{ - [Serializable] - public struct Unit : IEquatable - { - static readonly Unit @default = new Unit(); - - public static Unit Default { get { return @default; } } - - public static bool operator ==(Unit first, Unit second) - { - return true; - } - - public static bool operator !=(Unit first, Unit second) - { - return false; - } - - public bool Equals(Unit other) - { - return true; - } - public override bool Equals(object obj) - { - return obj is Unit; - } - - public override int GetHashCode() - { - return 0; - } - - public override string ToString() - { - return "()"; - } - } -} +using System; + +namespace DepthFirstScheduler +{ + [Serializable] + public struct Unit : IEquatable + { + static readonly Unit @default = new Unit(); + + public static Unit Default { get { return @default; } } + + public static bool operator ==(Unit first, Unit second) + { + return true; + } + + public static bool operator !=(Unit first, Unit second) + { + return false; + } + + public bool Equals(Unit other) + { + return true; + } + public override bool Equals(object obj) + { + return obj is Unit; + } + + public override int GetHashCode() + { + return 0; + } + + public override string ToString() + { + return "()"; + } + } +} diff --git a/DepthFirstScheduler/Unit.cs.meta b/Assets/DepthFirstScheduler/Unit.cs.meta similarity index 100% rename from DepthFirstScheduler/Unit.cs.meta rename to Assets/DepthFirstScheduler/Unit.cs.meta