Exemplo n.º 1
0
        public static void LoadContent()
        {
            MyMwcLog.WriteLine("MyDebugDraw.LoadContent() - START");
            MyMwcLog.IncreaseIndent();

            //  Line
            m_verticesLine = new MyVertexFormatPositionColor[2];
            m_verticesLine[0] = new MyVertexFormatPositionColor();
            m_verticesLine[1] = new MyVertexFormatPositionColor();

            //  Triangle
            m_triangleVertices = new MyVertexFormatPositionColor[3];
            m_triangleVertices[0] = new MyVertexFormatPositionColor();
            m_triangleVertices[1] = new MyVertexFormatPositionColor();
            m_triangleVertices[2] = new MyVertexFormatPositionColor();

            m_moints = new List<MyVertexFormatPositionColor>();  
            m_spheres = new List<BoundingSphere>();

            /*
            m_modelSphere = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Sphere");
            m_modelSphereLowRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Sphere_low");
            m_modelHemisphere = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Hemisphere");
            m_modelBoxHiRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\BoxHiRes");
            m_modelBoxLowRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\BoxLowRes");
            m_modelCapsule = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Capsule");

            m_lowResBoxEffect = (BasicEffect)m_modelBoxLowRes.Meshes[0].Effects[0];
                                   */
            m_lineBatch = new MyLineBatch(Matrix.Identity, Matrix.Identity, 128);

            m_frustumCorners = new Vector3[8];
            m_coneVertex = new List<Vector3>(32);

            MyDebugDrawCoordSystem.LoadContent();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyDebugDraw.LoadContent() - END");
        }
Exemplo n.º 2
0
        public static void LoadContent()
        {
            MyMwcLog.WriteLine("MyDebugDraw.LoadContent() - START");
            MyMwcLog.IncreaseIndent();

            //  Line
            m_verticesLine    = new MyVertexFormatPositionColor[2];
            m_verticesLine[0] = new MyVertexFormatPositionColor();
            m_verticesLine[1] = new MyVertexFormatPositionColor();

            //  Triangle
            m_triangleVertices    = new MyVertexFormatPositionColor[3];
            m_triangleVertices[0] = new MyVertexFormatPositionColor();
            m_triangleVertices[1] = new MyVertexFormatPositionColor();
            m_triangleVertices[2] = new MyVertexFormatPositionColor();

            m_moints  = new List <MyVertexFormatPositionColor>();
            m_spheres = new List <BoundingSphere>();

            /*
             * m_modelSphere = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Sphere");
             * m_modelSphereLowRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Sphere_low");
             * m_modelHemisphere = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Hemisphere");
             * m_modelBoxHiRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\BoxHiRes");
             * m_modelBoxLowRes = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\BoxLowRes");
             * m_modelCapsule = MyMinerGame.Static.Content.Load<Model>("Models2\\Debug\\Capsule");
             *
             * m_lowResBoxEffect = (BasicEffect)m_modelBoxLowRes.Meshes[0].Effects[0];
             */
            m_lineBatch = new MyLineBatch(Matrix.Identity, Matrix.Identity, 128);

            m_frustumCorners = new Vector3[8];
            m_coneVertex     = new List <Vector3>(32);

            MyDebugDrawCoordSystem.LoadContent();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyDebugDraw.LoadContent() - END");
        }
Exemplo n.º 3
0
        public void Draw()
        {
            if (!m_enabled)
                return;

            if (MyProfiler.EnableAsserts)
                MyCommonDebugUtils.AssertDebug(m_selectedProfiler.CurrentProfilingStack.Count == 0, "Stack size must be 0!");

            // Init linebatch
            if (m_lineBatch == null)
            {            
                SharpDX.Direct3D9.Device device = MyMinerGame.Static.GraphicsDevice;
                m_lineBatch = new MyLineBatch(
                    Matrix.Identity,
                    Matrix.CreateOrthographicOffCenter(0.0F, device.Viewport.Width, device.Viewport.Height, 0.0F, 0.0F, -1.0F),
                    50000);
                           
                m_fpsBlock.Stopwatch.Start();
            }


            // Handle FPS timer
            m_fpsBlock.End(false);

            float elapsedTime = (float)m_fpsBlock.Stopwatch.Elapsed.TotalSeconds;
            float invElapsedTime = elapsedTime > 0 ? 1 / elapsedTime : 0;
            m_fpsBlock.averagePctg = 0.9f * m_fpsBlock.averagePctg + 0.1f * invElapsedTime;

#if MEMORY_PROFILING
            // Handle memory usage for frame
            float processDeltaMB = m_fpsBlock.ProcessDeltaMB;
            m_fpsBlock.ProcessMemory[m_index] = processDeltaMB;
#endif

            float managedDeltaMB = m_fpsBlock.ManagedDeltaMB;
            m_fpsBlock.ManagedMemory[m_index] = managedDeltaMB;
            m_fpsBlock.CustomValues[m_index] = m_fpsBlock.CustomValue;

            m_fpsBlock.Stopwatch.Reset();
            
            m_fpsBlock.Start(false);

            int numCalls = 0;  // number of calls of StartProfilingBlock

            // Add new measured time to each graph
            if (!Paused)
            {
                foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
                {
                    float dt;

                    profilerBlock.ManagedMemory[m_index] = profilerBlock.ManagedDeltaMB;
#if MEMORY_PROFILING
                    profilerBlock.ProcessMemory[m_index] = profilerBlock.ProcessDeltaMB;
#endif
                    profilerBlock.NumCallsArray[m_index] = profilerBlock.NumCalls;
                    profilerBlock.CustomValues[m_index] = profilerBlock.CustomValue;

                    dt = (float)profilerBlock.Stopwatch.Elapsed.TotalSeconds * 1000f;

                    profilerBlock.Miliseconds[m_index] = (float)profilerBlock.Stopwatch.Elapsed.TotalMilliseconds;
                    float pctg = (0.001f * dt) * invElapsedTime;
                    profilerBlock.averagePctg = 0.9f * profilerBlock.averagePctg + (0.1f * pctg);
                    profilerBlock.averagePctg = System.Math.Min(profilerBlock.averagePctg, 1.0f); // block cannot take more than 100% of elapsed fram time
                    profilerBlock.averageMiliseconds = 0.9f * profilerBlock.averageMiliseconds + 0.1f * (float)profilerBlock.Stopwatch.Elapsed.TotalMilliseconds;
                    profilerBlock.Stopwatch.Reset();

                    if (profilerBlock.ManagedDeltaMB > memoryRange)
                        memoryRange = 2 * profilerBlock.ManagedDeltaMB;

#if MEMORY_PROFILING
                    if (profilerBlock.ProcessDeltaMB > memoryRange)
                    {
                        memoryRange = 2 * profilerBlock.ProcessDeltaMB;
                    }
#endif
                    numCalls += profilerBlock.NumCalls;
                    profilerBlock.NumChildCalls = profilerBlock.GetNumChildCalls();
                }
            }

            if (m_enabled)
            {
                // Draw events as text 
                float Y_TEXT_POSITION = MyMinerGame.Static.GraphicsDevice.Viewport.Height / 2;
                StringBuilder text = new StringBuilder(100);
                int textOffsetY = 0;

                if (m_selectedProfiler.SelectedRoot == null)
                {
                    foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
                    {
                        if (profilerBlock.Parent != null)
                            continue;

                        profilerBlock.color = textOffsetY < m_colors.Length ? m_colors[textOffsetY].PackedValue : Color.Green.PackedValue;

                        if (profilerBlock.NumCalls == 0)
                            profilerBlock.Cooldown--;
                        else
                            profilerBlock.Cooldown = 1000;

                        profilerBlock.DrawGraph = true;

                        if(m_useCustomFrame)
                            DrawEvent(textOffsetY, profilerBlock, m_selectedFrame);
                        else
                            DrawEvent(textOffsetY, profilerBlock, Paused ? (m_selectedFrame - 1) % MyProfiler.MAX_FRAMES : m_selectedFrame);

                        textOffsetY++;
                    }
                }
                else
                {
                    for (int i = 0; i < m_selectedProfiler.SelectedRoot.Children.Count; i++)
                    {
                        MyProfiler.MyProfilerBlock profilerBlock = m_selectedProfiler.SelectedRoot.Children[i];

                        profilerBlock.color = i < m_colors.Length ? m_colors[i].PackedValue : Color.Green.PackedValue;

                        if (profilerBlock.NumCalls == 0)
                            profilerBlock.Cooldown--;
                        else
                            profilerBlock.Cooldown = 1000;

                        profilerBlock.DrawGraph = true;

                        if (m_useCustomFrame)
                            DrawEvent(textOffsetY, profilerBlock, m_selectedFrame);
                        else
                            DrawEvent(textOffsetY, profilerBlock);
                        textOffsetY++;
                    }
                }

                // Draw thread name
                text.Clear();
                text.Append("Thread (" + m_selectedProfilerIndex + "/" + m_threadProfilers.Count + "): " + m_selectedThread.Name);
                text.Append(", Level limit: " + m_levelLimit.ToString());
                MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-2) * 20), text, Color.Gray, 1);

                // Draw fps
                text.Clear();
                text.Append(m_fpsBlock.Name);
                if (m_useCustomFrame && m_selectedFrame >= 0 && m_selectedFrame < MyProfiler.MAX_FRAMES)
                {
                    //text.Append(m_fpsBlock.TimePercentage[SelectedFrame].ToString(" #,###0.000"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-1) * 20), text, Color.Red, 1);
                }
                else
                {
                    text.Append(m_fpsBlock.averagePctg.ToString(" #,###0.000"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-1) * 20), text, Color.Red, 1);
                }
                

                // Total calls
                text.Clear();
                text.Append(numCalls.ToString("Total calls 0"));
                MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (textOffsetY) * 20), text, Color.Red, 1);

                if (m_useCustomFrame)
                {
                    text.Clear();
                    text.Append(m_selectedFrame.ToString("Selected frame: 0"));
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + 2*(textOffsetY) * 20), text, Color.Yellow, 1);
                }

                // Handle stack checking
                if (m_stackCheckingDuration > 0)
                {
                    text.Clear();
                    text.Append("Checking Profiler Stack");
                    MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + (-3) * 20), text, Color.Orange, 1);

                    m_stackCheckingDuration -= elapsedTime;
                    m_stackCheckingDuration = Math.Max(m_stackCheckingDuration, 0);

                    MyProfiler.StackChecking = true;   // enable checking for next frame
                }
                else
                    MyProfiler.StackChecking = false;
                
                                    
                // Draw graphs
                m_lineBatch.Begin();
                DrawPerfEvents();
                m_lineBatch.End();
            }

            // Update horizontal offset
            if (!Paused)
            {
                m_index = (++m_index) % MyProfiler.MAX_FRAMES;

                if (!m_useCustomFrame)
                    m_selectedFrame = m_index;
            }

            // Reset childs before next run
            foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
            {
                profilerBlock.StackChildren.Clear();
                profilerBlock.StackParent = null;
                profilerBlock.Stopwatch.Reset();
                profilerBlock.DrawGraph = false;
                profilerBlock.NumCalls = 0;
                profilerBlock.NumChildCalls = -1; // -1 means it needs to be computed first.

                profilerBlock.StartManagedMB = 0;
                profilerBlock.EndManagedMB = 0;
                profilerBlock.DeltaManagedB = 0;

#if MEMORY_PROFILING
                profilerBlock.startProcessMB = 0;
                profilerBlock.endProcessMB = 0;
                profilerBlock.deltaProcessB = 0;
#endif

                profilerBlock.CustomValue = 0;
            }
        }