From f325ed2598adaccb8eae4d24d36de5b51e584d65 Mon Sep 17 00:00:00 2001 From: Matt Thorson Date: Mon, 15 Jun 2020 23:13:29 -0700 Subject: [PATCH] Memory leak fix. Start of debug console --- src/Assets/Asset.bf | 2 +- src/Assets/Font.bf | 1 - src/Content/strawberry-seeds.ttf | Bin 0 -> 14448 bytes src/Core/Game.bf | 9 ++--- src/Static/Console.bf | 60 ++++++++++++++++++++++++++++--- 5 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 src/Content/strawberry-seeds.ttf diff --git a/src/Assets/Asset.bf b/src/Assets/Asset.bf index 51156fb..8e28172 100644 --- a/src/Assets/Asset.bf +++ b/src/Assets/Asset.bf @@ -5,7 +5,7 @@ namespace Strawberry { public abstract class Asset { - public readonly String Path; + public readonly String Path ~ delete _; protected this(String path) { diff --git a/src/Assets/Font.bf b/src/Assets/Font.bf index ba2a395..55268df 100644 --- a/src/Assets/Font.bf +++ b/src/Assets/Font.bf @@ -25,7 +25,6 @@ namespace Strawberry return fonts[size]; else { - Calc.Log(Path); let f = SDLTTF.OpenFont(Path, size); fonts[size] = f; return f; diff --git a/src/Content/strawberry-seeds.ttf b/src/Content/strawberry-seeds.ttf new file mode 100644 index 0000000000000000000000000000000000000000..c94216ba965ed80c452a3f83daba6911f3e2d179 GIT binary patch literal 14448 zcmd^GU2I%e5uW|Ao&Pk1Hc9J{+cs1nVy_d2Izg>O8rOtYg*0wW3aRMYUfWy8UbDN7 zV}wwVct8TtiYE{h@xTKTMMAuQ+Vb;)Kmq{*B#_{t5i>xr#vME8G8SC>BQ0xbGM4*PJ#Nw)IxdbzGu!pCsG&^ z$;<5J)tR$jA9+xu_opIv9h|F_r*9jY{2q8;M7etogkAaKEc$;#IXbt{ygK#lW9a5S z&oW=BFRp$2b&MbTBko_lT$?IO-;W@x2l8`YS}0##k|ntd{ezekEtVH5PaoL%6_LT; zi)?Q!)f!Ftxy*>1I?r(-c9dHyqt`#Y_nyCtYy&~$cYAid6t~x<7k{|6!356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 +20,6 @@ namespace Strawberry public readonly int Width; public readonly int Height; public readonly int WindowScale; - public readonly String ContentRoot; private Scene scene; private Scene switchToScene; @@ -49,12 +48,6 @@ namespace Strawberry WindowScale = windowScale; screenRect = SDL.Rect(0, 0, width * windowScale, height * windowScale); -#if DEBUG - ContentRoot = "../../../src/Content/"; -#else - ContentRoot = "Content/"; -#endif - String exePath = scope .(); Environment.GetExecutableFilePath(exePath); String exeDir = scope .(); @@ -85,6 +78,7 @@ namespace Strawberry BuildTypeLists(); Assets.LoadAll(); + Strawberry.Console.Init(); } public ~this() @@ -107,6 +101,7 @@ namespace Strawberry Assets.DisposeAll(); DisposeTypeLists(); Input.[Friend]Dispose(); + Strawberry.Console.Dispose(); Game = null; } diff --git a/src/Static/Console.bf b/src/Static/Console.bf index 4fb2448..b0724c8 100644 --- a/src/Static/Console.bf +++ b/src/Static/Console.bf @@ -1,18 +1,70 @@ +using System; + namespace Strawberry { static public class Console { - static public bool Enabled; + static public bool Open; + + static private bool enabled; + static private SDL2.SDLTTF.Font* font; + + static public void Init() + { + enabled = true; + font = SDL2.SDLTTF.OpenFont("../../../../Strawberry/src/Content/strawberry-seeds.ttf", 8); + } + + static public void Dispose() + { + SDL2.SDLTTF.CloseFont(font); + } + + static public bool Enabled + { + get => enabled; + set + { + enabled = value; + if (!enabled) + Open = false; + } + } static public void Update() { - if (Input.KeyPressed(.Grave)) - Enabled = !Enabled; + if (enabled) + { + if (Input.KeyPressed(.Grave)) + Open = !Open; + + if (Open) + { + + } + } } static public void Draw() { - Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.4f); + if (enabled && Open) + { + Draw.Rect(0, 0, Game.Width, Game.Height, .Black * 0.5f); + + Text(">", 0, 0, .White); + if (Time.BetweenInterval(0.5f)) + Text("_", 0, 1, .White); + } } + + static private void Text(String str, int row, int col, Color color) + { + Point pos = .(4 + 6 * col, Game.Height - 10 - 10 * row); + if (row > 0) + pos.Y -= 4; + + Draw.Text(font, str, pos + .Down, .Black); + Draw.Text(font, str, pos, color); + } } }