/// <summary>
        /// Add a new callback function to the worker thread.
        /// The 'main' delegate will run on a secondary thread, while the 'finished' delegate will run in Update().
        /// </summary>

        static public void CreateConditional(BoolFunc main, VoidFunc finished = null)
        {
            if (mInstance == null)
            {
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    if (main() && finished != null)
                    {
                        finished();
                    }
                    return;
                }
#endif
                GameObject go = new GameObject("Worker Thread");
                mInstance = go.AddComponent <WorkerThread>();
            }

            Entry ent;

            if (mInstance.mUnused.Count != 0)
            {
                lock (mInstance.mUnused) { ent = (mInstance.mUnused.size != 0) ? mInstance.mUnused.Pop() : new Entry(); }
            }
            else
            {
                ent = new Entry();
            }

            ent.conditional = main;
            ent.finished    = finished;
            lock (mInstance.mNew) mInstance.mNew.Enqueue(ent);
        }
Example #2
0
        public static CBResult <bool> boolPositive(BoolFunc f, bool arg2)
        {
            bool b = f();

            return(new CBResult <bool>()
            {
                breakloop = b,
                ans = b
            });
        }
Example #3
0
    IEnumerator DelayBoolFunction(int frames, BoolFunc func, bool arg)
    {
        int numSkipped = 0;

        while (numSkipped++ < frames)
        {
            yield return(null);
        }

        func(arg);
    }
Example #4
0
        /// <summary>
        /// Add a new callback function to the worker thread.
        /// The 'main' delegate will run on a secondary thread, while the 'finished' delegate will run in Update().
        /// Return 'false' if you want the same delegates to execute again next time, or 'true' if you're done.
        /// </summary>

        static public void CreateMultiStage(BoolFunc main, BoolFunc finished = null, bool highPriority = false)
        {
#if SINGLE_THREADED
            if (main != null)
            {
                while (!main())
                {
                }
            }
            if (finished != null)
            {
                while (!finished())
                {
                }
            }
#else
            if (mInstance == null)
            {
#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    if (main != null)
                    {
                        while (!main())
                        {
                        }
                    }
                    if (finished != null)
                    {
                        while (!finished())
                        {
                        }
                    }
                    return;
                }
#endif
                GameObject go = new GameObject("Worker Thread");
                mInstance = go.AddComponent <WorkerThread>();
            }

            Entry ent;

            if (mInstance.mUnused.size != 0)
            {
                lock (mInstance.mUnused) { ent = (mInstance.mUnused.size != 0) ? mInstance.mUnused.Pop() : new Entry(); }
            }
            else
            {
                ent = new Entry();
            }

            ent.mainBool     = main;
            ent.finishedBool = finished;
            ent.milliseconds = 0;

            if (highPriority)
            {
                lock (mInstance.mPriority) mInstance.mPriority.Enqueue(ent);
            }
            else
            {
                lock (mInstance.mRegular) mInstance.mRegular.Enqueue(ent);
            }
#endif
        }