public void DoWork(WorkData workData = null)
        {
            ProfilerShort.Begin("DoCullWork");

            var frustum = m_query.Frustum;

            if (m_query.SmallObjects.HasValue)
            {
                if (MyRender11.Settings.DrawNonMergeInstanced)
                {
                    m_renderables.OverlapAllFrustum<MyCullProxy>(ref frustum, m_query.List, m_query.IsInsideList,
                        m_query.SmallObjects.Value.ProjectionDir, m_query.SmallObjects.Value.ProjectionFactor, m_query.SmallObjects.Value.SkipThreshold,
                        0, false);
                }

                if (MyRender11.Settings.DrawMergeInstanced)
                {
                    MyScene.GroupsDBVH.OverlapAllFrustum<MyCullProxy_2>(ref frustum, m_query.List2, m_query.IsInsideList2,
                        m_query.SmallObjects.Value.ProjectionDir, m_query.SmallObjects.Value.ProjectionFactor, m_query.SmallObjects.Value.SkipThreshold,
                        0, false);
                }
            }
            else
            {
                if (MyRender11.Settings.DrawNonMergeInstanced)
                    m_renderables.OverlapAllFrustum<MyCullProxy>(ref frustum, m_query.List, m_query.IsInsideList, 0, false);

                if(MyRender11.Settings.DrawMergeInstanced)
                    MyScene.GroupsDBVH.OverlapAllFrustum<MyCullProxy_2>(ref frustum, m_query.List2, m_query.IsInsideList2, 0, false);
            }

            ProfilerShort.End();
        }
            void IWork.DoWork(ParallelTasks.WorkData workData = null)
            {
                m_timer.Start();
                MyPrecalcJob work;

                while (Queue.TryDequeueFront(out work))
                {
                    if (work.IsCanceled)
                    {
                        m_finishedList.Add(work);
                        continue;
                    }
                    try
                    {
                        ProfilerShort.Begin("MyPrecalcWork");
                        work.DoWork();
                    }
                    finally
                    {
                        ProfilerShort.End();
                    }
                    m_finishedList.Add(work);
                    if (m_timer.ElapsedMilliseconds >= MaxPrecalcTime)
                    {
                        break;
                    }
                    if (MyFakes.ENABLE_YIELDING_IN_PRECALC_TASK)
                    {
                        Thread.Yield();
                    }
                }

                m_timer.Stop();
                m_timer.Reset();
            }
        public unsafe void DoWork(WorkData workData = null)
        {
            try
            {
                //MyEntities.EntityCloseLock.AcquireShared();

                if (m_renderObject == null)
                    return;

                if (m_renderObject is MyRenderVoxelCell)
                {
                }
                              
                Vector3 directionToSunNormalized = -MyRender.Sun.Direction;

                VisibleFromSun = false;

                var line2 = new LineD(m_renderObject.WorldVolume.Center, m_renderObject.WorldVolume.Center + directionToSunNormalized * MyShadowRenderer.SHADOW_MAX_OFFSET * 0.5f);
                var result2 = MyRender.GetAnyIntersectionWithLine(MyRender.ShadowPrunning, ref line2, m_renderObject, null, m_overlapList);
                VisibleFromSun |= (result2 == null); //if nothing hit, its visible from sun

                if (m_renderObject.FastCastShadowResolve)
                    return;

                Vector3D* corners = stackalloc Vector3D[8];
                m_renderObject.GetCorners(corners);

                for (int i = 0; i < 8; i++)
                {
                    LineD line = new LineD(corners[i], corners[i] + directionToSunNormalized * MyShadowRenderer.SHADOW_MAX_OFFSET * 0.5f);
                    var result = MyRender.GetAnyIntersectionWithLine(MyRender.ShadowPrunning, ref line, m_renderObject, null, m_overlapList);

                    VisibleFromSun |= (result == null);

                    if (VisibleFromSun)
                        break;
                }

                if (!VisibleFromSun)
                {
                }
            }
            finally
            {      /*
                if (m_renderObject != null)
                {
                    m_renderObject.OnClose -= m_entity_OnMarkForClose;
                }
                 */
               // MyEntities.EntityCloseLock.ReleaseShared();
            }
        }
Beispiel #4
0
        public void DoWork(WorkData workData = null)
        {
            int start;

            while ((start = IncrementIndex()) < length)
            {
                int end = Math.Min(start + stride, length);
                for (int i = start; i < end; i++)
                {
                    action(i);
                }
            }
        }
Beispiel #5
0
 public void DoWork(WorkData workData = null)
 {
     if (Action != null)
     {
         Action();
         Action = null;
     }
     if (DataAction != null)
     {
         DataAction(workData);
         DataAction = null;
     }
     instances.Return(this);
 }
Beispiel #6
0
 public void DoWork(WorkData workData = null)
 {
     if (Action != null)
     {
         Action();
         Action = null;
     }
     if (DataAction != null)
     {
         DataAction(workData);
         DataAction = null;
     }
     instances.Return(this);
 }
Beispiel #7
0
        public void DoWork(WorkData workData = null)
        {
            MyRender11.GetRenderProfiler().StartProfilingBlock("DoActorUpdateWork");

            for (int i = m_start; i < m_end; i++)
            {
                var renderable = m_array[i];
                if (renderable.IsVisible)
                {
                    renderable.OnFrameUpdate();
                }
            }

            MyRender11.GetRenderProfiler().EndProfilingBlock();
        }
        private void RaiseLogicalSectors(WorkData data)
        {
            MyProceduralLogicalSector sector;
            var server = (MyMultiplayerServerBase)MyMultiplayer.Static;

            m_sectorsQueued = false;

            while (m_sectorsToDestroy.TryDequeue(out sector))
            {
                sector.Close();
            }

            while (m_sectorsToRaise.TryDequeue(out sector))
            {
                server.RaiseReplicableCreated(sector);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Creates and schedules a task to execute on the given work-tracking thread.
        /// If the requested thread that does not execute completion callbacks the callback will never be called.
        /// </summary>
        /// <param name="action">The work to execute in parallel.</param>
        /// <param name="workData">Data to be passed along both the work and the completion callback.</param>
        /// <param name="thread">Thread to execute the callback on. If not provided this is the calling thread.</param>
        /// <returns>A task which represents one execution of the action.</returns>
        public static Task ScheduleForThread(Action <WorkData> action, WorkData workData, Thread thread = null)
        {
            if (thread == null)
            {
                thread = Thread.CurrentThread;
            }

            WorkOptions options = new WorkOptions()
            {
                MaximumThreads = 1, DetachFromParent = false, QueueFIFO = false
            };

            var work = DelegateWork.GetInstance();

            work.Options = options;

            var workItem = WorkItem.Get(thread);

            lock (Buffers)
            {
                workItem.CompletionCallbacks = Buffers[thread];
            }
            workItem.DataCallback = action;


            if (workData != null)
            {
                workItem.WorkData = workData;
            }
            else
            {
                workItem.WorkData = new WorkData();
            }

            var task = workItem.PrepareStart(work, thread);

            CallbackBuffer.Add(workItem);
            return(task);
        }
Beispiel #10
0
        public void DoWork(WorkData workData = null)
        {
            T item = default(T);

            while (notDone)
            {
                bool haveValue = false;
                lock (syncLock)
                {
                    if (notDone = enumerator.MoveNext())
                    {
                        item      = enumerator.Current;
                        haveValue = true;
                    }
                }

                if (haveValue)
                {
                    action(item);
                }
            }
        }
 public void CallLoadWorkshopPrefab(WorkData workData)
 {
     m_prefab = LoadWorkshopPrefab(m_path, m_id);
     CallOnPrefabLoaded();
 }
 public void DoWork(WorkData workData = null)
 {
     Action(workData);
 }
Beispiel #13
0
 public void DoWork(WorkData workData = null)
 {
     Result = Function();
 }
Beispiel #14
0
        /// <summary>
        /// Creates and schedules a task to execute the given work with the given work data.
        /// </summary>
        /// <param name="action">The work to execute in parallel.</param>
        /// <param name="completionCallback">A method which will be called in Parallel.RunCallbacks() once this task has completed.</param>
        /// <param name="workData">Data to be passed along both the work and the completion callback.</param>
        /// <returns>A task which represents one execution of the action.</returns>
        public static Task Start(Action <WorkData> action, Action <WorkData> completionCallback, WorkData workData)
        {
            WorkOptions options = new WorkOptions()
            {
                MaximumThreads = 1, DetachFromParent = false, QueueFIFO = false
            };

            var work = DelegateWork.GetInstance();

            work.DataAction = action;
            work.Options    = options;

            var workItem = WorkItem.Get(Thread.CurrentThread);

            workItem.CompletionCallbacks = CallbackBuffer;
            workItem.DataCallback        = completionCallback;

            if (workData != null)
            {
                workItem.WorkData  = workData;
                workData.WorkState = WorkData.WorkStateEnum.NOT_STARTED;
            }
            else
            {
                workItem.WorkData = new WorkData();
            }

            var task = workItem.PrepareStart(work);

            Scheduler.Schedule(task);
            return(task);
        }
Beispiel #15
0
        /// <summary>
        /// Starts a task in a secondary worker thread. Intended for long running, blocking work such as I/O.
        /// </summary>
        /// <param name="action">The work to execute.</param>
        /// <param name="completionCallback">A method which will be called in Parallel.RunCallbacks() once this task has completed.</param>
        /// <param name="workData">Data to be passed along both the work and the completion callback.</param>
        /// <returns>A task which represents one execution of the action.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="action"/> is <see langword="null"/>.
        /// </exception>
        public static Task StartBackground(Action <WorkData> action, Action <WorkData> completionCallback, WorkData workData)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            var work = DelegateWork.GetInstance();

            work.DataAction = action;
            work.Options    = DefaultOptions;

            var workItem = WorkItem.Get(Thread.CurrentThread);

            workItem.DataCallback = completionCallback;
            if (workData != null)
            {
                workItem.WorkData = workData;
            }
            else
            {
                workItem.WorkData = new WorkData();
            }

            var task = workItem.PrepareStart(work);

            BackgroundWorker.StartWork(task);
            return(task);
        }
 public abstract void DoWork(WorkData workData = null);
 public void CallLoadPrefab(WorkData workData)
 {
     m_prefab = LoadPrefab(m_path);
     CallOnPrefabLoaded();
 }
 public void DoWork(WorkData workData = null)
 {
     PrepareCascadesForDraw();
 }
Beispiel #19
0
 public void DoWork(WorkData workData = null)
 {
     _Action(workData);
 }