diff --git a/new_editor/CMakeLists.txt b/new_editor/CMakeLists.txt index 6a2226fd..e0783f89 100644 --- a/new_editor/CMakeLists.txt +++ b/new_editor/CMakeLists.txt @@ -166,7 +166,7 @@ set(XCUI_EDITOR_HOST_PLATFORM_SOURCES ) set(XCUI_EDITOR_HOST_RENDERING_SOURCES - app/Rendering/Native/AutoScreenshot.cpp + app/Platform/Win32/EditorWindowScreenshotController.cpp app/Rendering/D3D12/D3D12HostDevice.cpp app/Rendering/D3D12/D3D12WindowCapture.cpp app/Rendering/D3D12/D3D12UiRenderer.cpp diff --git a/new_editor/app/Bootstrap/Application.cpp b/new_editor/app/Bootstrap/Application.cpp index d82a4ef8..1b34f1b5 100644 --- a/new_editor/app/Bootstrap/Application.cpp +++ b/new_editor/app/Bootstrap/Application.cpp @@ -5,6 +5,7 @@ #include "Platform/Win32/EditorWindowManager.h" #include "Platform/Win32/EditorWindow.h" #include "Platform/Win32/Win32SystemInteractionHost.h" +#include "Support/EnvironmentFlags.h" #include "Support/ExecutablePath.h" #include @@ -144,7 +145,8 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) { createParams.title = kWindowTitle; createParams.showCommand = nCmdShow; createParams.primary = true; - createParams.autoCaptureOnStartup = true; + createParams.autoCaptureOnStartup = + App::IsEnvironmentFlagEnabled("XCUI_AUTO_CAPTURE_ON_STARTUP"); if (m_windowManager->CreateEditorWindow( m_editorContext->BuildWorkspaceController(), createParams) == nullptr) { diff --git a/new_editor/app/Platform/Win32/EditorWindow.cpp b/new_editor/app/Platform/Win32/EditorWindow.cpp index 2999fe6a..defa8e80 100644 --- a/new_editor/app/Platform/Win32/EditorWindow.cpp +++ b/new_editor/app/Platform/Win32/EditorWindow.cpp @@ -64,10 +64,6 @@ void LogRuntimeTrace(std::string_view channel, std::string_view message) { AppendUIEditorRuntimeTrace(channel, message); } -bool IsAutoCaptureOnStartupEnabled() { - return App::IsEnvironmentFlagEnabled("XCUI_AUTO_CAPTURE_ON_STARTUP"); -} - } // namespace XCEngine::UI::Editor::App::EditorWindowSupport namespace XCEngine::UI::Editor::App { diff --git a/new_editor/app/Platform/Win32/EditorWindowRuntimeController.cpp b/new_editor/app/Platform/Win32/EditorWindowRuntimeController.cpp index bee022ba..78e6a304 100644 --- a/new_editor/app/Platform/Win32/EditorWindowRuntimeController.cpp +++ b/new_editor/app/Platform/Win32/EditorWindowRuntimeController.cpp @@ -168,9 +168,9 @@ bool EditorWindowRuntimeController::Initialize( ResetFrameTiming(); m_ready = true; - m_autoScreenshot.Initialize(captureRoot); - if (autoCaptureOnStartup && IsAutoCaptureOnStartupEnabled()) { - m_autoScreenshot.RequestCapture("startup"); + m_screenshotController.Initialize(captureRoot); + if (autoCaptureOnStartup) { + m_screenshotController.RequestCapture("startup"); editorContext.SetStatus("Capture", "Startup capture requested."); } @@ -182,8 +182,10 @@ void EditorWindowRuntimeController::Shutdown() { ResetFrameTiming(); LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=WaitForGpuIdle"); m_windowRenderer.WaitForGpuIdle(); - LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=AutoScreenshot"); - m_autoScreenshot.Shutdown(); + LogRuntimeTrace( + "window-close", + "EditorWindowRuntimeController::Shutdown stage=ScreenshotController"); + m_screenshotController.Shutdown(); LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=ShellRuntime"); m_shellRuntime.Shutdown(); LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=RenderLoopDetach"); @@ -232,7 +234,7 @@ Host::D3D12WindowRenderLoopFrameContext EditorWindowRuntimeController::BeginFram Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present( const ::XCEngine::UI::UIDrawData& drawData) { std::filesystem::path capturePath = {}; - const bool captureRequested = m_autoScreenshot.TryBeginCapture(capturePath); + const bool captureRequested = m_screenshotController.TryBeginCapture(capturePath); Host::D3D12WindowRenderLoopPresentResult result = m_windowRenderLoop.Present( @@ -242,7 +244,7 @@ Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present( if (captureRequested) { const bool captureSucceeded = result.framePresented && result.captureSucceeded; if (captureSucceeded) { - m_autoScreenshot.CompleteCaptureSuccess(capturePath); + m_screenshotController.CompleteCaptureSuccess(capturePath); LogRuntimeTrace("capture", "native d3d12 capture succeeded: " + capturePath.string()); } else { std::string captureError = result.captureError; @@ -251,10 +253,10 @@ Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present( ? result.warning : "Screenshot capture did not complete."; } - m_autoScreenshot.CompleteCaptureFailure(std::move(captureError)); + m_screenshotController.CompleteCaptureFailure(std::move(captureError)); LogRuntimeTrace( "capture", - "native d3d12 capture failed: " + m_autoScreenshot.GetLastCaptureError()); + "native d3d12 capture failed: " + m_screenshotController.GetLastCaptureError()); } } @@ -262,20 +264,20 @@ Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present( } void EditorWindowRuntimeController::RequestManualScreenshot(std::string reason) { - m_autoScreenshot.RequestCapture(std::move(reason)); + m_screenshotController.RequestCapture(std::move(reason)); } std::string EditorWindowRuntimeController::BuildCaptureStatusText() const { - if (m_autoScreenshot.HasPendingCapture()) { + if (m_screenshotController.HasPendingCapture()) { return "Shot pending..."; } - if (!m_autoScreenshot.GetLastCaptureError().empty()) { - return TruncateText(m_autoScreenshot.GetLastCaptureError(), 38u); + if (!m_screenshotController.GetLastCaptureError().empty()) { + return TruncateText(m_screenshotController.GetLastCaptureError(), 38u); } - if (!m_autoScreenshot.GetLastCaptureSummary().empty()) { - return TruncateText(m_autoScreenshot.GetLastCaptureSummary(), 38u); + if (!m_screenshotController.GetLastCaptureSummary().empty()) { + return TruncateText(m_screenshotController.GetLastCaptureSummary(), 38u); } return {}; diff --git a/new_editor/app/Platform/Win32/EditorWindowRuntimeController.h b/new_editor/app/Platform/Win32/EditorWindowRuntimeController.h index 35e93fd5..6c3f8f03 100644 --- a/new_editor/app/Platform/Win32/EditorWindowRuntimeController.h +++ b/new_editor/app/Platform/Win32/EditorWindowRuntimeController.h @@ -5,13 +5,13 @@ #endif #include "Composition/EditorShellRuntime.h" +#include "Platform/Win32/EditorWindowScreenshotController.h" #include #include #include #include #include -#include #include @@ -97,7 +97,7 @@ private: Host::D3D12UiTextSystem m_textSystem = {}; Host::D3D12UiRenderer m_uiRenderer = {}; Host::D3D12WindowRenderLoop m_windowRenderLoop = {}; - Host::AutoScreenshotController m_autoScreenshot = {}; + EditorWindowScreenshotController m_screenshotController = {}; ::XCEngine::UI::UITextureHandle m_titleBarLogoIcon = {}; UIEditorWorkspaceController m_workspaceController = {}; EditorShellRuntime m_shellRuntime = {}; diff --git a/new_editor/app/Rendering/Native/AutoScreenshot.cpp b/new_editor/app/Platform/Win32/EditorWindowScreenshotController.cpp similarity index 80% rename from new_editor/app/Rendering/Native/AutoScreenshot.cpp rename to new_editor/app/Platform/Win32/EditorWindowScreenshotController.cpp index 42454a49..7d0e1171 100644 --- a/new_editor/app/Rendering/Native/AutoScreenshot.cpp +++ b/new_editor/app/Platform/Win32/EditorWindowScreenshotController.cpp @@ -1,6 +1,5 @@ -#include "AutoScreenshot.h" +#include "Platform/Win32/EditorWindowScreenshotController.h" -#include "Support/EnvironmentFlags.h" #include "Support/ExecutablePath.h" #include @@ -8,7 +7,7 @@ #include #include -namespace XCEngine::UI::Editor::Host { +namespace XCEngine::UI::Editor::App { namespace { @@ -24,7 +23,7 @@ std::filesystem::path ResolveBuildCaptureRoot(const std::filesystem::path& reque } // namespace -void AutoScreenshotController::Initialize(const std::filesystem::path& captureRoot) { +void EditorWindowScreenshotController::Initialize(const std::filesystem::path& captureRoot) { m_captureRoot = ResolveBuildCaptureRoot(captureRoot); m_historyRoot = (m_captureRoot / "history").lexically_normal(); m_latestCapturePath = (m_captureRoot / "latest.png").lexically_normal(); @@ -34,23 +33,20 @@ void AutoScreenshotController::Initialize(const std::filesystem::path& captureRo m_pendingReason.clear(); m_lastCaptureSummary = "Output: " + m_captureRoot.string(); m_lastCaptureError.clear(); - if (App::IsEnvironmentFlagEnabled("XCUI_AUTO_CAPTURE_ON_STARTUP")) { - RequestCapture("startup"); - } } -void AutoScreenshotController::Shutdown() { +void EditorWindowScreenshotController::Shutdown() { m_activeHistoryCapturePath.clear(); m_capturePending = false; m_pendingReason.clear(); } -void AutoScreenshotController::RequestCapture(std::string reason) { +void EditorWindowScreenshotController::RequestCapture(std::string reason) { m_pendingReason = reason.empty() ? "capture" : std::move(reason); m_capturePending = true; } -bool AutoScreenshotController::TryBeginCapture(std::filesystem::path& outHistoryPath) { +bool EditorWindowScreenshotController::TryBeginCapture(std::filesystem::path& outHistoryPath) { outHistoryPath.clear(); if (!m_capturePending) { return false; @@ -78,7 +74,8 @@ bool AutoScreenshotController::TryBeginCapture(std::filesystem::path& outHistory return true; } -void AutoScreenshotController::CompleteCaptureSuccess(const std::filesystem::path& historyPath) { +void EditorWindowScreenshotController::CompleteCaptureSuccess( + const std::filesystem::path& historyPath) { const std::filesystem::path resolvedHistoryPath = historyPath.empty() ? m_activeHistoryCapturePath : historyPath; if (resolvedHistoryPath.empty()) { @@ -114,7 +111,7 @@ void AutoScreenshotController::CompleteCaptureSuccess(const std::filesystem::pat ResetPendingRequest(); } -void AutoScreenshotController::CompleteCaptureFailure(std::string error) { +void EditorWindowScreenshotController::CompleteCaptureFailure(std::string error) { if (!m_activeHistoryCapturePath.empty()) { std::error_code deleteError = {}; std::filesystem::remove(m_activeHistoryCapturePath, deleteError); @@ -127,29 +124,30 @@ void AutoScreenshotController::CompleteCaptureFailure(std::string error) { ResetPendingRequest(); } -bool AutoScreenshotController::HasPendingCapture() const { +bool EditorWindowScreenshotController::HasPendingCapture() const { return m_capturePending; } -const std::filesystem::path& AutoScreenshotController::GetLatestCapturePath() const { +const std::filesystem::path& EditorWindowScreenshotController::GetLatestCapturePath() const { return m_latestCapturePath; } -const std::string& AutoScreenshotController::GetLastCaptureSummary() const { +const std::string& EditorWindowScreenshotController::GetLastCaptureSummary() const { return m_lastCaptureSummary; } -const std::string& AutoScreenshotController::GetLastCaptureError() const { +const std::string& EditorWindowScreenshotController::GetLastCaptureError() const { return m_lastCaptureError; } -void AutoScreenshotController::ResetPendingRequest() { +void EditorWindowScreenshotController::ResetPendingRequest() { m_capturePending = false; m_pendingReason.clear(); m_activeHistoryCapturePath.clear(); } -std::filesystem::path AutoScreenshotController::BuildHistoryCapturePath(std::string_view reason) const { +std::filesystem::path EditorWindowScreenshotController::BuildHistoryCapturePath( + std::string_view reason) const { std::ostringstream filename; filename << BuildTimestampString() << '_' @@ -160,7 +158,7 @@ std::filesystem::path AutoScreenshotController::BuildHistoryCapturePath(std::str return (m_historyRoot / filename.str()).lexically_normal(); } -std::string AutoScreenshotController::BuildTimestampString() { +std::string EditorWindowScreenshotController::BuildTimestampString() { const auto now = std::chrono::system_clock::now(); const std::time_t currentTime = std::chrono::system_clock::to_time_t(now); std::tm localTime = {}; @@ -180,7 +178,7 @@ std::string AutoScreenshotController::BuildTimestampString() { return buffer; } -std::string AutoScreenshotController::SanitizeReason(std::string_view reason) { +std::string EditorWindowScreenshotController::SanitizeReason(std::string_view reason) { std::string sanitized = {}; sanitized.reserve(reason.size()); @@ -208,4 +206,4 @@ std::string AutoScreenshotController::SanitizeReason(std::string_view reason) { return sanitized.empty() ? "capture" : sanitized; } -} // namespace XCEngine::UI::Editor::Host +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Rendering/Native/AutoScreenshot.h b/new_editor/app/Platform/Win32/EditorWindowScreenshotController.h similarity index 91% rename from new_editor/app/Rendering/Native/AutoScreenshot.h rename to new_editor/app/Platform/Win32/EditorWindowScreenshotController.h index 46d661fe..51ab1002 100644 --- a/new_editor/app/Rendering/Native/AutoScreenshot.h +++ b/new_editor/app/Platform/Win32/EditorWindowScreenshotController.h @@ -9,9 +9,9 @@ #include #include -namespace XCEngine::UI::Editor::Host { +namespace XCEngine::UI::Editor::App { -class AutoScreenshotController { +class EditorWindowScreenshotController { public: void Initialize(const std::filesystem::path& captureRoot); void Shutdown(); @@ -44,4 +44,4 @@ private: bool m_capturePending = false; }; -} // namespace XCEngine::UI::Editor::Host +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Platform/Win32/EditorWindowSupport.h b/new_editor/app/Platform/Win32/EditorWindowSupport.h index 229e19c5..563a753e 100644 --- a/new_editor/app/Platform/Win32/EditorWindowSupport.h +++ b/new_editor/app/Platform/Win32/EditorWindowSupport.h @@ -30,7 +30,6 @@ UINT QuerySystemDpi(); UINT QueryWindowDpi(HWND hwnd); bool ResolveVerboseRuntimeTraceEnabled(); void LogRuntimeTrace(std::string_view channel, std::string_view message); -bool IsAutoCaptureOnStartupEnabled(); using App::TruncateText; using App::WideToUtf8;