Changed the `AppStateMachine` to implement `IDisposable` and `IAsyncDisposable` for better resource management. Changed the `IAppState` interface to include asynchronous methods for state transitions. Changed the `App` class to start the host asynchronously and added an `OnClosed` method for proper shutdown. Changed the `EditorState` class to ensure the window closes correctly when exiting the state. Changed the `LandingState` class to improve window activation and deactivation management. Changed the `HostHelper` class to register `LandingWindow` and `EngineEditorWindow` as singletons for better performance. Changed the `ScenePage` class to utilize a new interface for swap chain management. Changed the `OpenProjectPage` and `CreateProjectPage` classes to enhance navigation handling. Changed the `ConsoleViewModel` to improve log update handling with a new context structure. Changed the `OpenProjectViewModel` to clear project lists when navigating away. Changed the `EngineCore` class to start the graphics pipeline asynchronously. Changed the `Logger` class to use a new context structure for log changes. Added the `ICommandBuffer`, `IGraphicsDevice`, and `IRenderView` interfaces to enhance the rendering pipeline. Changed the `DX12CommandBuffer`, `DX12GraphicsDevice`, and `DX12RenderView` classes for improved resource management and rendering efficiency. Refactored the `Mesh` class to use a new `Vertex` structure for simplified vertex management. Added the `TextureUtility` class for texture management utilities, including mip count calculation. Changed the `launchSettings.json` to include a new profile for the graphics project with native debugging enabled. Changed the `MeshBuilder` class to utilize the new `Vertex` structure for vertex creation.
105 lines
2.6 KiB
C#
105 lines
2.6 KiB
C#
using Ghost.Engine.Models;
|
|
using System.Diagnostics;
|
|
|
|
namespace Ghost.Engine.Services;
|
|
|
|
internal enum LogChangeType
|
|
{
|
|
LogAdded,
|
|
LogRemoved,
|
|
LogsCleared
|
|
}
|
|
|
|
internal readonly struct LogChangeContext(LogChangeType type, int index)
|
|
{
|
|
public readonly LogChangeType changeType = type;
|
|
public readonly int index = index;
|
|
}
|
|
|
|
public static class Logger
|
|
{
|
|
|
|
private const int _MAX_LOGS = 4096;
|
|
|
|
private static readonly List<LogMessage> _logs = new();
|
|
internal static IReadOnlyList<LogMessage> Logs => _logs;
|
|
|
|
internal static event Action<LogChangeContext>? OnLogsUpdate;
|
|
|
|
internal static bool HasStackTrace
|
|
{
|
|
get; set;
|
|
}
|
|
|
|
private static StackTrace? CaptureStackTrace()
|
|
{
|
|
return HasStackTrace ? new StackTrace(1, true) : null;
|
|
}
|
|
|
|
private static void LogInternal(LogLevel level, object? message, StackTrace? stackTrace)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogRemoved, 0));
|
|
}
|
|
|
|
var logMessage = new LogMessage(level, message?.ToString(), stackTrace?.ToString());
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogAdded, _logs.Count - 1));
|
|
}
|
|
|
|
private static void LogExceptionInternal(Exception ex)
|
|
{
|
|
if (_logs.Count >= _MAX_LOGS)
|
|
{
|
|
_logs.RemoveAt(0);
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogRemoved, 0));
|
|
}
|
|
|
|
var logMessage = new LogMessage(LogLevel.Error, ex.Message, ex.StackTrace);
|
|
_logs.Add(logMessage);
|
|
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogAdded, _logs.Count - 1));
|
|
}
|
|
|
|
public static void Log(LogLevel level, object? message)
|
|
{
|
|
LogInternal(level, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogInfo(object? message)
|
|
{
|
|
LogInternal(LogLevel.Info, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogWarning(object? message)
|
|
{
|
|
LogInternal(LogLevel.Warning, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogError(object? message)
|
|
{
|
|
LogInternal(LogLevel.Error, message, CaptureStackTrace());
|
|
}
|
|
|
|
public static void LogError(Exception ex)
|
|
{
|
|
LogExceptionInternal(ex);
|
|
}
|
|
|
|
public static void Assert(bool condition, object? message = null)
|
|
{
|
|
if (!condition)
|
|
{
|
|
LogInternal(LogLevel.Error, message ?? "Assertion failed", CaptureStackTrace());
|
|
}
|
|
}
|
|
|
|
internal static void Clear()
|
|
{
|
|
_logs.Clear();
|
|
OnLogsUpdate?.Invoke(new(LogChangeType.LogsCleared, -1));
|
|
}
|
|
} |