Esempio n. 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);
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
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);
                }
            }
        }