From 63a2645814a57391a68fd959e3f677bd55b5bbcc Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 18 Mar 2020 11:13:06 -0400 Subject: [PATCH] Timer: suppress printouts when not in DEBUG mode Debug: add "using System.Diagnostics" --- Shared/Debug.cs | 29 +++++++++++++++-------------- Shared/Timer.cs | 1 + 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Shared/Debug.cs b/Shared/Debug.cs index 56b5142..3237750 100644 --- a/Shared/Debug.cs +++ b/Shared/Debug.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System.Collections.Generic; +using System.Diagnostics; namespace SemiColinGames { public static class Debug { @@ -37,7 +38,7 @@ namespace SemiColinGames { static VertexPositionColor[] lineVertices; static VertexBuffer vertexBuffer; - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void Initialize(GraphicsDevice graphics) { lineVertices = new VertexPositionColor[MAX_LINE_VERTICES]; vertexBuffer?.Dispose(); @@ -45,17 +46,17 @@ namespace SemiColinGames { graphics, typeof(VertexPositionColor), MAX_LINE_VERTICES, BufferUsage.WriteOnly); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void WriteLine(string s) { System.Diagnostics.Debug.WriteLine(s); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void WriteLine(string s, params object[] args) { System.Diagnostics.Debug.WriteLine(s, args); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void Clear(bool paused) { toasts.Clear(); if (!paused) { @@ -63,18 +64,18 @@ namespace SemiColinGames { } } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddToast(string s) { toasts.AddLast(s); } // FPS text is always displayed as the first toast (if set). - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void SetFpsText(string s) { toasts.AddFirst(s); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddRect(Rectangle rect, Color color) { AddLine(rect.Left, rect.Top + 1, rect.Right, rect.Top + 1, color); AddLine(rect.Left + 1, rect.Top + 1, rect.Left + 1, rect.Bottom, color); @@ -82,7 +83,7 @@ namespace SemiColinGames { AddLine(rect.Left + 1, rect.Bottom, rect.Right, rect.Bottom, color); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddRect(AABB box, Color color) { Rectangle rect = new Rectangle( (int) (box.Position.X - box.HalfSize.X), (int) (box.Position.Y - box.HalfSize.Y), @@ -90,13 +91,13 @@ namespace SemiColinGames { AddRect(rect, color); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddPoint(Point p, Color color) { AddLine(p.X, p.Y - 2, p.X, p.Y + 1, color); AddLine(p.X - 2, p.Y, p.X + 1, p.Y, color); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddLine(int p1x, int p1y, int p2x, int p2y, Color color) { if (lineIdx >= MAX_LINE_VERTICES) { return; @@ -106,17 +107,17 @@ namespace SemiColinGames { lineIdx += 2; } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddLine(Point start, Point end, Color color) { AddLine(start.X, start.Y, end.X, end.Y, color); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void AddLine(Vector2 start, Vector2 end, Color color) { AddLine(start.ToPoint(), end.ToPoint(), color); } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void DrawToasts(SpriteBatch spriteBatch) { if (!Enabled) { return; @@ -132,7 +133,7 @@ namespace SemiColinGames { } } - [System.Diagnostics.Conditional("DEBUG")] + [Conditional("DEBUG")] public static void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) { if (!Enabled) { return; diff --git a/Shared/Timer.cs b/Shared/Timer.cs index 4c432c0..c024f06 100644 --- a/Shared/Timer.cs +++ b/Shared/Timer.cs @@ -29,6 +29,7 @@ namespace SemiColinGames { histogram[bucket]++; } + [Conditional("DEBUG")] public void DumpStats() { Debug.WriteLine(name + ".DumpStats():"); for (int i = 0; i < histogram.Length; i++) {