Changed the `EditorState` class to use a timeout in the `WaitForGPUReady` method for improved responsiveness. Changed the `nativeDebugging` setting in `launchSettings.json` to `false` for the "Ghost.Editor (Package)" profile. Changed the `D3D12Renderer` class to set the swap chain only for the composition target type and replaced back buffer reset with dispose. Changed the mapping of resources in `D3D12Resource` to use a pointer for improved safety and clarity. Changed the `Mesh` class's upload buffer creation to not use the `true` flag for better memory management. Added a new `Vertex` struct with a `StructLayout` attribute for improved interoperability with unmanaged code. Refactored the `GraphicsPipeline` class to replace `IsGpuReady` with `WaitForGPUReady`, including a timeout parameter. Added a constant buffer to the HLSL source code in `MeshRenderPass` for passing transformation matrices to the vertex shader. Expanded the `UnitTestAppWindow` class to include event handlers for window activation and size changes for better resource management. Updated the XAML for `UnitTestAppWindow` to include a `SwapChainPanel` and corrected the XML declaration for formatting consistency.
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.WaitForGPUReady(0))
|
|
{
|
|
_window?.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.High, () =>
|
|
{
|
|
PlayerLoopService.Update();
|
|
GraphicsPipeline.SignalCPUReady();
|
|
});
|
|
}
|
|
}
|
|
} |