make Toasts a list & implement FPS counter as a toast
GitOrigin-RevId: bae35697a0329f7d5c1c45cdbc13c3be500b8c73
This commit is contained in:
parent
bee17a99af
commit
34e7ab3ee1
@ -27,13 +27,16 @@ namespace SemiColinGames {
|
||||
}
|
||||
|
||||
public static bool Enabled;
|
||||
// This is a LinkedList instead of a List because SetFpsText() adds to its front.
|
||||
static LinkedList<string> toasts = new LinkedList<string>();
|
||||
static List<DebugRect> rects = new List<DebugRect>();
|
||||
static List<DebugLine> lines = new List<DebugLine>();
|
||||
static Texture2D whiteTexture;
|
||||
static string toast = null;
|
||||
|
||||
public static void Toast(string s) {
|
||||
toast = s;
|
||||
static Texture2D whiteTexture;
|
||||
|
||||
public static void Initialize(GraphicsDevice graphics) {
|
||||
whiteTexture = new Texture2D(graphics, 1, 1);
|
||||
whiteTexture.SetData(new Color[] { Color.White });
|
||||
}
|
||||
|
||||
public static void WriteLine(string s) {
|
||||
@ -44,16 +47,21 @@ namespace SemiColinGames {
|
||||
System.Diagnostics.Debug.WriteLine(s, args);
|
||||
}
|
||||
|
||||
public static void Initialize(GraphicsDevice graphics) {
|
||||
whiteTexture = new Texture2D(graphics, 1, 1);
|
||||
whiteTexture.SetData(new Color[] { Color.White });
|
||||
}
|
||||
|
||||
public static void Clear() {
|
||||
toasts.Clear();
|
||||
rects.Clear();
|
||||
lines.Clear();
|
||||
}
|
||||
|
||||
public static void AddToast(string s) {
|
||||
toasts.AddLast(s);
|
||||
}
|
||||
|
||||
// FPS text is always displayed as the first toast (if set).
|
||||
public static void SetFpsText(string s) {
|
||||
toasts.AddFirst(s);
|
||||
}
|
||||
|
||||
public static void AddRect(Rectangle rect, Color color) {
|
||||
rects.Add(new DebugRect(rect, color));
|
||||
}
|
||||
@ -62,12 +70,12 @@ namespace SemiColinGames {
|
||||
lines.Add(new DebugLine(start, end, color));
|
||||
}
|
||||
|
||||
public static void DrawToast(SpriteBatch spriteBatch, SpriteFont font) {
|
||||
if (toast == null) {
|
||||
return;
|
||||
public static void DrawToasts(SpriteBatch spriteBatch, SpriteFont font) {
|
||||
int y = 10;
|
||||
foreach (var toast in toasts) {
|
||||
spriteBatch.DrawString(font, toast, new Vector2(10, y), Color.Teal);
|
||||
y += 30;
|
||||
}
|
||||
spriteBatch.DrawString(font, toast, new Vector2(10, 40), Color.Teal);
|
||||
toast = null;
|
||||
}
|
||||
|
||||
public static void Draw(SpriteBatch spriteBatch, Camera camera) {
|
||||
|
@ -93,6 +93,9 @@ namespace SemiColinGames {
|
||||
// We need to update the FPS counter in Draw() since Update() might get called more
|
||||
// frequently, especially when gameTime.IsRunningSlowly.
|
||||
fpsCounter.Update();
|
||||
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
|
||||
$"{fpsCounter.Fps} FPS";
|
||||
Debug.SetFpsText(fpsText);
|
||||
|
||||
// Draw scene to RenderTarget.
|
||||
GraphicsDevice.SetRenderTarget(renderTarget);
|
||||
@ -131,10 +134,7 @@ namespace SemiColinGames {
|
||||
spriteBatch.Draw(renderTarget, drawRect, Color.White);
|
||||
|
||||
if (Debug.Enabled) {
|
||||
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
|
||||
$"{fpsCounter.Fps} FPS";
|
||||
spriteBatch.DrawString(font, fpsText, new Vector2(10, 10), Color.Teal);
|
||||
Debug.DrawToast(spriteBatch, font);
|
||||
Debug.DrawToasts(spriteBatch, font);
|
||||
}
|
||||
|
||||
spriteBatch.End();
|
||||
|
Loading…
Reference in New Issue
Block a user