Replace debug.debug() with a dummy function

This commit is contained in:
Alessandro Proto 2023-05-19 08:17:07 +02:00
parent efe510d0da
commit b44f943456
2 changed files with 40 additions and 24 deletions

View file

@ -41,7 +41,6 @@ public enum EngineMode
Free Free
} }
public class Capy64 : Game, IGame public class Capy64 : Game, IGame
{ {
public const string Version = "1.0.0-beta"; public const string Version = "1.0.0-beta";
@ -59,17 +58,19 @@ public class Capy64 : Game, IGame
} }
public static string AppDataPath public static string AppDataPath {
{ get {
get
{
string baseDir = string baseDir =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create) : ?
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create)
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create) : : RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create) : Environment.SpecialFolderOption.Create)
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolderOption.Create)
:
"./"; "./";
return Path.Combine(baseDir, "Capy64"); return Path.Combine(baseDir, "Capy64");
@ -92,13 +93,14 @@ public class Capy64 : Game, IGame
public int TickRate => tickrate; public int TickRate => tickrate;
public Color BorderColor { get; set; } = Color.Black; public Color BorderColor { get; set; } = Color.Black;
public Borders Borders = new()
{ public Borders Borders = new() {
Top = 0, Top = 0,
Bottom = 0, Bottom = 0,
Left = 0, Left = 0,
Right = 0, Right = 0,
}; };
public SpriteBatch SpriteBatch; public SpriteBatch SpriteBatch;
@ -147,6 +149,7 @@ public class Capy64 : Game, IGame
Window.AllowUserResizing = true; Window.AllowUserResizing = true;
break; break;
} }
UpdateSize(true); UpdateSize(true);
} }
@ -199,14 +202,12 @@ public class Capy64 : Game, IGame
ResetBorder(); ResetBorder();
UpdateSize(); UpdateSize();
} }
} }
private void ResetBorder() private void ResetBorder()
{ {
var size = (int)(Scale * DefaultParameters.BorderMultiplier); var size = (int)(Scale * DefaultParameters.BorderMultiplier);
Borders = new Borders Borders = new Borders {
{
Top = size, Top = size,
Bottom = size, Bottom = size,
Left = size, Left = size,
@ -256,6 +257,7 @@ public class Capy64 : Game, IGame
var instance = (IComponent)ActivatorUtilities.CreateInstance(_serviceProvider, type)!; var instance = (IComponent)ActivatorUtilities.CreateInstance(_serviceProvider, type)!;
plugins.Add(instance); plugins.Add(instance);
} }
return plugins; return plugins;
} }
@ -272,8 +274,7 @@ public class Capy64 : Game, IGame
// Register user input // Register user input
_inputManager.Update(IsActive); _inputManager.Update(IsActive);
EventEmitter.RaiseTick(new() EventEmitter.RaiseTick(new() {
{
GameTime = gameTime, GameTime = gameTime,
TotalTicks = _totalTicks, TotalTicks = _totalTicks,
IsActiveTick = (int)_totalTicks % everyTick == 0, IsActiveTick = (int)_totalTicks % everyTick == 0,
@ -292,12 +293,13 @@ public class Capy64 : Game, IGame
GraphicsDevice.Clear(BorderColor); GraphicsDevice.Clear(BorderColor);
SpriteBatch.DrawRectangle(renderTarget.Bounds.Location.ToVector2() + new Vector2(Borders.Left, Borders.Top), SpriteBatch.DrawRectangle(renderTarget.Bounds.Location.ToVector2() + new Vector2(Borders.Left, Borders.Top),
new Size2(renderTarget.Bounds.Width * Scale, renderTarget.Bounds.Height * Scale), Color.Black, Math.Min(renderTarget.Bounds.Width, renderTarget.Bounds.Height), 0); new Size2(renderTarget.Bounds.Width * Scale, renderTarget.Bounds.Height * Scale), Color.Black,
Math.Min(renderTarget.Bounds.Width, renderTarget.Bounds.Height), 0);
SpriteBatch.Draw(renderTarget, new(Borders.Left, Borders.Top), null, Color.White, 0f, Vector2.Zero, Scale, SpriteEffects.None, 0); SpriteBatch.Draw(renderTarget, new(Borders.Left, Borders.Top), null, Color.White, 0f, Vector2.Zero, Scale,
SpriteEffects.None, 0);
EventEmitter.RaiseOverlay(new() EventEmitter.RaiseOverlay(new() {
{
GameTime = gameTime, GameTime = gameTime,
TotalTicks = _totalTicks, TotalTicks = _totalTicks,
}); });

View file

@ -121,6 +121,20 @@ internal class Sandbox
L.SetTable(-3); L.SetTable(-3);
L.Pop(1); L.Pop(1);
// Replace debug.debug with a dummy function to avoid stalling the program
L.GetGlobal("debug");
L.PushString("debug");
L.PushCFunction(L_Dummy);
L.SetTable(-3);
L.Pop(1);
}
internal static int L_Dummy(IntPtr state)
{
return 0;
} }
internal static int L_Searcher(IntPtr state) internal static int L_Searcher(IntPtr state)