forked from Misaki/GhostEngine
Added `InternalsVisibleTo` attribute for "Ghost.Graphics" and "Ghost.Editor" in `AssemblyInfo.cs`. Added a new `EngineAssemblyAttribute` in `EngineAssemblyAttribute.cs`. Added a reference to `Misaki.HighPerformance.Unsafe` in `Ghost.Core.csproj`. Added a new `Bounds` struct to represent axis-aligned bounding boxes in `Bounds.cs`. Added new `Color32` and `Color128` structs for color representation in `Color.cs`. Changed the namespace from `Ghost.Editor.Controls` to `Ghost.Editor.Core.Controls` in multiple files. Changed the implicit conversion operator in `ConstPtr<T>` to use a more descriptive parameter name in `ConstPtr.cs`. Changed the `Mesh` class to use `Color128` instead of `Color32` for color representation. Enhanced the `TypeCache` class to load types from assemblies marked with `EngineAssemblyAttribute`. Enhanced the `ProjectService` class to improve the `GetAllProjectAsync` method by filtering out bad projects. Enhanced the `GraphicsPipeline` class to support both DX12 and D3D12 graphics APIs. Enhanced the `Shader` class to include methods for compiling HLSL shaders and managing root signatures. Enhanced the `MeshRenderPass` class to utilize the new shader compilation methods. Refactored the `AppStateMachine` class to use private fields instead of static fields for state management. Refactored the `ComponentDataView` class to use the new namespace and improve organization. Refactored project references in `Ghost.Graphics.csproj` to include new dependencies and remove outdated ones. Made various adjustments to ensure consistency and improve code quality across multiple files.
76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using Ghost.Data.Models;
|
|
using Ghost.Data.Services;
|
|
using Ghost.Editor.Core.AssetHandle;
|
|
using Ghost.Editor.View.Windows;
|
|
using Ghost.Engine;
|
|
using Ghost.Engine.Services;
|
|
using Ghost.Graphics;
|
|
using Microsoft.UI.Xaml.Media;
|
|
|
|
namespace Ghost.Editor.Core.AppState;
|
|
|
|
internal class EditorState : IAppState
|
|
{
|
|
private EngineEditorWindow? _window;
|
|
private EngineCore? _engineCore;
|
|
|
|
public Task OnExitingAsync()
|
|
{
|
|
if (App.Window == _window)
|
|
{
|
|
App.Window = null;
|
|
}
|
|
|
|
_engineCore?.ShutDown();
|
|
CompositionTarget.Rendering -= OnRendering;
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task OnEnteringAsync(object? parameter)
|
|
{
|
|
if (parameter is not ProjectMetadataInfo metadataInfo)
|
|
{
|
|
throw new ArgumentException("Parameter must be of type ProjectMetadata.", nameof(parameter));
|
|
}
|
|
|
|
ProjectService.CurrentProject = metadataInfo;
|
|
|
|
_engineCore = App.GetService<EngineCore>();
|
|
_engineCore.Start(new Engine.Models.LaunchArgument());
|
|
CompositionTarget.Rendering += OnRendering;
|
|
|
|
_window = App.GetService<EngineEditorWindow>();
|
|
_window.Activate();
|
|
|
|
App.Window = _window;
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task OnExitedAsync()
|
|
{
|
|
_window?.Close();
|
|
_window = null;
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task OnEnteredAsync(object? parameter)
|
|
{
|
|
AssetDatabase.Initialize();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void OnRendering(object? sender, object e)
|
|
{
|
|
if (GraphicsPipeline.IsGpuReady())
|
|
{
|
|
_window?.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.High, () =>
|
|
{
|
|
PlayerLoopService.Update();
|
|
GraphicsPipeline.SignalCPUReady();
|
|
});
|
|
}
|
|
}
|
|
} |