Пример #1
0
        private static void DebugDrawLights()
        {
            return;

            //Debug draw lights
            foreach (MyRenderLight light in m_renderLightsForDraw)
            {
                //if (light.LightOn && light.Glare.Type == TransparentGeometry.MyLightGlare.GlareTypeEnum.Distant)
                {
                    if ((light.LightType & LightTypeEnum.PointLight) != 0)
                    {
                        MyDebugDraw.DrawSphereWireframe(MatrixD.CreateScale(light.Range) * MatrixD.CreateTranslation(light.PositionWithOffset), Color.Red, 1);
                        MyDebugDraw.DrawAxis(MatrixD.CreateWorld(light.Position, light.ReflectorDirection, light.ReflectorUp), 2, 1, false);
                        // MyDebugDraw.DrawText(light.PositionWithOffset, new System.Text.StringBuilder(light.ID.ToString()), Color.White, 1);
                    }
                    //if ((light.LightType & LightTypeEnum.Hemisphere) != 0)
                    //{
                    //    Matrix rotationHotfix = Matrix.CreateFromAxisAngle(Vector3.UnitX, MathHelper.PiOver2);
                    //    Matrix world = Matrix.CreateScale(light.Range) * rotationHotfix * Matrix.CreateWorld(light.Position, light.ReflectorDirection, light.ReflectorUp);
                    //    MyDebugDraw.DrawHemisphereWireframe(world, new Vector3(1, 0, 0), 1);
                    //}
                    if ((light.LightType & LightTypeEnum.Spotlight) != 0)
                    {
                        // Uncomment to show sphere for spot light
                        //MyDebugDraw.DrawSphereWireframe(Matrix.CreateScale(light.ReflectorRange) * Matrix.CreateTranslation(light.Position), new Vector3(color.X, color.Y, color.Z), 0.25f);

                        //MyDebugDraw.DrawCapsule(light.Position, light.Position + light.ReflectorDirection * light.ReflectorRange, 1, new Color(color.X, color.Y, color.Z), false);

                        //float reflectorConeAngle = (float)System.Math.Acos(1 - light.ReflectorConeMaxAngleCos);
                        //float reflectorRadius = (float)System.Math.Tan(reflectorConeAngle) * light.ReflectorRange;
                        //MyDebugDraw.DrawCylinder(light.Position, light.Position + light.ReflectorDirection * light.ReflectorRange, 0, reflectorRadius, new Color(color.X, color.Y, color.Z), false);

//                        MyDebugDraw.DrawText(light.Position, new System.Text.StringBuilder(light.ShadowMapIndex.ToString() + " (" + (light.SpotQuery != null ? light.QueryPixels.ToString() : "") + ")" ), Color.Yellow, 0.8f, false);

                        MyDebugDraw.DrawText(light.Position, new System.Text.StringBuilder(Vector3D.Distance(MyRenderCamera.Position, light.Position).ToString()), Color.Yellow, 0.8f, false);

                        MyStateObjects.WireframeClockwiseRasterizerState.Apply();
                        DepthStencilState.None.Apply();



                        MyDebugDraw.DrawModel(MyDebugDraw.ModelCone, light.SpotWorld, Color.White, false);
                    }

                    //just glare
                    if (light.LightType == LightTypeEnum.None)
                    {
                        MyDebugDraw.DrawSphereWireframe(MatrixD.CreateScale(light.Range) * MatrixD.CreateTranslation(light.PositionWithOffset), Color.Red, 1);
                    }
                }
            }
        }
Пример #2
0
        public void DebugDraw()
        {
            MyDebugDraw.DrawAxis(WorldMatrix, 1.0f, 1.0f);
            MyDebugDraw.DrawSphereWireframe(WorldMatrix.Translation, 0.1f, Vector3.One, 1.0f);

            foreach (MyParticleGeneration generation in m_generations)
            {
                generation.DebugDraw();
            }

            Color color = !m_isStopped ? Color.White : Color.Red;

            MyDebugDraw.DrawText(WorldMatrix.Translation, new System.Text.StringBuilder(GetID().ToString() + " [" + GetParticlesCount().ToString() + "]"), color, 1.0f);

            // Vector4 colorV = color.ToVector4();
            // MyDebugDraw.DrawAABB(ref m_AABB, ref colorV, 1.0f);
        }
Пример #3
0
        void DrawWaypointEdge(Vector3 position1, Vector3 position2, Color color1, Color color2)
        {
            if (MyFakes.MWBUILDER)
            {
                MyDebugDraw.DrawText((position1 + position2) / 2, new StringBuilder(Vector3.Distance(position1, position2).ToString("#,###0.000")), Color.White, 1);
            }

            if (position1 == position2)
            {
                return;
            }
            Vector3 direction  = position2 - position1;
            float   lineLength = direction.Length();

            direction.Normalize();
            MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, color1.ToVector4(), position1, direction, lineLength, 0.25f);

            if (MyWayPointGraph.WaypointsIgnoreDepth)
            {
                MyDebugDraw.DrawLine3D(position1, position2, color1, color2);
            }
        }
Пример #4
0
        public override bool DebugDraw()
        {
            if (!base.DebugDraw())
            {
                return(false);
            }

            if (DRAW_DEBUG_INFORMATION)
            {
                m_debugDrawSb.Clear();

                m_debugDrawSb.Append("Is working:");
                m_debugDrawSb.Append(IsWorking());
                m_debugDrawSb.AppendLine();

                m_debugDrawSb.Append("Enabled:");
                m_debugDrawSb.Append(Enabled);
                m_debugDrawSb.AppendLine();

                m_debugDrawSb.Append("Detected entities:");
                m_debugDrawSb.AppendInt32(m_sensorHandler.GetDetectedEntitiesCount());
                m_debugDrawSb.AppendLine();

                m_debugDrawSb.Append("Sensor interactions:");
                m_debugDrawSb.AppendInt32(m_sensor.m_Interactions.Count);
                m_debugDrawSb.AppendLine();

                KinematicPrefabStateEnum?state = null;
                bool?isOpened = null;
                bool?isClosed = null;
                foreach (var part in Parts)
                {
                    if (part != null)
                    {
                        Debug.Assert(state == null || state.Value == part.GetState());
                        Debug.Assert(isOpened == null || isOpened.Value == part.IsOpened());
                        Debug.Assert(isClosed == null || isClosed.Value == part.IsClosed());
                        state    = part.GetState();
                        isOpened = part.IsOpened();
                        isClosed = part.IsClosed();
                    }
                }
                if (state != null && isOpened != null && isClosed != null)
                {
                    m_debugDrawSb.Append("State:");
                    switch (state.Value)
                    {
                    case KinematicPrefabStateEnum.Closing:
                        m_debugDrawSb.Append("Closing");
                        break;

                    case KinematicPrefabStateEnum.Opening:
                        m_debugDrawSb.Append("Opening");
                        break;

                    case KinematicPrefabStateEnum.Sleeping:
                        m_debugDrawSb.Append("Sleeping");
                        break;
                    }
                    m_debugDrawSb.AppendLine();
                    m_debugDrawSb.Append("IsOpened:");
                    m_debugDrawSb.Append(isOpened.Value);
                    m_debugDrawSb.AppendLine();
                    m_debugDrawSb.Append("IsClosed:");
                    m_debugDrawSb.Append(isClosed.Value);
                }


                MyDebugDraw.DrawText(WorldVolume.Center, m_debugDrawSb, Color.White, 0.5f);

                float radius = DETECTION_ANGLE != null ? DETECT_RADIUS * 0.5f : DETECT_RADIUS;
                MyDebugDraw.DrawSphereWireframe(WorldVolume.Center, radius, new Vector3(0f, 1f, 0f), 0.5f);
                if (DETECTION_ANGLE != null)
                {
                    float radius2 = (float)Math.Tan(DETECTION_ANGLE.Value) * DETECT_RADIUS;
                    Color color   = Color.Red;
                    color.A = 55;
                    MyDebugDraw.DrawCone(WorldVolume.Center, WorldVolume.Center + WorldMatrix.Forward * DETECT_RADIUS, radius2, color);
                    MyDebugDraw.DrawCone(WorldVolume.Center, WorldVolume.Center + WorldMatrix.Backward * DETECT_RADIUS, radius2, color);
                    //MyDebugDraw.DrawSphereWireframe(WorldVolume.Center, DETECT_RADIUS, color.ToVector3(), 0.3f);
                }
            }

            return(true);
        }
Пример #5
0
        private static void DrawDebugMessages()
        {
            //DepthStencilState.None.Apply();
            DepthStencilState.DepthRead.Apply();
            BlendState.NonPremultiplied.Apply();

            while (m_debugDrawMessages.Count > 0)
            {
                IMyRenderMessage debugDrawMessage = m_debugDrawMessages.Dequeue();

                MyRenderMessageEnum messageType = debugDrawMessage.MessageType;

                switch (messageType)
                {
                case MyRenderMessageEnum.DebugDrawLine3D:
                {
                    MyRenderMessageDebugDrawLine3D message = (MyRenderMessageDebugDrawLine3D)debugDrawMessage;

                    MyDebugDraw.DrawLine3D(
                        message.PointFrom,
                        message.PointTo,
                        message.ColorFrom,
                        message.ColorTo,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawLine2D:
                {
                    MyRenderMessageDebugDrawLine2D message = (MyRenderMessageDebugDrawLine2D)debugDrawMessage;

                    MyDebugDraw.DrawLine2D(
                        message.PointFrom,
                        message.PointTo,
                        message.ColorFrom,
                        message.ColorTo,
                        message.Projection);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawSphere:
                {
                    MyRenderMessageDebugDrawSphere message = (MyRenderMessageDebugDrawSphere)debugDrawMessage;

                    MyDebugDraw.DrawSphere(
                        message.Position,
                        message.Radius,
                        message.Color,
                        message.Alpha,
                        message.DepthRead,
                        message.Smooth,
                        message.Cull);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawAABB:
                {
                    MyRenderMessageDebugDrawAABB message = (MyRenderMessageDebugDrawAABB)debugDrawMessage;

                    Color color = new Color(message.Color, message.Alpha);
                    var   aabb  = new BoundingBoxD(message.AABB.Min, message.AABB.Max);
                    MyDebugDraw.DrawAABBLine(
                        ref aabb,
                        ref color,
                        message.Scale,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawAxis:
                {
                    MyRenderMessageDebugDrawAxis message = (MyRenderMessageDebugDrawAxis)debugDrawMessage;

                    MyDebugDraw.DrawAxis(
                        (MatrixD)message.Matrix,
                        message.AxisLength,
                        1,
                        message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawOBB:
                {
                    MyRenderMessageDebugDrawOBB message = (MyRenderMessageDebugDrawOBB)debugDrawMessage;

                    if (message.Smooth)
                    {
                        MyDebugDraw.DrawLowresBoxSmooth(
                            message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead,
                            message.Cull);
                    }
                    else
                    {
                        MyDebugDraw.DrawOBBLine(
                            new MyOrientedBoundingBoxD(message.Matrix),
                            message.Color,
                            message.Alpha,
                            message.DepthRead);

                        //BoundingBoxD bd = new BoundingBoxD(message.Matrix.Translation - new Vector3(100),message.Matrix.Translation + new Vector3(100));

                        //Vector4 c = new Vector4(message.Color.X, message.Color.Y, message.Color.Z, message.Alpha);
                        //MyDebugDraw.DrawAABBLine(ref bd, ref c, 1, false);
                    }
                    break;
                }

                case MyRenderMessageEnum.DebugDrawCylinder:
                {
                    MyRenderMessageDebugDrawCylinder message = (MyRenderMessageDebugDrawCylinder)debugDrawMessage;

                    if (message.Smooth)
                    {
                        MyDebugDraw.DrawLowresCylinderSmooth(
                            (MatrixD)message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead);
                    }
                    else
                    {
                        MyDebugDraw.DrawLowresCylinderWireframe(
                            (MatrixD)message.Matrix,
                            message.Color,
                            message.Alpha,
                            message.DepthRead);
                    }
                    break;
                }

                case MyRenderMessageEnum.DebugDrawTriangle:
                {
                    MyRenderMessageDebugDrawTriangle message = (MyRenderMessageDebugDrawTriangle)debugDrawMessage;

                    MyDebugDraw.DrawTriangle((Vector3D)message.Vertex0, (Vector3D)message.Vertex1, (Vector3D)message.Vertex2, message.Color, message.Color, message.Color, message.Smooth, message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawTriangles:
                {
                    MyRenderMessageDebugDrawTriangles message = (MyRenderMessageDebugDrawTriangles)debugDrawMessage;

                    MyDebugDraw.DrawTriangles(message.WorldMatrix, message.Vertices, message.Indices, message.Color,
                                              message.DepthRead, message.Shaded);
                    break;
                }

                case MyRenderMessageEnum.DebugDrawCapsule:
                {
                    MyRenderMessageDebugDrawCapsule message = (MyRenderMessageDebugDrawCapsule)debugDrawMessage;

                    if (message.Shaded)
                    {
                        MyDebugDraw.DrawCapsuleShaded(message.P0, message.P1, message.Radius, message.Color, message.DepthRead);
                    }
                    else
                    {
                        MyDebugDraw.DrawCapsule(message.P0, message.P1, message.Radius, message.Color, message.DepthRead);
                    }

                    break;
                }

                case MyRenderMessageEnum.DebugDrawText2D:
                {
                    MyRenderMessageDebugDrawText2D message = (MyRenderMessageDebugDrawText2D)debugDrawMessage;

                    MyDebugDraw.DrawText(
                        message.Coord,
                        new StringBuilder(message.Text),
                        message.Color,
                        message.Scale,
                        false,
                        message.Align);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawText3D:
                {
                    MyRenderMessageDebugDrawText3D message = (MyRenderMessageDebugDrawText3D)debugDrawMessage;

                    MyDebugDraw.DrawText(
                        (Vector3D)message.Coord,
                        new StringBuilder(message.Text),
                        message.Color,
                        message.Scale,
                        message.DepthRead,
                        message.Align,
                        message.CustomViewProjection);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawModel:
                {
                    MyRenderMessageDebugDrawModel message = (MyRenderMessageDebugDrawModel)debugDrawMessage;

                    MyDebugDraw.DrawModel(MyRenderModels.GetModel(message.Model), message.WorldMatrix, message.Color,
                                          message.DepthRead);

                    break;
                }

                case MyRenderMessageEnum.DebugDrawPlane:
                {
                    MyRenderMessageDebugDrawPlane message = (MyRenderMessageDebugDrawPlane)debugDrawMessage;

                    MyDebugDraw.DrawPlane((Vector3D)message.Position, message.Normal, message.Color, message.DepthRead);

                    break;
                }

                default:
                {
                    System.Diagnostics.Debug.Assert(false, "Unknown debug draw message");
                    break;
                }
                }
            }
        }
Пример #6
0
        public override bool DebugDraw()
        {            /*
                      * int i = MyWayPointGraph.GetConnectedComponentId(this);
                      * var vertexColor = HsvToRgb((0.36f + i * 0.618034f) % 1.0f, 0.8f, 0.75f);
                      *
                      * DrawWaypointVertex(WorldMatrix.Translation, vertexColor);  // draw only edges for generated waypoints
                      *
                      *
                      * // draw edges
                      * foreach (var neighbor in Neighbors)
                      * {
                      * //DrawWaypointEdge(wp.WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Red, Color.Green);  // selected path: red-green edges
                      *
                      * if (neighbor.WorldMatrix.Translation != WorldMatrix.Translation)
                      * {
                      * Vector3 direction = neighbor.WorldMatrix.Translation - WorldMatrix.Translation;
                      * float lineLength = direction.Length();
                      * direction.Normalize();
                      * MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, Color.Yellow.ToVector4(), WorldMatrix.Translation, direction, lineLength, 0.25f);
                      * }
                      *
                      * }
                      */
            if (((MyHud.ShowDebugWaypoints) || (MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive())) && (MyFakes.ENABLE_GENERATED_WAYPOINTS_IN_EDITOR || MyHud.ShowDebugGeneratedWaypoints || Save))
            {
                // color by connected components
                int i           = MyWayPointGraph.GetConnectedComponentId(this);
                var vertexColor = HsvToRgb((0.36f + i * 0.618034f) % 1.0f, 0.8f, 0.75f);

                if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.WayPoints.Contains(this))
                {
                    vertexColor = Color.Orange.ToVector3();  // selected path: orange vertices
                }

                if (IsSecret)
                {
                    vertexColor *= 0.25f;
                }

                // draw vertices
                if (MyEditorGizmo.SelectedEntities.Contains(this))
                {
                    DrawWaypointVertex(WorldMatrix.Translation, vertexColor + (IsSecret ? 1 : 3) * GetHighlightColor());
                    var name = new StringBuilder();
                    if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.WayPoints.Contains(this))
                    {
                        name.Append(MyWayPointGraph.SelectedPath.Name).Append(": ").Append(MyWayPointGraph.SelectedPath.WayPoints.IndexOf(this) + 1);
                    }
                    else
                    {
                        name.Append(MyWayPoint.FilterWayPoints(MyEditorGizmo.SelectedEntities).IndexOf(this) + 1);
                    }
                    MyDebugDraw.DrawText(WorldMatrix.Translation, name, Color.White, 1);
                }
                else
                {
                    if (Save)
                    {
                        DrawWaypointVertex(WorldMatrix.Translation, vertexColor);  // for generated waypoints, draw only edges
                    }
                }

                // draw edges
                if (Save || MyHud.ShowDebugGeneratedWaypoints)
                {
                    using (MyWayPoint.NeighborsLock.AcquireSharedUsing())
                    {
                        foreach (var neighbor in Neighbors)
                        {
                            if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.ContainsEdge(this, neighbor))
                            {
                                DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Yellow, Color.White);  // on selected path: yellow-white
                                continue;
                            }

                            if (neighbor.Save || MyHud.ShowDebugGeneratedWaypoints)
                            {
                                using (MyWayPoint.BlockedEdgesLock.AcquireSharedUsing())
                                {
                                    // blocked for player (by a locked indestructible door: white-gray)
                                    if (BlockedEdgesForPlayer.Contains(Tuple.Create(this, neighbor)) || BlockedEdgesForPlayer.Contains(Tuple.Create(neighbor, this)))
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.White, Color.Gray);
                                        continue;
                                    }

                                    // blocked for bots by a locked door: black-gray
                                    if (BlockedEdgesForBots.Contains(Tuple.Create(this, neighbor)) || BlockedEdgesForBots.Contains(Tuple.Create(neighbor, this)))
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Black, Color.Gray);
                                        continue;
                                    }
                                }

                                // obstructed: violet-white
                                if (MyHud.ShowDebugWaypointsCollisions && Position != neighbor.Position)
                                {
                                    var line = new MyLine(Position, neighbor.Position, true);
                                    if (MyEntities.GetAnyIntersectionWithLine(ref line, null, null, true, true, true, false) != null)
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Violet, Color.White);
                                        continue;
                                    }
                                }

                                // normal-normal: red-green
                                // generated-normal: orange-green (normally invisible)
                                // generated-generated: yellow-green (normally invisible)
                                bool generated      = !(Save && neighbor.Save);
                                bool fullyGenerated = !Save && !neighbor.Save;
                                DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, generated ? fullyGenerated ? Color.Yellow : Color.Orange : Color.Red, Color.Green);
                                continue;
                            }
                        }
                    }
                }
            }
            return(base.DebugDraw());
        }
Пример #7
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);
                }
            }
        }
Пример #8
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;
            }
        }
Пример #9
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);
        }
Пример #10
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;
            }
        }