Exemplo n.º 1
0
        public static void HandleInput(RenderProfilerCommand command, int index)
        {
            switch (command)
            {
                case RenderProfilerCommand.Enable:
                    {
                        if (!m_enabled)
                        {
                            m_enabled = true;
                            m_profilerProcessingEnabled = true; // Enable when disabled and keep enabled
                            SetLevel();
                        }
                        break;
                    }

                case RenderProfilerCommand.ToggleEnabled:
                    {
                        // Enable or Disable profiler drawing
                        if (m_enabled)
                        {
                            m_enabled = false;
                            m_useCustomFrame = false;
                        }
                        else
                        {
                            m_enabled = true;
                            m_profilerProcessingEnabled = true; // Enable when disabled and keep enabled
                        }
                        break;
                    }

                case RenderProfilerCommand.JumpToRoot:
                    m_selectedProfiler.SelectedRoot = null;
                    break;

                case RenderProfilerCommand.JumpToLevel:
                    {
                        // Enable when disabled, added this for programmers who are too used to using the numpad 0 to open the profiler.
                        if (index == 0 && !m_enabled)
                        {
                            m_enabled = true;
                            m_profilerProcessingEnabled = true; // Enable when disabled and keep enabled
                        }
                        else
                            m_selectedProfiler.SelectedRoot = FindBlockByIndex(index - 1); // On screen it's indexed from 1 (zero is level up)
                        break;
                    }
                case RenderProfilerCommand.Pause:
                    {
                        Paused = !Paused;
                        break;
                    }

                case RenderProfilerCommand.NextThread:
                    {
                        lock (m_threadProfilers)
                        {
                            int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) + 1) % m_threadProfilers.Count;
                            m_selectedProfiler = m_threadProfilers[profilerIndex];
                        }
                        break;
                    }

                case RenderProfilerCommand.PreviousThread:
                    {
                        lock (m_threadProfilers)
                        {
                            int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) - 1 + m_threadProfilers.Count) % m_threadProfilers.Count;
                            m_selectedProfiler = m_threadProfilers[profilerIndex];
                        }
                        break;
                    }

                case RenderProfilerCommand.Reset:
                    {
                        lock (m_threadProfilers)
                        {
                            foreach (var profiler in m_threadProfilers)
                            {
                                profiler.Reset();
                            }
                            m_selectedFrame = 0;
                        }
                        break;
                    }

                case RenderProfilerCommand.NextFrame:
                    {
                        MyRenderProfiler.NextFrame(index);
                        break;
                    }

                case RenderProfilerCommand.PreviousFrame:
                    {
                        MyRenderProfiler.PreviousFrame(index);
                        break;
                    }

                case RenderProfilerCommand.DisableFrameSelection:
                    {
                        m_useCustomFrame = false;
                        break;
                    }

                case RenderProfilerCommand.IncreaseLevel:
                    {
                        m_levelLimit++;
                        SetLevel();
                        break;
                    }

                case RenderProfilerCommand.DecreaseLevel:
                    {
                        m_levelLimit--;
                        if (m_levelLimit < -1)
                            m_levelLimit = -1;
                        SetLevel();
                        break;
                    }

                case RenderProfilerCommand.CopyPathToClipboard:
                    {
                        StringBuilder pathBuilder = new StringBuilder(200);
                        MyProfilerBlock currentBlock = m_selectedProfiler.SelectedRoot;

                        while (currentBlock != null)
                        {
                            if (pathBuilder.Length > 0)
                                pathBuilder.Insert(0, " > ");
                            pathBuilder.Insert(0, currentBlock.Name);
                            currentBlock = currentBlock.Parent;
                        }

                        if (pathBuilder.Length > 0)
                        {
                            // Clipboard can only be accessed from a thread on the STA apartment
                            System.Threading.Thread thread = new System.Threading.Thread(() => System.Windows.Forms.Clipboard.SetText(pathBuilder.ToString()));
                            thread.SetApartmentState(System.Threading.ApartmentState.STA);
                            thread.Start();
                            thread.Join();
                        }
                        break;
                    }

                case RenderProfilerCommand.TryGoToPathInClipboard:
                    {
                        string fullPath = string.Empty;

                        Exception threadEx = null;
                        System.Threading.Thread staThread = new System.Threading.Thread(
                            delegate()
                            {
                                try
                                {
                                    fullPath = System.Windows.Forms.Clipboard.GetText();
                                }

                                catch (Exception ex)
                                {
                                    threadEx = ex;
                                }
                            });
                        staThread.SetApartmentState(System.Threading.ApartmentState.STA);
                        staThread.Start();
                        staThread.Join();

                        if (!string.IsNullOrEmpty(fullPath))
                        {
                            string[] split = fullPath.Split(new string[] { " > " }, StringSplitOptions.None);

                            MyProfilerBlock pathBlock = null;
                            List<MyProfilerBlock> blockSet = m_selectedProfiler.RootBlocks;
                            for (int i = 0; i<split.Length; i++)
                            {
                                string blockName = split[i];
                                MyProfilerBlock oldPath = pathBlock;

                                for (int j = 0; j<blockSet.Count; j++)
                                {
                                    MyProfilerBlock block = blockSet[j];
                                    if (block.Name == blockName)
                                    {
                                        pathBlock = block;
                                        blockSet = pathBlock.Children;
                                        break;
                                    }
                                }

                                // If the path did not change, we cannot go any deeper, break out of this loop
                                if (oldPath == pathBlock)
                                    break;
                            }

                            if (pathBlock != null)
                                m_selectedProfiler.SelectedRoot = pathBlock;
                        }
                        break;
                    }

                case RenderProfilerCommand.SetLevel:
                    {
                        m_levelLimit = index;
                        if (m_levelLimit < -1)
                            m_levelLimit = -1;
                        SetLevel();
                        break;
                    }

                case RenderProfilerCommand.DecreaseLocalArea:
                    m_frameLocalArea = Math.Max(2, m_frameLocalArea / 2);
                    break;

                case RenderProfilerCommand.IncreaseLocalArea:
                    m_frameLocalArea = Math.Min(MyProfiler.MAX_FRAMES, m_frameLocalArea * 2);
                    break;

                case RenderProfilerCommand.IncreaseRange:
                    m_milisecondsGraphScale.IncreaseYRange();
                    break;

                case RenderProfilerCommand.DecreaseRange:
                    m_milisecondsGraphScale.DecreaseYRange();
                    break;

                case RenderProfilerCommand.ChangeSortingOrder:
                    m_sortingOrder += 1;
                    if (m_sortingOrder >= RenderProfilerSortingOrder.NumSortingTypes)
                        m_sortingOrder = RenderProfilerSortingOrder.Id;
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown command");
                    break;
            }
        }
Exemplo n.º 2
0
        public static void HandleInput(RenderProfilerCommand command, int index)
        {
            switch (command)
            {
            case RenderProfilerCommand.Enable:
            {
                // Enable or Disable profiler drawing
                if (m_enabled && m_selectedProfiler.SelectedRoot == null)
                {
                    m_enabled        = false;
                    m_useCustomFrame = false;
                }
                else if (!m_enabled)
                {
                    m_enabled = true;
                }
                else
                {
                    // Go to parent node
                    if (m_selectedProfiler.SelectedRoot != null)
                    {
                        m_selectedProfiler.SelectedRoot = m_selectedProfiler.SelectedRoot.Parent;
                    }
                }
                break;
            }

            case RenderProfilerCommand.JumpToLevel:
            {
                m_selectedProfiler.SelectedRoot = FindBlockByIndex(index - 1);         // On screen it's indexed from 1 (zero is level up)
                break;
            }

            case RenderProfilerCommand.FindMaxChild:
            {
                MyProfiler.MyProfilerBlock block;
                int lastFrameIndex;
                using (m_selectedProfiler.LockHistory(out lastFrameIndex))
                {
                    block = FindBlockByMax(m_selectedFrame, lastFrameIndex);
                }
                if (block != null)
                {
                    m_selectedProfiler.SelectedRoot = block;
                }
                break;
            }

            case RenderProfilerCommand.Pause:
            {
                Paused           = !Paused;
                m_useCustomFrame = false;         // Turn-off custom frame after ALT + ENTER

                break;
            }

            case RenderProfilerCommand.NextThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) + 1) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.PreviousThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) - 1 + m_threadProfilers.Count) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.NextFrame:
            {
                MyRenderProfiler.NextFrame();
                break;
            }

            case RenderProfilerCommand.PreviousFrame:
            {
                MyRenderProfiler.PreviousFrame();
                break;
            }

            case RenderProfilerCommand.IncreaseLevel:
            {
                m_levelLimit++;
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLevel:
            {
                m_levelLimit--;
                if (m_levelLimit < -1)
                {
                    m_levelLimit = -1;
                }
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLocalArea:
                m_frameLocalArea = Math.Max(2, m_frameLocalArea / 2);
                break;

            case RenderProfilerCommand.IncreaseLocalArea:
                m_frameLocalArea = Math.Min(MyProfiler.MAX_FRAMES, m_frameLocalArea * 2);
                break;

            case RenderProfilerCommand.IncreaseRange:
                m_milisecondsGraphScale.IncreaseYRange();
                break;

            case RenderProfilerCommand.DecreaseRange:
                m_milisecondsGraphScale.DecreaseYRange();
                break;

            default:
                System.Diagnostics.Debug.Assert(false, "Unknown command");
                break;
            }
        }
Exemplo n.º 3
0
        public static void RenderProfilerInput(RenderProfilerCommand command, int index)
        {
            var message = MessagePool.Get<MyRenderMessageRenderProfiler>(MyRenderMessageEnum.RenderProfiler);

            message.Command = command;
            message.Index = index;

            EnqueueMessage(message);
        }
Exemplo n.º 4
0
        public static void HandleInput(RenderProfilerCommand command, int index)
        {
            switch (command)
            {
            case RenderProfilerCommand.Enable:
            {
                if (!m_enabled)
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;         // Enable when disabled and keep enabled
                    SetLevel();
                }
                break;
            }

            case RenderProfilerCommand.ToggleEnabled:
            {
                // Enable or Disable profiler drawing
                if (m_enabled)
                {
                    m_enabled        = false;
                    m_useCustomFrame = false;
                }
                else
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;         // Enable when disabled and keep enabled
                }
                break;
            }

            case RenderProfilerCommand.JumpToRoot:
                m_selectedProfiler.SelectedRoot = null;
                break;

            case RenderProfilerCommand.JumpToLevel:
            {
                // Enable when disabled, added this for programmers who are too used to using the numpad 0 to open the profiler.
                if (index == 0 && !m_enabled)
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;
                }
                else
                {
                    MyProfiler.MyProfilerBlock nextBlock = FindBlockByIndex(index - 1);         // On screen it's indexed from 1 (zero is level up)
                    if (nextBlock != null || (m_selectedProfiler.SelectedRoot != null && m_selectedProfiler.SelectedRoot.Parent == null))
                    {
                        m_selectedProfiler.SelectedRoot = nextBlock;
                    }
                }
                break;
            }

            case RenderProfilerCommand.Pause:
            {
                Paused = !Paused;
                break;
            }

            case RenderProfilerCommand.NextThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) + 1) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.PreviousThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) - 1 + m_threadProfilers.Count) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.Reset:
            {
                lock (m_threadProfilers)
                {
                    foreach (var profiler in m_threadProfilers)
                    {
                        profiler.Reset();
                    }
                    m_selectedFrame = 0;
                }
                break;
            }

            case RenderProfilerCommand.NextFrame:
            {
                MyRenderProfiler.NextFrame(index);
                break;
            }

            case RenderProfilerCommand.PreviousFrame:
            {
                MyRenderProfiler.PreviousFrame(index);
                break;
            }

            case RenderProfilerCommand.DisableFrameSelection:
            {
                m_useCustomFrame = false;
                break;
            }

            case RenderProfilerCommand.IncreaseLevel:
            {
                m_levelLimit++;
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLevel:
            {
                m_levelLimit--;
                if (m_levelLimit < -1)
                {
                    m_levelLimit = -1;
                }
                SetLevel();
                break;
            }

            case RenderProfilerCommand.CopyPathToClipboard:
            {
                StringBuilder pathBuilder = new StringBuilder(200);
                MyProfiler.MyProfilerBlock currentBlock = m_selectedProfiler.SelectedRoot;

                while (currentBlock != null)
                {
                    if (pathBuilder.Length > 0)
                    {
                        pathBuilder.Insert(0, " > ");
                    }
                    pathBuilder.Insert(0, currentBlock.Name);
                    currentBlock = currentBlock.Parent;
                }

                if (pathBuilder.Length > 0)
                {
                    // Clipboard can only be accessed from a thread on the STA apartment
                    System.Threading.Thread thread = new System.Threading.Thread(() => System.Windows.Forms.Clipboard.SetText(pathBuilder.ToString()));
                    thread.SetApartmentState(System.Threading.ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
                break;
            }

            case RenderProfilerCommand.TryGoToPathInClipboard:
            {
                string fullPath = string.Empty;

                Exception threadEx = null;
                System.Threading.Thread staThread = new System.Threading.Thread(
                    delegate()
                    {
                        try
                        {
                            fullPath = System.Windows.Forms.Clipboard.GetText();
                        }

                        catch (Exception ex)
                        {
                            threadEx = ex;
                        }
                    });
                staThread.SetApartmentState(System.Threading.ApartmentState.STA);
                staThread.Start();
                staThread.Join();

                if (!string.IsNullOrEmpty(fullPath))
                {
                    string[] split = fullPath.Split(new string[] { " > " }, StringSplitOptions.None);

                    MyProfiler.MyProfilerBlock        pathBlock = null;
                    List <MyProfiler.MyProfilerBlock> blockSet  = m_selectedProfiler.RootBlocks;
                    for (int i = 0; i < split.Length; i++)
                    {
                        string blockName = split[i];
                        MyProfiler.MyProfilerBlock oldPath = pathBlock;

                        for (int j = 0; j < blockSet.Count; j++)
                        {
                            MyProfiler.MyProfilerBlock block = blockSet[j];
                            if (block.Name == blockName)
                            {
                                pathBlock = block;
                                blockSet  = pathBlock.Children;
                                break;
                            }
                        }

                        // If the path did not change, we cannot go any deeper, break out of this loop
                        if (oldPath == pathBlock)
                        {
                            break;
                        }
                    }

                    if (pathBlock != null)
                    {
                        m_selectedProfiler.SelectedRoot = pathBlock;
                    }
                }
                break;
            }

            case RenderProfilerCommand.SetLevel:
            {
                m_levelLimit = index;
                if (m_levelLimit < -1)
                {
                    m_levelLimit = -1;
                }
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLocalArea:
                m_frameLocalArea = Math.Max(2, m_frameLocalArea / 2);
                break;

            case RenderProfilerCommand.IncreaseLocalArea:
                m_frameLocalArea = Math.Min(MyProfiler.MAX_FRAMES, m_frameLocalArea * 2);
                break;

            case RenderProfilerCommand.IncreaseRange:
                m_milisecondsGraphScale.IncreaseYRange();
                break;

            case RenderProfilerCommand.DecreaseRange:
                m_milisecondsGraphScale.DecreaseYRange();
                break;

            case RenderProfilerCommand.ChangeSortingOrder:
                m_sortingOrder += 1;
                if (m_sortingOrder >= RenderProfilerSortingOrder.NumSortingTypes)
                {
                    m_sortingOrder = RenderProfilerSortingOrder.Id;
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false, "Unknown command");
                break;
            }
        }
Exemplo n.º 5
0
        public static void HandleInput(RenderProfilerCommand command, int index)
        {
            switch (command)
            {
                case RenderProfilerCommand.Enable:
                    {
                        // Enable or Disable profiler drawing
                        if (m_enabled && m_selectedProfiler.SelectedRoot == null)
                        {
                            m_enabled = false;
                            m_useCustomFrame = false;
                        }
                        else if (!m_enabled)
                        {
                            m_enabled = true;
                        }
                        else
                        {
                            // Go to parent node
                            if (m_selectedProfiler.SelectedRoot != null)
                            {
                                m_selectedProfiler.SelectedRoot = m_selectedProfiler.SelectedRoot.Parent;
                            }
                        }
                        break;
                    }

                case RenderProfilerCommand.JumpToLevel:
                    {
                        m_selectedProfiler.SelectedRoot = FindBlockByIndex(index - 1); // On screen it's indexed from 1 (zero is level up)
                        break;
                    }

                case RenderProfilerCommand.FindMaxChild:
                    {
                        MyProfiler.MyProfilerBlock block;
                        int lastFrameIndex;
                        using (m_selectedProfiler.LockHistory(out lastFrameIndex))
                        {
                            block = FindBlockByMax(m_selectedFrame, lastFrameIndex);
                        }
                        if (block != null)
                        {
                            m_selectedProfiler.SelectedRoot = block;
                        }
                        break;
                    }

                case RenderProfilerCommand.Pause:
                    {
                        Paused = !Paused;
                        m_useCustomFrame = false; // Turn-off custom frame after ALT + ENTER

                        break;
                    }

                case RenderProfilerCommand.NextThread:
                    {
                        lock (m_threadProfilers)
                        {
                            int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) + 1) % m_threadProfilers.Count;
                            m_selectedProfiler = m_threadProfilers[profilerIndex];
                        }
                        break;
                    }

                case RenderProfilerCommand.PreviousThread:
                    {
                        lock (m_threadProfilers)
                        {
                            int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) - 1 + m_threadProfilers.Count) % m_threadProfilers.Count;
                            m_selectedProfiler = m_threadProfilers[profilerIndex];
                        }
                        break;
                    }

                case RenderProfilerCommand.NextFrame:
                    {
                        MyRenderProfiler.NextFrame();
                        break;
                    }

                case RenderProfilerCommand.PreviousFrame:
                    {
                        MyRenderProfiler.PreviousFrame();
                        break;
                    }

                case RenderProfilerCommand.IncreaseLevel:
                    {
                        m_levelLimit++;
                        SetLevel();
                        break;
                    }

                case RenderProfilerCommand.DecreaseLevel:
                    {
                        m_levelLimit--;
                        if (m_levelLimit < -1)
                            m_levelLimit = -1;
                        SetLevel();
                        break;
                    }

                case RenderProfilerCommand.DecreaseLocalArea:
                    m_frameLocalArea = Math.Max(2, m_frameLocalArea / 2);
                    break;

                case RenderProfilerCommand.IncreaseLocalArea:
                    m_frameLocalArea = Math.Min(MyProfiler.MAX_FRAMES, m_frameLocalArea * 2);
                    break;

                case RenderProfilerCommand.IncreaseRange:
                    m_milisecondsGraphScale.IncreaseYRange();
                    break;

                case RenderProfilerCommand.DecreaseRange:
                    m_milisecondsGraphScale.DecreaseYRange();
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown command");
                    break;
            }
        }