示例#1
0
        public void CreateAndCacheCondition(int fourierSize, float windSpeed, float windDir, float waveAge)
        {
            if (this.m_conditionCache == null)
            {
                return;
            }
            if (this.m_conditionCache.Count >= this.m_maxConditionCacheSize)
            {
                Ocean.LogWarning("Condition cache full. Condition not cached.");
                return;
            }
            if (!Mathf.IsPowerOfTwo(fourierSize) || fourierSize < 32 || fourierSize > 512)
            {
                Ocean.LogWarning("Fourier size must be a pow2 number from 32 to 512. Condition not cached.");
                return;
            }
            WaveSpectrumCondition waveSpectrumCondition = this.NewSpectrumCondition(fourierSize, windSpeed, windDir, waveAge);

            if (this.m_conditionCache.ContainsKey(waveSpectrumCondition.Key))
            {
                return;
            }
            IThreadedTask createSpectrumConditionTask = waveSpectrumCondition.GetCreateSpectrumConditionTask();

            createSpectrumConditionTask.Start();
            createSpectrumConditionTask.Run();
            createSpectrumConditionTask.End();
            this.m_conditionCache.AddFirst(waveSpectrumCondition.Key, waveSpectrumCondition);
        }
示例#2
0
        /// <summary>
        /// Finish all tasks in the finished list
        /// by calling there end function and removing
        /// the from the running list.
        /// </summary>
        public void FinishTasks()
        {
            if (TasksFinishedThisUpdate >= MaxFinishPerUpdate)
            {
                return;
            }

            lock (m_lock)
            {
                m_haveRan.Clear();

                //Get a list of all tasks that have ran.
                var e1 = m_runningTasks.GetEnumerator();
                while (e1.MoveNext())
                {
                    IThreadedTask task = e1.Current;

                    if (task.Ran)
                    {
                        m_haveRan.AddLast(task);
                    }
                }

                //Remove from running list and add to finished list.
                var e2 = m_haveRan.GetEnumerator();
                while (e2.MoveNext())
                {
                    Finished(e2.Current);
                }

                if (m_finishedTasks.Count == 0)
                {
                    return;
                }

                //Get task at start of queue
                IThreadedTask finished = m_finishedTasks.First.Value;
                m_finishedTasks.RemoveFirst();

                while (finished != null)
                {
                    //Clean up task.
                    finished.End();
                    TasksFinishedThisUpdate++;

                    if (m_finishedTasks.Count == 0 || TasksFinishedThisUpdate >= MaxFinishPerUpdate)
                    {
                        finished = null;
                    }
                    else
                    {
                        finished = m_finishedTasks.First.Value;
                        m_finishedTasks.RemoveFirst();
                    }
                }

                m_haveRan.Clear();
            }
        }
示例#3
0
        public void FinishTasks()
        {
            if (this.TasksFinishedThisUpdate >= this.MaxFinishPerUpdate)
            {
                return;
            }
            object @lock = this.m_lock;

            lock (@lock)
            {
                this.m_haveRan.Clear();
                LinkedList <IThreadedTask> .Enumerator enumerator = this.m_runningTasks.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    IThreadedTask current = enumerator.Current;
                    if (current.Ran)
                    {
                        this.m_haveRan.AddLast(current);
                    }
                }
                LinkedList <IThreadedTask> .Enumerator enumerator2 = this.m_haveRan.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    this.Finished(enumerator2.Current);
                }
                if (this.m_finishedTasks.Count != 0)
                {
                    IThreadedTask threadedTask = this.m_finishedTasks.First.Value;
                    this.m_finishedTasks.RemoveFirst();
                    while (threadedTask != null)
                    {
                        threadedTask.End();
                        this.TasksFinishedThisUpdate++;
                        if (this.m_finishedTasks.Count == 0 || this.TasksFinishedThisUpdate >= this.MaxFinishPerUpdate)
                        {
                            threadedTask = null;
                        }
                        else
                        {
                            threadedTask = this.m_finishedTasks.First.Value;
                            this.m_finishedTasks.RemoveFirst();
                        }
                    }
                    this.m_haveRan.Clear();
                }
            }
        }
示例#4
0
        public void FinishTasks()
        {
            if (this.TasksFinishedThisUpdate >= this.MaxFinishPerUpdate)
            {
                return;
            }
            object @lock = this.m_lock;

            lock (@lock)
            {
                this.m_haveRan.Clear();
                foreach (IThreadedTask threadedTask in this.m_runningTasks)
                {
                    if (threadedTask.Ran)
                    {
                        this.m_haveRan.AddLast(threadedTask);
                    }
                }
                foreach (IThreadedTask task in this.m_haveRan)
                {
                    this.Finished(task);
                }
                if (this.m_finishedTasks.Count != 0)
                {
                    IThreadedTask threadedTask2 = this.m_finishedTasks.First.Value;
                    this.m_finishedTasks.RemoveFirst();
                    while (threadedTask2 != null)
                    {
                        threadedTask2.End();
                        this.TasksFinishedThisUpdate++;
                        if (this.m_finishedTasks.Count == 0 || this.TasksFinishedThisUpdate >= this.MaxFinishPerUpdate)
                        {
                            threadedTask2 = null;
                        }
                        else
                        {
                            threadedTask2 = this.m_finishedTasks.First.Value;
                            this.m_finishedTasks.RemoveFirst();
                        }
                    }
                    this.m_haveRan.Clear();
                }
            }
        }
示例#5
0
        private void CreateConditions()
        {
            int size = this.m_bufferSettings.size;
            WaveSpectrumConditionKey waveSpectrumConditionKey = this.NewSpectrumConditionKey(size, this.windSpeed, this.m_ocean.windDir, this.waveAge);

            if (this.m_conditions[0] == null)
            {
                if (this.m_conditionCache.ContainsKey(waveSpectrumConditionKey))
                {
                    this.m_conditions[0] = this.m_conditionCache[waveSpectrumConditionKey];
                    this.m_conditionCache.Remove(waveSpectrumConditionKey);
                }
                else
                {
                    this.m_conditions[0] = this.NewSpectrumCondition(size, this.windSpeed, this.m_ocean.windDir, this.waveAge);
                    IThreadedTask createSpectrumConditionTask = this.m_conditions[0].GetCreateSpectrumConditionTask();
                    createSpectrumConditionTask.Start();
                    createSpectrumConditionTask.Run();
                    createSpectrumConditionTask.End();
                }
            }
            else if (this.m_conditions[1] != null && this.m_conditions[1].Done)
            {
                this.CacheCondition(this.m_conditions[0]);
                this.m_conditions[0] = this.m_conditions[1];
                this.m_conditions[1] = null;
            }
            else if (this.m_conditions[1] == null && this.m_conditions[0].Done && waveSpectrumConditionKey != this.m_conditions[0].Key)
            {
                if (this.m_conditionCache.ContainsKey(waveSpectrumConditionKey))
                {
                    this.m_conditions[0] = this.m_conditionCache[waveSpectrumConditionKey];
                    this.m_conditionCache.Remove(waveSpectrumConditionKey);
                }
                else
                {
                    this.m_conditions[1] = this.NewSpectrumCondition(size, this.windSpeed, this.m_ocean.windDir, this.waveAge);
                    IThreadedTask createSpectrumConditionTask2 = this.m_conditions[1].GetCreateSpectrumConditionTask();
                    this.m_scheduler.Add(createSpectrumConditionTask2);
                }
            }
        }
示例#6
0
        private void RunTask(IThreadedTask task)
        {
            object @lock = this.m_lock;

            lock (@lock)
            {
                this.TasksRanThisUpdate++;
                if (!task.IsThreaded || this.DisableMultithreading)
                {
                    task.Start();
                    IEnumerator enumerator = task.Run();
                    if (enumerator != null)
                    {
                        if (this.m_coroutine == null)
                        {
                            throw new InvalidOperationException("Scheduler trying to run a coroutine task when coroutine interface is null");
                        }
                        this.m_coroutine.RunCoroutine(enumerator);
                        if (!this.IsFinishing(task))
                        {
                            this.m_runningTasks.AddLast(task);
                        }
                    }
                    else
                    {
                        task.End();
                    }
                }
                else
                {
                    task.Start();
                    this.m_runningTasks.AddLast(task);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(this.RunThreaded), task);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Runs next task. 
        /// </summary>
        void RunTask(IThreadedTask task)
        {
            lock(m_lock)
            {

            #if CETO_DEBUG_SCHEDULER

                if (Contains(task))
                    throw new ArgumentException("Scheduler already contains task.");

                if (task.Started)
                    throw new ArgumentException("Task has already been started.");

                if (task.Ran)
                    throw new ArgumentException("Task has already been ran.");

                if (task.Done)
                    throw new ArgumentException("Task has already been done.");

                if (task.Cancelled)
                    throw new ArgumentException("Task has been cancelled.");
            #endif

                TasksRanThisUpdate++;

                if (!task.IsThreaded || DisableMultithreading)
                {
                    //Start task.
                    task.Start();
                    //Run task
                    IEnumerator e = task.Run();

                    //If task returned a enumerator
                    //the task is a coroutine.
                    if(e != null)
                    {
                        if(m_coroutine == null)
                            throw new InvalidOperationException("Scheduler trying to run a coroutine task when coroutine interface is null");

                        //Start coroutine and add to running queue if it has
                        //not been added to the finishing queue.
                        //If a task has ran quickly it may have already
                        //been added to the finished queue.
                        m_coroutine.RunCoroutine(e);
                        if(!IsFinishing(task))
                        {
                            m_runningTasks.AddLast(task);
                        }
                    }
                    else
                    {
                        //Clean up task
                        task.End();
                    }
                }
                else
                {
                    //Start task
                    task.Start();
                    //Run task on separate thread
                    //and add to running tasks list.
                    m_runningTasks.AddLast(task);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(RunThreaded), task);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Runs next task.
        /// </summary>
        void RunTask(IThreadedTask task)
        {
            lock (m_lock)
            {
#if CETO_DEBUG_SCHEDULER
                if (Contains(task))
                {
                    throw new ArgumentException("Scheduler already contains task.");
                }

                if (task.Started)
                {
                    throw new ArgumentException("Task has already been started.");
                }

                if (task.Ran)
                {
                    throw new ArgumentException("Task has already been ran.");
                }

                if (task.Done)
                {
                    throw new ArgumentException("Task has already been done.");
                }

                if (task.Cancelled)
                {
                    throw new ArgumentException("Task has been cancelled.");
                }
#endif

                TasksRanThisUpdate++;

                if (!task.IsThreaded || DisableMultithreading)
                {
                    //Start task.
                    task.Start();
                    //Run task
                    IEnumerator e = task.Run();

                    //If task returned a enumerator
                    //the task is a coroutine.
                    if (e != null)
                    {
                        if (m_coroutine == null)
                        {
                            throw new InvalidOperationException("Scheduler trying to run a coroutine task when coroutine interface is null");
                        }

                        //Start coroutine and add to running queue if it has
                        //not been added to the finishing queue.
                        //If a task has ran quickly it may have already
                        //been added to the finished queue.
                        m_coroutine.RunCoroutine(e);
                        if (!IsFinishing(task))
                        {
                            m_runningTasks.AddLast(task);
                        }
                    }
                    else
                    {
                        //Clean up task
                        task.End();
                    }
                }
                else
                {
                    //Start task
                    task.Start();
                    //Run task on separate thread
                    //and add to running tasks list.
                    m_runningTasks.AddLast(task);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(RunThreaded), task);
                }
            }
        }