Memory leak fix. Start of debug console

This commit is contained in:
Matt Thorson 2020-06-15 23:13:29 -07:00
parent f1285179cd
commit f325ed2598
5 changed files with 59 additions and 13 deletions

View File

@ -5,7 +5,7 @@ namespace Strawberry
{ {
public abstract class Asset public abstract class Asset
{ {
public readonly String Path; public readonly String Path ~ delete _;
protected this(String path) protected this(String path)
{ {

View File

@ -25,7 +25,6 @@ namespace Strawberry
return fonts[size]; return fonts[size];
else else
{ {
Calc.Log(Path);
let f = SDLTTF.OpenFont(Path, size); let f = SDLTTF.OpenFont(Path, size);
fonts[size] = f; fonts[size] = f;
return f; return f;

Binary file not shown.

View File

@ -20,7 +20,6 @@ namespace Strawberry
public readonly int Width; public readonly int Width;
public readonly int Height; public readonly int Height;
public readonly int WindowScale; public readonly int WindowScale;
public readonly String ContentRoot;
private Scene scene; private Scene scene;
private Scene switchToScene; private Scene switchToScene;
@ -49,12 +48,6 @@ namespace Strawberry
WindowScale = windowScale; WindowScale = windowScale;
screenRect = SDL.Rect(0, 0, width * windowScale, height * windowScale); screenRect = SDL.Rect(0, 0, width * windowScale, height * windowScale);
#if DEBUG
ContentRoot = "../../../src/Content/";
#else
ContentRoot = "Content/";
#endif
String exePath = scope .(); String exePath = scope .();
Environment.GetExecutableFilePath(exePath); Environment.GetExecutableFilePath(exePath);
String exeDir = scope .(); String exeDir = scope .();
@ -85,6 +78,7 @@ namespace Strawberry
BuildTypeLists(); BuildTypeLists();
Assets.LoadAll(); Assets.LoadAll();
Strawberry.Console.Init();
} }
public ~this() public ~this()
@ -107,6 +101,7 @@ namespace Strawberry
Assets.DisposeAll(); Assets.DisposeAll();
DisposeTypeLists(); DisposeTypeLists();
Input.[Friend]Dispose(); Input.[Friend]Dispose();
Strawberry.Console.Dispose();
Game = null; Game = null;
} }

View File

@ -1,18 +1,70 @@
using System;
namespace Strawberry namespace Strawberry
{ {
static public class Console 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() static public void Update()
{
if (enabled)
{ {
if (Input.KeyPressed(.Grave)) if (Input.KeyPressed(.Grave))
Enabled = !Enabled; Open = !Open;
if (Open)
{
}
}
} }
static public void Draw() 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);
} }
} }
} }