|
@ -27,20 +27,16 @@ namespace SemiColinGames { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static bool Enabled = true; |
|
|
public static bool Enabled = true; |
|
|
// Lines in excess of MAX_LINES get dropped on the floor.
|
|
|
|
|
|
const int MAX_LINES = 1000; |
|
|
|
|
|
const int MAX_LINE_VERTICES = MAX_LINES * 2; |
|
|
|
|
|
// This is a LinkedList instead of a List because SetFpsText() adds to its front.
|
|
|
// This is a LinkedList instead of a List because SetFpsText() adds to its front.
|
|
|
static readonly LinkedList<string> toasts = new LinkedList<string>(); |
|
|
static readonly LinkedList<string> toasts = new LinkedList<string>(); |
|
|
static readonly List<DebugRect> rects = new List<DebugRect>(); |
|
|
|
|
|
|
|
|
// Lines in excess of MAX_LINES get dropped on the floor.
|
|
|
|
|
|
const int MAX_LINES = 2000; |
|
|
|
|
|
const int MAX_LINE_VERTICES = MAX_LINES * 2; |
|
|
static int lineIdx = 0; |
|
|
static int lineIdx = 0; |
|
|
static readonly VertexPositionColor[] lineVertices = new VertexPositionColor[MAX_LINE_VERTICES]; |
|
|
static readonly VertexPositionColor[] lineVertices = new VertexPositionColor[MAX_LINE_VERTICES]; |
|
|
static VertexBuffer vertexBuffer; |
|
|
static VertexBuffer vertexBuffer; |
|
|
|
|
|
|
|
|
static Texture2D whiteTexture; |
|
|
|
|
|
|
|
|
|
|
|
public static void Initialize(GraphicsDevice graphics, Texture2D white) { |
|
|
|
|
|
whiteTexture = white; |
|
|
|
|
|
|
|
|
public static void Initialize(GraphicsDevice graphics) { |
|
|
vertexBuffer = new VertexBuffer( |
|
|
vertexBuffer = new VertexBuffer( |
|
|
graphics, typeof(VertexPositionColor), MAX_LINE_VERTICES, BufferUsage.WriteOnly); |
|
|
graphics, typeof(VertexPositionColor), MAX_LINE_VERTICES, BufferUsage.WriteOnly); |
|
|
} |
|
|
} |
|
@ -56,7 +52,6 @@ namespace SemiColinGames { |
|
|
public static void Clear(bool paused) { |
|
|
public static void Clear(bool paused) { |
|
|
toasts.Clear(); |
|
|
toasts.Clear(); |
|
|
if (!paused) { |
|
|
if (!paused) { |
|
|
rects.Clear(); |
|
|
|
|
|
lineIdx = 0; |
|
|
lineIdx = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -71,7 +66,10 @@ namespace SemiColinGames { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void AddRect(Rectangle rect, Color color) { |
|
|
public static void AddRect(Rectangle rect, Color color) { |
|
|
rects.Add(new DebugRect(rect, color)); |
|
|
|
|
|
|
|
|
AddLine(rect.Left, rect.Top, rect.Right, rect.Top, color); |
|
|
|
|
|
AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom, color); |
|
|
|
|
|
AddLine(rect.Right, rect.Bottom, rect.Left, rect.Bottom, color); |
|
|
|
|
|
AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top, color); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void AddRect(AABB box, Color color) { |
|
|
public static void AddRect(AABB box, Color color) { |
|
@ -109,31 +107,14 @@ namespace SemiColinGames { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void Draw( |
|
|
|
|
|
SpriteBatch spriteBatch, GraphicsDevice graphics, BasicEffect lightingEffect) { |
|
|
|
|
|
|
|
|
public static void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) { |
|
|
if (!Enabled) { |
|
|
if (!Enabled) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
if (lineIdx == 0) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Draw rects.
|
|
|
|
|
|
foreach (var debugRect in rects) { |
|
|
|
|
|
var rect = debugRect.Rect; |
|
|
|
|
|
var color = debugRect.Color; |
|
|
|
|
|
// top side
|
|
|
|
|
|
spriteBatch.Draw( |
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color); |
|
|
|
|
|
// bottom side
|
|
|
|
|
|
spriteBatch.Draw( |
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color); |
|
|
|
|
|
// left side
|
|
|
|
|
|
spriteBatch.Draw( |
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color); |
|
|
|
|
|
// right side
|
|
|
|
|
|
spriteBatch.Draw( |
|
|
|
|
|
whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Draw lines.
|
|
|
|
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
graphics.SetVertexBuffer(vertexBuffer); |
|
|
vertexBuffer.SetData(lineVertices); |
|
|
vertexBuffer.SetData(lineVertices); |
|
|
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) { |
|
|
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) { |
|
|