예제 #1
0
        public void Invoke(InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(m);

            PushInvoke(cmd);

            while (!cmd.processed)
            {
                ;
            }

            if (cmd.ex != null)
            {
                throw cmd.ex;
            }
        }
예제 #2
0
        // this tagged version is for cases when we might send a request - e.g. to pick a vertex or pixel
        // - and want to pre-empt it with a new request before the first has returned. Either because some
        // other work is taking a while or because we're sending requests faster than they can be
        // processed.
        // the manager processes only the request on the top of the queue, so when a new tagged invoke
        // comes in, we remove any other requests in the queue before it that have the same tag
        public void BeginInvoke(string tag, InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(tag, m);

            if (tag != "")
            {
                lock (m_renderQueue)
                {
                    bool added = false;

                    for (int i = 0; i < m_renderQueue.Count;)
                    {
                        if (m_renderQueue[i].tag == tag)
                        {
                            m_renderQueue[i].processed = true;
                            if (!added)
                            {
                                m_renderQueue[i] = cmd;
                                added            = true;
                            }
                            else
                            {
                                m_renderQueue.RemoveAt(i);
                            }
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if (!added)
                    {
                        m_renderQueue.Add(cmd);
                    }
                }

                m_WakeupEvent.Set();
            }
            else
            {
                PushInvoke(cmd);
            }
        }
        public static bool TrySchedule(object animtoken, System.Action <object> callback)
        {
            if (callback == null)
            {
                throw new System.ArgumentNullException("callback");
            }
            if (animtoken.IsNullOrDestroyed())
            {
                return(false);
            }

            if (animtoken is ISPAnim)
            {
                (animtoken as ISPAnim).Schedule((a) => callback(a));
                return(true);
            }
            else if (animtoken is IRadicalWaitHandle)
            {
                var handle = animtoken as IRadicalWaitHandle;
                if (handle.IsComplete)
                {
                    callback(animtoken);
                }
                else
                {
                    handle.OnComplete((h) => callback(h));
                }

                return(true);
            }
            else if (animtoken is AnimationState)
            {
                //GameLoop.Hook.StartCoroutine((animtoken as AnimationState).ScheduleLegacy((a) => callback(a)));
                InvokeHandle.Begin(GameLoop.UpdatePump, () => callback(animtoken), ScheduleLegacyForInvokeHandle(animtoken as AnimationState));
                return(true);
            }
            else
            {
                GameLoop.Hook.StartCoroutine(CoroutineUtil.Wait(animtoken, callback));
            }

            return(false);
        }
예제 #4
0
        public void BeginInvoke(InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(m);

            PushInvoke(cmd);
        }
예제 #5
0
        private void PushInvoke(InvokeHandle cmd)
        {
            if (m_Thread == null || !Running)
            {
                cmd.processed = true;
                return;
            }

            m_WakeupEvent.Set();

            lock (m_renderQueue)
            {
                m_renderQueue.Add(cmd);
            }
        }
예제 #6
0
        public void Invoke(InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(m);

            PushInvoke(cmd);

            while (!cmd.processed) ;

            if (cmd.ex != null)
                throw cmd.ex;
        }
예제 #7
0
        private void RunThread()
        {
            try
            {
                ReplayRenderer renderer = CreateReplayRenderer();
                if(renderer != null)
                {
                    System.Diagnostics.Debug.WriteLine("Renderer created");

                    Running = true;

                    m_current = null;

                    while (Running)
                    {
                        lock (m_renderQueue)
                        {
                            if (m_renderQueue.Count > 0)
                            {
                                m_current = m_renderQueue[0];
                                m_renderQueue.RemoveAt(0);
                            }
                        }

                        if(m_current == null)
                        {
                            m_WakeupEvent.WaitOne(10);
                            continue;
                        }

                        if (m_current.method != null)
                        {
                            if (CatchExceptions)
                            {
                                try
                                {
                                    m_current.method(renderer);
                                }
                                catch (Exception ex)
                                {
                                    m_current.ex = ex;
                                }
                            }
                            else
                            {
                                m_current.method(renderer);
                            }
                        }

                        m_current.processed = true;
                        m_current = null;
                    }

                    lock (m_renderQueue)
                    {
                        foreach (var cmd in m_renderQueue)
                            cmd.processed = true;

                        m_renderQueue.Clear();
                    }

                    DestroyReplayRenderer(renderer);
                }
            }
            catch (ReplayCreateException ex)
            {
                InitException = ex;
            }
        }
예제 #8
0
        public void InvokeForPaint(InvokeMethod m)
        {
            if (m_Thread == null || !Running)
                return;

            // special logic for painting invokes. Normally we want these to
            // go off immediately, but if we have a remote connection active
            // there could be slow operations on the pipe or currently being
            // processed.
            // So we check to see if the paint is likely to finish soon
            // (0, or only other paint invokes on the queue, nothing active)
            // and if so do it synchronously. Otherwise we just append to the
            // queue and return immediately.

            bool waitable = true;

            InvokeHandle cmd = new InvokeHandle(m);
            cmd.paintInvoke = true;

            lock (m_renderQueue)
            {
                InvokeHandle current = m_current;

                if (current != null && !current.paintInvoke)
                    waitable = false;

                // any non-painting commands on the queue? can't wait
                for (int i = 0; waitable && i < m_renderQueue.Count; i++)
                    if (!m_renderQueue[i].paintInvoke)
                        waitable = false;

                m_renderQueue.Add(cmd);
            }

            m_WakeupEvent.Set();

            if (!waitable)
                return;

            while (!cmd.processed) ;

            if (cmd.ex != null)
                throw cmd.ex;
        }
예제 #9
0
        public void CloseThreadSync()
        {
            Running = false;

            while (m_Thread != null && m_Thread.IsAlive) ;

            m_renderQueue = new List<InvokeHandle>();
            m_current = null;
        }
예제 #10
0
        public void BeginInvoke(InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(m);

            PushInvoke(cmd);
        }
예제 #11
0
        private void RunThread()
        {
            try
            {
                ReplayRenderer renderer = CreateReplayRenderer();
                if (renderer != null)
                {
                    System.Diagnostics.Debug.WriteLine("Renderer created");

                    Running = true;

                    m_current = null;

                    while (Running)
                    {
                        lock (m_renderQueue)
                        {
                            if (m_renderQueue.Count > 0)
                            {
                                m_current = m_renderQueue[0];
                                m_renderQueue.RemoveAt(0);
                            }
                        }

                        if (m_current == null)
                        {
                            m_WakeupEvent.WaitOne(10);
                            continue;
                        }

                        if (m_current.method != null)
                        {
                            if (CatchExceptions)
                            {
                                try
                                {
                                    m_current.method(renderer);
                                }
                                catch (Exception ex)
                                {
                                    m_current.ex = ex;
                                }
                            }
                            else
                            {
                                m_current.method(renderer);
                            }
                        }

                        m_current.processed = true;
                        m_current           = null;
                    }

                    lock (m_renderQueue)
                    {
                        foreach (var cmd in m_renderQueue)
                        {
                            cmd.processed = true;
                        }

                        m_renderQueue.Clear();
                    }

                    DestroyReplayRenderer(renderer);
                }
            }
            catch (ReplayCreateException ex)
            {
                InitException = ex;
            }
        }
예제 #12
0
        public void InvokeForPaint(string tag, InvokeMethod m)
        {
            if (m_Thread == null || !Running)
            {
                return;
            }

            // special logic for painting invokes. Normally we want these to
            // go off immediately, but if we have a remote connection active
            // there could be slow operations on the pipe or currently being
            // processed.
            // So we check to see if the paint is likely to finish soon
            // (0, or only other paint invokes on the queue, nothing active)
            // and if so do it synchronously. Otherwise we just append to the
            // queue and return immediately.

            bool waitable = true;

            InvokeHandle cmd = new InvokeHandle(tag, m);

            cmd.paintInvoke = true;

            lock (m_renderQueue)
            {
                InvokeHandle current = m_current;

                if (current != null && !current.paintInvoke)
                {
                    waitable = false;
                }

                // any non-painting commands on the queue? can't wait
                for (int i = 0; waitable && i < m_renderQueue.Count; i++)
                {
                    if (!m_renderQueue[i].paintInvoke)
                    {
                        waitable = false;
                    }
                }

                // remove any duplicated paints if we have a tag
                bool added = false;

                if (tag != "")
                {
                    for (int i = 0; i < m_renderQueue.Count;)
                    {
                        if (m_renderQueue[i].tag == tag)
                        {
                            m_renderQueue[i].processed = true;
                            if (!added)
                            {
                                m_renderQueue[i] = cmd;
                                added            = true;
                            }
                            else
                            {
                                m_renderQueue.RemoveAt(i);
                            }
                        }
                        else
                        {
                            i++;
                        }
                    }
                }

                if (!added)
                {
                    m_renderQueue.Add(cmd);
                }
            }

            m_WakeupEvent.Set();

            if (!waitable)
            {
                return;
            }

            while (!cmd.processed)
            {
                ;
            }

            if (cmd.ex != null)
            {
                throw cmd.ex;
            }
        }
예제 #13
0
        public void Invoke(InvokeMethod m)
        {
            InvokeHandle cmd = new InvokeHandle(m);

            PushInvoke(cmd);

            while (!cmd.processed) ;
        }