Going to bed but i wanna show off my cool debugging system

This commit is contained in:
2026-02-01 23:02:53 -05:00
parent 6370a70e77
commit 6032a04ad9
20 changed files with 303 additions and 47 deletions

View File

@@ -0,0 +1,10 @@
namespace Awperative.Kernel.Communication.Config;
//TEMPORARY LIST OF VARIABLES, CONFIG DOESNT EXIST YET SO IM MAKING A VARIABLE LIST TO SEE WHAT I NEED TO REPLACE
public static class Config
{
public static string logFileName = "log";
}

View File

@@ -0,0 +1 @@
todo: make a yaml file for the kernel config and this can find it outside of the kernel

View File

@@ -0,0 +1,5 @@
Awperative debugger writes errors to file while staying within runtime.
Searches for a file with any specifiable name in config. that must end in .awlf
stands for awperative logging format.

View File

@@ -0,0 +1,37 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Awperative.Kernel.Communication.Config;
namespace Awperative;
public static partial class Debugger
{
/// <summary>
/// True path of the log file Awperative dumps to.
/// </summary>
public static string LogFilePath { get; private set; }
/// <summary>
/// Sets up the Awperative debugger and finds the log file.
/// </summary>
internal static void Initiate() {
string directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if(directoryPath == null) throw new Exception("Failed to get directory path!");
if(!Directory.GetFiles(directoryPath).Contains(Config.logFileName + ".awlf")) throw new Exception("Failed to find log file!");
LogFilePath = Path.Join(directoryPath, Config.logFileName + ".awlf");
}
}

View File

@@ -0,0 +1,68 @@
using System.Diagnostics;
using System.IO;
namespace Awperative;
public static partial class Debugger
{
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
public static void DebugState(string __message) => DebugGeneric(__message, "STA");
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
public static void DebugValue(string __message) => DebugGeneric(__message, "VAL");
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
public static void DebugLog(string __message) => DebugGeneric(__message, "LOG");
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
public static void DebugWarning(string __message) => DebugGeneric(__message, "WAR");
/// <summary>
/// Writes the current message to the log file.
/// </summary>
/// <param name="__message"> Message to debug</param>
public static void DebugError(string __message) => DebugGeneric(__message, "ERR");
/// <summary>
/// Writes the current message to the log file. With any given call sign.
/// </summary>
/// <param name="__message"> Message to debug</param>
/// <param name="__callSign"> Message identifier</param>
public static void DebugGeneric(string __message, string __callSign) {
File.AppendAllText(LogFilePath, "\n\n" + __callSign + "- \"" + __message + "\"\n STK-" + new StackTrace());
}
}

View File

@@ -1,29 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Awperative;
public sealed partial class Body
public sealed partial class Body
{
public readonly Scene scene;
public readonly Transform transform = new Transform();
public readonly List<string> tags = [];
public readonly List<Component> components = [];
/// <summary>
/// Current scene the body exists in
/// </summary>
public Scene Scene { get; internal set; }
/// <summary>
/// All components attached to the body
/// </summary>
public List<Component> Components => _components.ToList();
internal HashSet<Component> _components { get; private set; } = [];
/// <summary>
/// All tags attached to the body
/// </summary>
public List<string> Tags => _tags.ToList();
internal HashSet<string> _tags { get; private set; }= [];
public Body(Scene __scene) {
scene = __scene;
/// <summary>
/// Position of the body
/// </summary>
public Transform transform { get; internal set; } = new();
//Prevents outside construction
internal Body() {}
/// <summary>
/// Creates a body in the given scene
/// </summary>
/// <param name="__scene"></param>
internal Body(Scene __scene) {
Scene = __scene;
}
public Body(Scene __scene, Transform __transform) {
scene = __scene;
/// <summary>
/// Creates a body with a scene and transform
/// </summary>
/// <param name="__scene"></param>
/// <param name="__transform"></param>
internal Body(Scene __scene, Transform __transform) {
Scene = __scene;
transform = __transform;
}
//todo: make internal
}

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Microsoft.Xna.Framework;
@@ -6,13 +7,13 @@ namespace Awperative;
public sealed partial class Body
{
public void Unload() { foreach (Component component in components) component.Unload(); }
public void Unload() { foreach (Component component in components.ToList()) component.Unload(); }
public void Load() { foreach (Component component in components) { component.Load(); } }
public void Load() { foreach (Component component in components.ToList()) { component.Load(); } }
public void Update(GameTime __gameTime) { foreach (Component component in components) { component.Update(__gameTime); } }
public void Draw(GameTime __gameTime) { foreach (Component component in components) { component.Draw(__gameTime); } }
public void Update(GameTime __gameTime) { foreach (Component component in components.ToList()) { component.Update(__gameTime); } }
public void Draw(GameTime __gameTime) { foreach (Component component in components.ToList()) { component.Draw(__gameTime); } }
public void Destroy() { foreach(Component component in components) component.Destroy(); }
public void Create() { foreach (Component component in components) component.Create(); }
public void Destroy() { foreach(Component component in components.ToList()) component.Destroy(); }
public void Create() { foreach (Component component in components.ToList()) component.Create(); }
}

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Microsoft.Xna.Framework;
@@ -7,22 +8,22 @@ public sealed partial class Scene
{
public void Unload() {
foreach (Behavior behavior in behaviors) behavior.Unload();
foreach (Body body in bodies) body.Unload();
foreach (Behavior behavior in behaviors.ToList()) behavior.Unload();
foreach (Body body in bodies.ToList()) body.Unload();
}
public void Load() {
foreach (Behavior behavior in behaviors) { behavior.Load(); }
foreach (Body body in bodies) { body.Load(); }
foreach (Behavior behavior in behaviors.ToList()) { behavior.Load(); }
foreach (Body body in bodies.ToList()) { body.Load(); }
}
public void Update(GameTime __gameTime) {
foreach (Behavior behavior in behaviors) { behavior.Update(__gameTime); }
foreach (Body body in bodies) { body.Update(__gameTime); }
foreach (Behavior behavior in behaviors.ToList()) { behavior.Update(__gameTime); }
foreach (Body body in bodies.ToList()) { body.Update(__gameTime); }
}
public void Draw(GameTime __gameTime) {
foreach (Behavior behavior in behaviors) { behavior.Draw(__gameTime); }
foreach (Body body in bodies) { body.Draw(__gameTime); }
foreach (Behavior behavior in behaviors.ToList()) { behavior.Draw(__gameTime); }
foreach (Body body in bodies.ToList()) { body.Draw(__gameTime); }
}
}

View File

@@ -3,6 +3,7 @@ namespace Awperative;
/// <summary>
/// Awperative hooks are the source of entry for scripts using Awperative. Create a hook and send into Start() to be recognized by the engine.
/// </summary>
/// <author> Avery Norris </author>
public interface AwperativeHook
{
/// <summary>
@@ -10,8 +11,15 @@ public interface AwperativeHook
/// </summary>
public void Load() {}
/// <summary>
/// Called when the program closes.
/// </summary>
public void Unload() {}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -8,6 +9,7 @@ namespace Awperative;
/// <summary>
/// Base class of Awperative. Carries events from MonoGame into scenes and hooks.
/// </summary>
/// <author> Avery Norris </author>
public sealed class Base : Game
{
@@ -19,6 +21,10 @@ public sealed class Base : Game
Content.RootDirectory = "Content";
}
/// <summary>
/// Initialize() is called when the program starts. Goes before LoadContent(). And prepares the kernel for use.
/// </summary>
@@ -29,42 +35,60 @@ public sealed class Base : Game
base.Initialize();
}
/// <summary>
/// LoadContent() is called when the program starts; right after Initialize(). Override Load() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> It is recommended to load content during LoadContent()</remarks>
protected override void LoadContent() {
foreach (AwperativeHook hook in Awperative.EventHooks)
hook.Load();
foreach(Scene scene in Awperative.LoadedScenes)
scene.Load();
foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Load();
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Load();
}
/// <summary>
/// Update() is called every frame; before Draw(). Override Update() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Update(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes) scene.Update(__gameTime);
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Update(__gameTime);
base.Update(__gameTime);
}
/// <summary>
/// Draw() is called every frame; after Update(). Override Draw() in scripting tools to call from this event.
/// </summary>
/// <remarks> Hooks are unable to receive both Update() and Draw()</remarks>
protected override void Draw(GameTime __gameTime) {
foreach(Scene scene in Awperative.LoadedScenes) scene.Draw(__gameTime);
foreach(Scene scene in Awperative.LoadedScenes.ToList()) scene.Draw(__gameTime);
base.Draw(__gameTime);
}
/// <summary>
/// EndRun() is called if the program closes. Override Terminate() in scripting tools or use hooks to call from this event.
/// </summary>
/// <remarks> This event may not trigger if the program is force closed.</remarks>
protected override void EndRun() {
foreach (AwperativeHook hook in Awperative.EventHooks) hook.Unload();
foreach (Scene scene in Awperative.LoadedScenes) scene.Unload();
foreach (AwperativeHook hook in Awperative.EventHooks.ToList()) hook.Unload();
foreach (Scene scene in Awperative.LoadedScenes.ToList()) scene.Unload();
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
@@ -9,29 +10,75 @@ namespace Awperative;
/// <summary>
/// Initiating class of Awperative. Call Start() to start the kernel.
/// </summary>
/// <author> Avery Norris </author>
public static class Awperative
{
//Inherits MonoGame and carries events.
public static Base Base;
public static List<Scene> LoadedScenes = [];
//Handles, graphic Settings, drawing, and loading content respectively.
/// <summary>
/// Bottom class of Awperative. Contains the MonoGame instance.
/// </summary>
public static Base Base { get; internal set; }
/// <summary>
/// Handles graphics settings through MonoGame.
/// </summary>
public static GraphicsDeviceManager GraphicsDeviceManager { get; internal set; }
public static SpriteBatch SpriteBatch { get; internal set; }
public static ContentManager ContentManager { get; internal set; }
//Entry points for code
internal static List<AwperativeHook> EventHooks { get; private set; }
/// <summary>
/// Handles drawing sprites to the screen through MonoGame.
/// </summary>
public static SpriteBatch SpriteBatch { get; internal set; }
/// <summary>
/// Handles loading content through MonoGame.
/// </summary>
public static ContentManager ContentManager { get; internal set; }
/// <summary>
/// List of all scenes currently loaded in the kernel.
/// </summary>
public static List<Scene> LoadedScenes => _loadedScenes.ToList();
internal static HashSet<Scene> _loadedScenes { get; private set; }= [];
/// <summary>
/// List of all event hooks currently loaded in the kernel.
/// </summary>
public static List<AwperativeHook> EventHooks => _eventHooks.ToList();
internal static HashSet<AwperativeHook> _eventHooks { get; private set; } = [];
/// <summary>
/// Start() begins the game; and begins communication with all event hooks.
/// </summary>
/// <param name="__hooks"> List of all event hooks you wish to use. </param>
/// <remarks> You cannot add new hooks later; so make sure to register all of them in the Start() method.</remarks>
public static void Start(List<AwperativeHook> __hooks) {
EventHooks = __hooks;
_eventHooks = new HashSet<AwperativeHook>(__hooks);
Base = new Base();
Base.Run();
}
}

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Awperative")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9f744fcd5f47a08f81587169de34e57d3562e7ba")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6370a70e77e58afd49c5270eea3656796c8a8b60")]
[assembly: System.Reflection.AssemblyProductAttribute("Awperative")]
[assembly: System.Reflection.AssemblyTitleAttribute("Awperative")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
7a962b2fea56a4a2f915d2e475c1e494ec261a6791d7faf4c957d39c460317a6
65f076e2a35d39f7816008dc38aa7c8c9fe617c292f8f16923e08f8a886186cf

View File

@@ -1 +1 @@
be1a95e7069d34b03cfebe4fe9e9ce02a90bff6923670e2ee1bce3618e098560
f552bda458f25e93b640f2f86a474c139ae16e84a42a47639427c638e2566334