Ejemplo n.º 1
0
        public override bool DebugDraw()
        {
            /*
             * m_targetEntities.Clear();
             *
             * Matrix proj = Matrix.CreateOrthographic(300, 300, 0, 1000);
             * Matrix view = Matrix.CreateLookAt(GetPosition(), GetPosition() + WorldMatrix.Forward, WorldMatrix.Up);
             * m_visualFrustum.Matrix = view * proj;
             *
             * //MyEntities.GetIntersectionWithSphere(ref sphere, this, OwnerEntity, false, false, ref m_targetEntities);
             * MyEntities.GetAllIntersectionWithBoundingFrustum(ref m_visualFrustum, m_targetEntities);
             *
             * MyEntity target = null;
             * float closestToMissileDirection = float.MaxValue;
             *
             * foreach (MyEntity entity in m_targetEntities)
             * {
             * if (CanTarget(entity))
             * {
             *  MySmallShip targetShip = entity as MySmallShip;
             *  if (targetShip != null)
             *  {
             *      if ((targetShip.IsEngineTurnedOff()))
             *          continue;
             *  }
             *
             *  Vector3 targetPos = entity.GetPosition();
             *  Vector3 missilePos = this.GetPosition();
             *  Vector3 missilePosEnd = this.GetPosition() + this.WorldMatrix.Forward * 10000;
             *  Vector3 closestPos = MyUtils.GetClosestPointOnLine(ref missilePos, ref missilePosEnd, ref targetPos);
             *
             *  float distance = Vector3.Distance(closestPos, targetPos);
             *
             *  MyDebugDraw.DrawText(targetPos, new System.Text.StringBuilder(distance.ToString()), Color.White, 1);
             *
             *  if (distance < closestToMissileDirection)
             *  {
             *      closestToMissileDirection = distance;
             *      target = entity;
             *  }
             * }
             * }
             *
             * /*
             * MyEntity target = null; //looks better if missile gets "lost"
             *
             * float closestToMissileDirection = float.MaxValue;
             *
             * foreach (MyEntity entity in m_targetEntities)
             * {
             * if (!CanTarget(entity))
             *  continue;
             *
             * if (MyEnemyTargeting.CanSee(this, entity) == null)
             * {
             *  Vector3 targetPos = entity.GetPosition();
             *  Vector3 missilePos = this.GetPosition();
             *  Vector3 missilePosEnd = this.GetPosition() + this.WorldMatrix.Forward * 10000;
             *  Vector3 closestPos = MyUtils.GetClosestPointOnLine(ref missilePos, ref missilePosEnd, ref targetPos);
             *
             *  float distance = Vector3.Distance(closestPos, targetPos);
             *
             *
             *  MyDebugDraw.DrawText(targetPos, new System.Text.StringBuilder(distance.ToString()), Color.White, 1);
             *
             *  if (distance < closestToMissileDirection)
             *  {
             *      closestToMissileDirection = distance;
             *      target = entity;
             *  }
             * }
             * }
             */


            return(base.DebugDraw());

            //MyDebugDraw.DrawBoundingFrustum(m_visualFrustum, Color.White);
            return(true);

            //  bool retVal = base.DebugDraw();
            //if (!retVal)
            //  return false;

            //Matrix tempInvertedWorldMatrix = Matrix.Invert(Body.CollisionSkin.GetPrimitiveLocal(0).Transform.Orientation * Physics.Matrix);

            //  Transform world's Y axis to body space
            //Vector3 forward = MyUtils.GetTransformNormal(WorldMatrix.Forward, ref tempInvertedWorldMatrix);

#if DEBUG_MISSILE
            if (m_targetShip != null)
            {
                //Vector3 torque = MyUtils.GetTransformNormal(MyMwcUtils.Normalize(m_targetEntity.WorldMatrix.Translation - WorldMatrix.Translation), ref tempInvertedWorldMatrix);
                MyDebugDraw.DrawLine3D(WorldMatrix.Translation, WorldMatrix.Translation + (m_targetShip.WorldMatrix.Translation - WorldMatrix.Translation), Color.Pink, Color.Pink);

                MyDebugDraw.DrawLine3D(WorldMatrix.Translation, WorldMatrix.Translation + (m_predicatedPosition - WorldMatrix.Translation), Color.Yellow, Color.Yellow);
            }
#endif
            Vector3 pos = WorldMatrix.Translation;
            MyDebugDraw.DrawSphereWireframe(pos, WorldVolume.Radius, Vector3.One, 1);
            //Matrix matrix = Physics.Matrix;

            /*
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Right * 1000, Color.Red, Color.Red);
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Up * 1000, Color.Green, Color.Green);
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Forward * 1000, Color.Blue, Color.Blue);
             */
            /*
             * pos = WorldMatrix.Translation;
             * matrix = Physics.Matrix;
             * matrix.Right *= m_targetsRelativePosition.X;
             * matrix.Up *= m_targetsRelativePosition.Y;
             * matrix.Forward *= m_targetsRelativePosition.Z;
             *
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Right * 1000, Color.Red, Color.Red);
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Up * 1000, Color.Green, Color.Green);
             * MyDebugDraw.DrawLine3D(pos, pos + matrix.Forward * 1000, Color.Blue, Color.Blue);
             */

#if DEBUG_MISSILE
            for (int i = 0; i < m_trailDebug.Count - 1; i++)
            {
                MyDebugDraw.DrawLine3D(m_trailDebug[i], m_trailDebug[i + 1], Color.White, Color.White);
            }
#endif

            //if (this.Physics.CollisionSkin.Collisions.Count > 0)
            //{
            //    MyDebugDraw.DrawLine3D(GetPosition(), GetPosition() + (Vector3.Negate(this.Physics.CollisionSkin.Collisions[0].DirToBody0) * 1000), Color.White, Color.White);
            //}

            return(true);
        }
Ejemplo n.º 2
0
        public void DrawPerfEvents()
        {
            Vector3 v0 = Vector3.Zero;
            Vector3 v1 = Vector3.Zero;

            float x_start = 0.5f;
            float y_start = 0;
            float x_scale = (2f - x_start) / 2f;
            float y_scale = 0.9f;

            float invMilisecondRange = 1f / m_milisecondRange;

            // Draw graphs for selected events
            foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
            {
                if (!profilerBlock.DrawGraph)
                {
                    continue;
                }

                for (int i = 1; i < MyProfiler.MAX_FRAMES; i++)
                {
                    v0.X = -1.0f + x_start + x_scale * (i - 1) / 512.0f;
                    v0.Y = profilerBlock.Miliseconds[i - 1] * y_scale * invMilisecondRange;
                    v0.Z = 0;

                    v1.X = -1.0f + x_start + x_scale * i / 512.0f;
                    v1.Y = profilerBlock.Miliseconds[i] * y_scale * invMilisecondRange;
                    v1.Z = 0;

                    if (v0.Y > 1e-3f || v1.Y > 1e-3f)
                    {
                        m_lineBatch.DrawOnScreenLine(v0, v1, UintToColor(profilerBlock.color));
                    }
                }
            }


            // Draw legend
            float x_legend_start   = x_start - 0.1f;
            float x_legend_ms_size = 0.01f;

            m_lineBatch.DrawOnScreenLine(new Vector3(-1.0f + x_legend_start, 0, 0), new Vector3(-1.0f + x_legend_start, y_scale, 0), Color.Silver);

            const int legendMsCount = 5;

            StringBuilder text = new StringBuilder(10);

            float viewportWidth  = MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice.Viewport.Width;
            float viewportHeight = MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice.Viewport.Height;

            for (int i = 0; i <= legendMsCount; i++)
            {
                m_lineBatch.DrawOnScreenLine(new Vector3(-1.0f + x_legend_start, y_scale * (float)i / legendMsCount, 0),
                                             new Vector3(-1.0f + x_legend_start + x_legend_ms_size, y_scale * (float)i / legendMsCount, 0), Color.Silver);

                // Miliseconds legend
                text.Clear();
                text.Append((i * m_milisecondRange / legendMsCount).ToString());
                MyDebugDraw.DrawText(new Vector2(0.5f * viewportWidth * x_legend_start - 25f + 3 * x_legend_ms_size, -10 + 0.5f * viewportHeight - y_scale * 0.5f * viewportHeight * ((float)i / legendMsCount)), text, Color.Silver, 0.7f);
            }

            text.Clear();
            text.Append("[ms]");
            MyDebugDraw.DrawText(new Vector2(0.5f * viewportWidth * x_legend_start - 25f + 3 * x_legend_ms_size, -10 + 0.5f * viewportHeight - y_scale * 0.5f * viewportHeight * 1.05f), text, Color.Silver, 0.7f);

            // Memory legend
            x_legend_start = x_start + 1.48f;
            x_start        = 0.5f;
            y_start        = -0.7f;
            x_scale        = (2f - x_start) / 2f;

            x_legend_ms_size = -0.01f;
            y_scale          = 0.6f;

            for (int i = 0; i <= legendMsCount; i++)
            {
                text.Clear();
                text.Append((i * memoryRange / legendMsCount).ToString("#,###.###000"));
                MyDebugDraw.DrawText(new Vector2(0.5f * viewportWidth * x_legend_start - 25f + 3 * x_legend_ms_size,
                                                 -10 + 0.85f * viewportHeight - y_scale * 0.5f * viewportHeight * ((float)i / legendMsCount)),
                                     text, Color.Yellow, 0.7f);

                if (i == 0)
                {
                    text.Clear();
                    text.Append("[MB]");
                    MyDebugDraw.DrawText(new Vector2(0.5f * viewportWidth * x_legend_start - 25f + 3 * x_legend_ms_size,
                                                     -30 + 0.85f * viewportHeight - y_scale * 0.5f * viewportHeight * ((float)i / legendMsCount)),
                                         text, Color.Yellow, 0.7f);
                }
            }

            float invMemoryRange = 1f / memoryRange;

            foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
            {
                if (!profilerBlock.DrawGraph)
                {
                    continue;
                }

                // process memory
                Color processColor = UintToColor(profilerBlock.color);

#if MEMORY_PROFILING
                for (int i = 1; i < MyProfiler.MAX_FRAMES; i++)
                {
                    v0.X = -1.0f + x_start + x_scale * (i - 1) / 512.0f;
                    v0.Y = y_start + profilerBlock.ProcessMemory[i - 1] * y_scale * invMemoryRange;
                    v0.Z = 0;

                    v1.X = -1.0f + x_start + x_scale * i / 512.0f;
                    v1.Y = y_start + profilerBlock.ProcessMemory[i] * y_scale * invMemoryRange;
                    v1.Z = 0;

                    if (v0.Y - y_start > 1e-3f || v1.Y - y_start > 1e-3f)
                    {
                        lineBatch.DrawOnScreenLine(v0, v1, processColor);
                    }
                }
#else
                // managed memory
                Color managedColor = UintToColor(profilerBlock.color);
                for (int i = 1; i < MyProfiler.MAX_FRAMES; i++)
                {
                    v0.X = -1.0f + x_start + x_scale * (i - 1) / 512.0f;
                    v0.Y = y_start + profilerBlock.ManagedMemory[i - 1] * y_scale * invMemoryRange;
                    v0.Z = 0;

                    v1.X = -1.0f + x_start + x_scale * i / 512.0f;
                    v1.Y = y_start + profilerBlock.ManagedMemory[i] * y_scale * invMemoryRange;
                    v1.Z = 0;

                    //if (v0.Y - y_start > 1e-3f || v1.Y - y_start > 1e-3f)
                    m_lineBatch.DrawOnScreenLine(v0, v1, managedColor);
                }
#endif
            }

            // Draw selected frame
            if (m_useCustomFrame)
            {
                if (m_selectedFrame >= 0 && m_selectedFrame < MyProfiler.MAX_FRAMES)
                {
                    v0.X = -1.0f + x_start + x_scale * (m_selectedFrame) / 512.0f;
                    v0.Y = y_start;
                    v0.Z = 0;

                    v1.X = v0.X;
                    v1.Y = 0.9f;
                    v1.Z = 0;

                    m_lineBatch.DrawOnScreenLine(v0, v1, Color.Yellow);
                }
            }
        }
Ejemplo n.º 3
0
        public void DebugDraw(float elapsedTime, Matrix worldMatrix)
        {
            Vector3 currentOffsetUntransformed, currentOffset;

            Offset.GetInterpolatedValue <Vector3>(elapsedTime, out currentOffsetUntransformed);
            Vector3.Transform(ref currentOffsetUntransformed, ref worldMatrix, out currentOffset);
            float currentSize;

            Size.GetInterpolatedValue <float>(elapsedTime, out currentSize);

            switch (Type)
            {
            case MyParticleEmitterType.Point:
            {
                MyDebugDraw.DrawSphereWireframe(currentOffset, 0.1f, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Line:
            {
                if (DirToCamera)
                {
                    Vector3 dir = MyCamera.Position - currentOffset;
                    dir.Normalize();
                    Matrix  matrix = Matrix.CreateScale(currentSize) * MyMath.MatrixFromDir(dir);
                    Vector3 currentOffsetScaled = Vector3.TransformNormal(Vector3.Forward, matrix);
                    MyDebugDraw.DrawLine3D(worldMatrix.Translation, worldMatrix.Translation + currentOffsetScaled, Color.Yellow, Color.Yellow);
                }
                else
                {
                    Vector3 currentOffsetScaled = Vector3.Transform(Vector3.Up * currentSize, worldMatrix);
                    MyDebugDraw.DrawLine3D(worldMatrix.Translation, currentOffsetScaled, Color.Yellow, Color.Yellow);
                }
            }
            break;

            case MyParticleEmitterType.Sphere:
            {
                MyDebugDraw.DrawSphereWireframe(currentOffset, currentSize, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Box:
            {
                Matrix matrix = Matrix.CreateScale(currentSize) * Matrix.CreateTranslation(currentOffsetUntransformed) * worldMatrix;
                MyDebugDraw.DrawLowresBoxWireframe(matrix, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Hemisphere:
            {
                Vector3 worldPos = currentOffset;

                Matrix matrix;

                if (DirToCamera)
                {
                    Matrix WorldView = worldMatrix * MyCamera.ViewMatrix;
                    WorldView.Translation += currentOffsetUntransformed;
                    Matrix newWorld = WorldView * Matrix.Invert(MyCamera.ViewMatrix);

                    Vector3 dir = MyCamera.Position - newWorld.Translation;
                    dir.Normalize();

                    matrix             = Matrix.CreateScale(currentSize) * Matrix.CreateRotationX(MathHelper.PiOver2) * MyMath.MatrixFromDir(dir);
                    matrix.Translation = newWorld.Translation;
                }
                else
                {
                    matrix = Matrix.CreateScale(currentSize) * Matrix.CreateTranslation(currentOffsetUntransformed) * worldMatrix;
                }

                MyDebugDraw.DrawHemisphereWireframe(matrix, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Circle:
            {
                //No debug draw
            }
            break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
        public void DrawEvent(int textOffsetY, MyProfiler.MyProfilerBlock profilerBlock, int index = -1)
        {
            float Y_TEXT_POSITION = MyMinerGame.Static.GraphicsDevice.Viewport.Height / 2;

            float textScale = 0.7f;

            StringBuilder text = new StringBuilder(100);

            text.Clear();
            text.Append((textOffsetY + 1).ToString("0 "));
            text.Append(profilerBlock.Name);

            MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);

            float length = 500;

            text.Clear();
            text.Append(profilerBlock.Children.Count.ToString("(0) "));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 50 * textScale;

            text.Clear();
            //text.Append(((index != -1 ? profilerBlock.TimePercentage[index] : profilerBlock.averagePctg)).ToString("#,#0.0%"));
            //MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 155 * textScale;

            text.Clear();
            text.Append((index != -1 ? profilerBlock.Miliseconds[index] : profilerBlock.averageMiliseconds).ToString("#,##0.00ms"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 155 * textScale;

            text.Clear();
            text.Append((index != -1 ? profilerBlock.ManagedMemory[index] : profilerBlock.TotalManagedMB).ToString("#,###0.000 GC"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 40 + 158 * textScale;

            text.Clear();
#if MEMORY_PROFILING
            text.Append((index != -1 ? profilerBlock.ProcessMemory[index] : profilerBlock.totalProcessMB).ToString("#,###0.000 MB"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 158 * textScale;

            text.Clear();
#endif

            length += 40 + 40 * textScale;
            text.Append(profilerBlock.NumCallsArray[index != -1 ? index : 0].ToString());
            text.Append(profilerBlock.NumCalls.ToString(" calls"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);

            length += 150 * textScale;
            text.Clear();
            text.Append("Custom: ");
            text.Append((index != -1 ? profilerBlock.CustomValues[index] : profilerBlock.CustomValue).ToString("#,###0.000"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);



//             if (profilerBlock.NumCalls > 1)
//                 text.Append("s");

            length += MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
        }
Ejemplo n.º 6
0
 public void DebugDraw()
 {
     MyDebugDraw.DrawBoundingFrustum(BoundingFrustum, Color.Green);
 }
Ejemplo n.º 7
0
        static private void ShowEnhancedRenderStats()
        {
            ClearEnhancedStats();

            //m_renderObjectListForDraw.Clear();
            //m_shadowPrunningStructure.OverlapAllFrustum(ref m_cameraFrustum, m_renderObjectListForDraw);
            //m_cameraFrustumBox = new BoundingBox(new Vector3(float.NegativeInfinity), new Vector3(float.PositiveInfinity));
            //m_shadowPrunningStructure.OverlapAllBoundingBox(ref m_cameraFrustumBox, m_renderObjectListForDraw);

            foreach (MyRenderObject ro in m_renderObjectListForDraw)
            {
                string ts = ro.Entity.GetType().Name.ToString();
                if (!m_typesStats.ContainsKey(ts))
                {
                    m_typesStats.Add(ts, new MyTypeStats());
                }
                m_typesStats[ts].Count++;
            }


            float   topOffset = 100;
            Vector2 offset    = new Vector2(100, topOffset);

            MyDebugDraw.DrawText(offset, new System.Text.StringBuilder("Detailed render statistics"), Color.Yellow, 2);

            float scale = 0.7f;

            offset.Y += 50;
            MyDebugDraw.DrawText(offset, new System.Text.StringBuilder("Prepared entities for draw:"), Color.Yellow, scale);
            offset.Y += 30;
            foreach (var pair in SortByCount(m_typesStats))
            {
                MyDebugDraw.DrawText(offset, new System.Text.StringBuilder(pair.Key + ": " + pair.Value.Count.ToString() + "x"), Color.Yellow, scale);
                offset.Y += 20;
            }

            offset = new Vector2(400, topOffset + 50);
            scale  = 0.6f;
            MyDebugDraw.DrawText(offset, new System.Text.StringBuilder("Prepared prefabs for draw:"), Color.Yellow, 0.7f);
            offset.Y += 30;
            foreach (var pair in SortByCount(m_prefabStats))
            {
                MyDebugDraw.DrawText(offset, new System.Text.StringBuilder(pair.Key + ": " + pair.Value.Count.ToString() + "x"), Color.Yellow, scale);
                offset.Y += 14;
            }


            ClearEnhancedStats();
            foreach (MyRenderObject ro in m_debugRenderObjectListForDrawLOD0)
            {
                string pt = ro.Entity.GetType().Name.ToString();
                if (!m_prefabStats.ContainsKey(pt))
                {
                    m_prefabStats.Add(pt, new MyTypeStats());
                }

                m_prefabStats[pt].Count++;
                m_prefabStats[pt].Tris += ro.Entity.ModelLod0.GetTrianglesCount();
            }

            offset = new Vector2(800, topOffset + 50);
            scale  = 0.6f;
            MyDebugDraw.DrawText(offset, new System.Text.StringBuilder("Prepared entities for LOD0:"), Color.Yellow, 0.7f);
            offset.Y += 30;
            foreach (var pair in SortByCount(m_prefabStats))
            {
                MyDebugDraw.DrawText(offset, new System.Text.StringBuilder(pair.Key + ": " + pair.Value.Count.ToString() + "x [" + pair.Value.Tris.ToString() + " tris]"), Color.Yellow, scale);
                offset.Y += 14;
            }

            ClearEnhancedStats();
            foreach (MyRenderObject ro in m_debugRenderObjectListForDrawLOD1)
            {
                string pt = ro.Entity.GetType().Name.ToString();
                if (!m_prefabStats.ContainsKey(pt))
                {
                    m_prefabStats.Add(pt, new MyTypeStats());
                }

                m_prefabStats[pt].Count++;
                if (ro.Entity.ModelLod1 != null)
                {
                    m_prefabStats[pt].Tris += ro.Entity.ModelLod1.GetTrianglesCount();
                }
            }

            offset = new Vector2(1200, topOffset + 50);
            scale  = 0.6f;
            MyDebugDraw.DrawText(offset, new System.Text.StringBuilder("Prepared entities for LOD1:"), Color.Yellow, 0.7f);
            offset.Y += 30;
            foreach (var pair in SortByCount(m_prefabStats))
            {
                MyDebugDraw.DrawText(offset, new System.Text.StringBuilder(pair.Key + ": " + pair.Value.Count.ToString() + "x [" + pair.Value.Tris.ToString() + " tris]"), Color.Yellow, scale);
                offset.Y += 14;
            }
        }
Ejemplo n.º 8
0
        void DebugDrawFrustum(MatrixD camera, Color color)
        {
            BoundingFrustumD frustum = new BoundingFrustumD(camera);

            MyDebugDraw.DrawBoundingFrustum(frustum, color);
        }