Skip to main content

Debug

Namespace: MonineEngine.Core

Helper class with a set of methods and properties to assist in debugging. Includes console logging, debug mode checking, and debug overlays/rendering.

public static class Debug

Inheritance ObjectDebug
Attributes NullableContextAttribute, NullableAttribute

Remarks:

Many elements of this class are either directly from, or inspired by Debug. Such elements have comments in source to communicate that.

Fields

DisplayFlags

The DebugDisplayFlags that define what the debug renderer should render.

public static DebugDisplayFlags DisplayFlags;

Properties

DebugMode

Gets if the currently running build is built with the Debug configuration.

public static bool DebugMode { get; private set; }

Property Value

Boolean

Remarks:

This will always be false until Engine is constructed.

Methods

Log(Object, String, String, Int32)

Logs a message to the console.

public static void Log(object message, string memberName, string path, int num)

Parameters

message Object
The message to log.

memberName String

path String

num Int32

LogOnce(String, Object, String, String, Int32)

Logs a message to the console once, then never again, even on repeat calls.

public static void LogOnce(string id, object message, string memberName, string path, int num)

Parameters

id String
The ID of this log. Used to track if it has been logged or not.

message Object
The message to log.

memberName String

path String

num Int32

LogIf(Boolean, Object, String, String, Int32)

Logs a message to the console if the given condition is true.

public static void LogIf(bool condition, object message, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, logs the message. If false, nothing is logged.

message Object
The message to log.

memberName String

path String

num Int32

Warning(Object, String, String, Int32)

Logs a warning to the console.

public static void Warning(object message, string memberName, string path, int num)

Parameters

message Object
The message to log, likely the reason for warning.

memberName String

path String

num Int32

WarningOnce(String, Object, String, String, Int32)

Logs a warning to the console once, then never again, even on repeat calls.

public static void WarningOnce(string id, object message, string memberName, string path, int num)

Parameters

id String
The ID of this log. Used to track if it has been logged or not.

message Object
The message to log, likely the reason for warning.

memberName String

path String

num Int32

WarningIf(Boolean, Object, String, String, Int32)

Logs a warning to the console if the given condition is true.

public static void WarningIf(bool condition, object message, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, logs the warning. If false, nothing is logged.

message Object
The message to log, likely the reason for warning.

memberName String

path String

num Int32

Error(String, String, String, String, Int32)

Logs an error to the console.

public static void Error(string message, string detailedMessage, string memberName, string path, int num)

Parameters

message String
The error to log. Usually the reason of the error.

detailedMessage String
An optional, more detailed variation of message.

memberName String

path String

num Int32

Remarks:

Does not throw the error on call, and only sends text to the console.

Error(Exception, String, String, Int32)

Logs an exception to the console. Does not throw the error on log.

public static void Error(Exception exception, string memberName, string path, int num)

Parameters

exception Exception
The exception associated with the error.

memberName String

path String

num Int32

Remarks:

This is most useful for logging exceptions worth tracking without throwing the exception.

ErrorOnce(String, String, String, String, String, Int32)

Logs an error to the console once, then never again, even on repeat calls.

public static void ErrorOnce(string id, string message, string detailedMessage, string memberName, string path, int num)

Parameters

id String
The ID of this log. Used to track if it has been logged or not.

message String
The error to log. Usually the reason of the error.

detailedMessage String
An optional, more detailed variation of message.

memberName String

path String

num Int32

Remarks:

Does not throw the error on call, and only sends text to the console.

ErrorOnce(String, Exception, String, String, Int32)

Logs an exception to the console once, then never again, even on repeat calls.

public static void ErrorOnce(string id, Exception exception, string memberName, string path, int num)

Parameters

id String
The ID of this log. Used to track if it has been logged or not.

exception Exception
The exception associated with the error.

memberName String

path String

num Int32

Remarks:

Does not throw the error on call, and only sends text to the console.

ErrorIf(Boolean, String, String, String, String, Int32)

Logs an error to the console if the given condition is true.

public static void ErrorIf(bool condition, string message, string detailedMessage, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, logs the warning. If false, nothing is logged.

message String
The error to log. Usually the reason of the error.

detailedMessage String
An optional, more detailed variation of message.

memberName String

path String

num Int32

Remarks:

Does not throw the error on call, and only sends text to the console.

ErrorIf(Boolean, Exception, String, String, Int32)

Logs an exception to the console if the given condition is true. Does not throw the error on log.

public static void ErrorIf(bool condition, Exception exception, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, logs the warning. If false, nothing is logged.

exception Exception
The exception associated with the error.

memberName String

path String

num Int32

Remarks:

This is most useful for logging exceptions worth tracking without throwing the exception.

ThrowError(String, String, String, String, Int32)

Logs and throws an error to the console.

public static void ThrowError(string message, string detailedMessage, string memberName, string path, int num)

Parameters

message String
The error to log. Usually the reason of the error.

detailedMessage String
An optional, more detailed variation of message.

memberName String

path String

num Int32

ThrowError(Exception, String, String, Int32)

Logs and throws an exception to the console.

public static void ThrowError(Exception exception, string memberName, string path, int num)

Parameters

exception Exception
The exception associated with the error.

memberName String

path String

num Int32

ThrowErrorIf(Boolean, String, String, String, String, Int32)

Logs and throws an error to the console if the given condition is true.

public static void ThrowErrorIf(bool condition, string message, string detailedMessage, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, logs the warning. If false, nothing is logged.

message String
The error to log. Usually the reason of the error.

detailedMessage String
An optional, more detailed variation of .

memberName String

path String

num Int32

ThrowErrorIf(Boolean, Exception, String, String, Int32)

Logs and throws an exception to the console if the given condition is true. Does not throw the error on log.

public static void ThrowErrorIf(bool condition, Exception exception, string memberName, string path, int num)

Parameters

condition Boolean
The condition to check. If true, throws the error. If false, nothing is logged.

exception Exception
The exception associated with the error.

memberName String

path String

num Int32

GetClassFromPath(String)

Isolates a file path and returns the final element alongside the folder containing it.

public static string GetClassFromPath(string path)

Parameters

path String
The path to the file to isolate.

Returns

String
The final section of the path, and the containing folder of it.

Remarks:

Used by console methods to find member locations in file paths.

EmptyLine()

Writes a new, empty line to the console.

public static void EmptyLine()

ClearConsole()

Clears the console.

public static void ClearConsole()

ResetSingleLogs()

Resets the list of logs that were only meant to be logged once. Not recommended to explicitly call this function.

public static void ResetSingleLogs()

Assert(Boolean, String, String)

Checks a condition, and if the condition is false, throws an error with the given message.

public static void Assert(bool condition, string message, string detailedMessage)

Parameters

condition Boolean
The condition to check. If the condition is false, an error is logged to the console. If true, no error is logged.

message String
The message to display if the condition is false.

detailedMessage String
An optional, more detailed variation of .

Remarks:

This will only run if the build configuration is "Debug".

AssertNotNull(Object, String, String)

Checks if the given object is null, and throws an error with the given message if it is null.

public static void AssertNotNull(object value, string message, string detailedMessage)

Parameters

value Object
The object to check.

message String
The message to display if the object is null.

detailedMessage String
An optional, more detailed variation of .

Remarks:

This will only run if the build configuration is "Debug".

AssertInRange(Single, Single, Single, String, String)

Checks if the given value is within the given range, and throws an error if it isn't within the range.

public static void AssertInRange(float value, float min, float max, string message, string detailedMessage)

Parameters

value Single
The value to check.

min Single
The minimum value of the range.

max Single
The maximum value of the range.

message String
The message to display if the value is not within range.

detailedMessage String
An optional, more detailed variation of .

Remarks:

This will only run if the build configuration is "Debug".

AssertType<T>(Object, String, String)

Checks if the given object has the same type as the given type, and throws an error if the types are different.

public static void AssertType<T>(object value, string message, string detailedMessage)

Type Parameters

T
The type to validate with the object.

Parameters

value Object
The object to check.

message String
The message to display if the object has a different type to the given type.

detailedMessage String
An optional, more detailed variation of .

Remarks:

This will only run if the build configuration is "Debug".

AssertPositive(Single, String, String)

Checks if the given value is positive, and throws an error if the value is negative.

public static void AssertPositive(float value, string message, string detailedMessage)

Parameters

value Single
The value to check.

message String
The message to display if the value is negative.

detailedMessage String
An optional, more detailed variation of .

Remarks:

This will only run if the build configuration is "Debug".

DrawLine(Vector2, Vector2, Color, Single, Single)

Draws a line to the screen with the given properties.

public static void DrawLine(Vector2 start, Vector2 end, Color color, float duration, float thickness)

Parameters

start Vector2
The start of the line in screen space.

end Vector2
The end of the line in screen space.

color Color
The colour of the line.

duration Single
How long the line lasts on screen in seconds. If 0, draws for 1 frame.

thickness Single
How thick the line is, in pixels.

DrawRect(Rectangle, Color, Single, Single)

Draws a rectangle to the screen with the given properties.

public static void DrawRect(Rectangle rect, Color color, float duration, float thickness)

Parameters

rect Rectangle
The rectangle position and scale. Position is in screen space.

color Color
The colour of the rectangle.

duration Single
How long the rectangle lasts on screen in seconds. If 0, draws for 1 frame.

thickness Single
How thick the rectangle is, in pixels.

DrawCircle(Vector2, Single, Color, Single, Int32, Single)

Draws a circle to the screen with the given properties.

public static void DrawCircle(Vector2 center, float radius, Color color, float duration, int segments, float thickness)

Parameters

center Vector2
The center position of the circle in screen space.

radius Single
The radius of the circle in pixels.

color Color
The colour of the circle.

duration Single
How long the circle lasts on screen in seconds. If 0, draws for 1 frame.

segments Int32
How many segments make up the circle. Higher values lead to smoother circles, but multiple circles with large segment counts may impact performance.

thickness Single
How thick the segments are, in pixels.

DrawOverlay(SpriteBatch, SpriteFont)

Draws all values watched by the debug overlay onto the top-left corner of the screen.

public static void DrawOverlay(SpriteBatch sb, SpriteFont font)

Parameters

sb SpriteBatch
The to use to render the overlay.

font SpriteFont
The to use when drawing the overlay.

Remarks:

Does not run if Debug.DisplayFlags are set to none, or Debug.DebugMode is disabled.

Watch(Object, String)

Watch an object's value and display it on the debug overlay.

public static void Watch(object value, string label)

Parameters

value Object
The Object to watch the value of.

label String
The label for the overlay to use to title the value when drawing it to the screen.