Refine editor action shell and add regression tests

This commit is contained in:
2026-03-27 12:06:24 +08:00
parent c33404767e
commit 4b9a63098e
21 changed files with 838 additions and 308 deletions

View File

@@ -17,6 +17,62 @@ Application& Application::Get() {
return instance;
}
bool Application::InitializeWindowRenderer(HWND hwnd) {
if (m_windowRenderer.Initialize(hwnd, 1280, 720)) {
return true;
}
MessageBoxW(hwnd, L"Failed to create D3D12 device", L"Error", MB_OK | MB_ICONERROR);
return false;
}
void Application::InitializeEditorContext(const std::string& projectPath) {
m_editorContext = std::make_shared<EditorContext>();
m_editorContext->SetProjectPath(projectPath);
m_exitRequestedHandlerId = m_editorContext->GetEventBus().Subscribe<EditorExitRequestedEvent>(
[this](const EditorExitRequestedEvent&) {
if (m_hwnd) {
PostMessageW(m_hwnd, WM_CLOSE, 0, 0);
}
});
}
void Application::InitializeImGui(HWND hwnd) {
m_imguiSession.Initialize(m_editorContext->GetProjectPath());
m_imguiBackend.Initialize(hwnd, m_windowRenderer.GetDevice(), m_windowRenderer.GetSrvHeap());
}
void Application::AttachEditorLayer() {
m_editorLayer = new EditorLayer();
m_editorLayer->SetContext(m_editorContext);
m_layerStack.pushLayer(std::unique_ptr<Core::Layer>(m_editorLayer));
m_layerStack.onAttach();
}
void Application::DetachEditorLayer() {
m_layerStack.onDetach();
m_editorLayer = nullptr;
}
void Application::ShutdownEditorContext() {
if (m_editorContext && m_exitRequestedHandlerId) {
m_editorContext->GetEventBus().Unsubscribe<EditorExitRequestedEvent>(m_exitRequestedHandlerId);
m_exitRequestedHandlerId = 0;
}
m_editorContext.reset();
}
void Application::RenderEditorFrame() {
static constexpr float kClearColor[4] = { 0.22f, 0.22f, 0.22f, 1.0f };
m_imguiBackend.BeginFrame();
m_layerStack.onImGuiRender();
UpdateWindowTitle();
ImGui::Render();
m_windowRenderer.Render(m_imguiBackend, kClearColor);
}
bool Application::Initialize(HWND hwnd) {
Platform::InstallCrashExceptionFilter();
Platform::RedirectStderrToExecutableLog();
@@ -25,55 +81,27 @@ bool Application::Initialize(HWND hwnd) {
ConfigureEditorLogging(exeDir);
m_hwnd = hwnd;
if (!m_windowRenderer.Initialize(hwnd, 1280, 720)) {
MessageBoxW(hwnd, L"Failed to create D3D12 device", L"Error", MB_OK | MB_ICONERROR);
if (!InitializeWindowRenderer(hwnd)) {
return false;
}
m_editorContext = std::make_shared<EditorContext>();
m_editorContext->SetProjectPath(exeDir);
m_exitRequestedHandlerId = m_editorContext->GetEventBus().Subscribe<EditorExitRequestedEvent>(
[this](const EditorExitRequestedEvent&) {
if (m_hwnd) {
PostMessageW(m_hwnd, WM_CLOSE, 0, 0);
}
});
m_imguiSession.Initialize(m_editorContext->GetProjectPath());
m_imguiBackend.Initialize(hwnd, m_windowRenderer.GetDevice(), m_windowRenderer.GetSrvHeap());
m_editorLayer = new EditorLayer();
m_editorLayer->SetContext(m_editorContext);
m_layerStack.pushLayer(std::unique_ptr<Core::Layer>(m_editorLayer));
m_layerStack.onAttach();
InitializeEditorContext(exeDir);
InitializeImGui(hwnd);
AttachEditorLayer();
return true;
}
void Application::Shutdown() {
m_layerStack.onDetach();
if (m_editorContext && m_exitRequestedHandlerId) {
m_editorContext->GetEventBus().Unsubscribe<EditorExitRequestedEvent>(m_exitRequestedHandlerId);
m_exitRequestedHandlerId = 0;
}
DetachEditorLayer();
m_imguiBackend.Shutdown();
m_imguiSession.Shutdown();
ShutdownEditorContext();
m_windowRenderer.Shutdown();
}
void Application::Render() {
m_imguiBackend.BeginFrame();
m_layerStack.onImGuiRender();
UpdateWindowTitle();
ImGui::Render();
float clearColor[4] = { 0.22f, 0.22f, 0.22f, 1.0f };
m_windowRenderer.Render(m_imguiBackend, clearColor);
RenderEditorFrame();
}
void Application::UpdateWindowTitle() {