refactor(new_editor): snapshot hosted editor restructuring
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
#include "Platform/Win32/EditorWindowRuntimeController.h"
|
||||
|
||||
#include "Bootstrap/EditorResources.h"
|
||||
#include "Internal/EmbeddedPngLoader.h"
|
||||
#include "Platform/Win32/EditorWindowRuntimeInternal.h"
|
||||
#include "Composition/EditorContext.h"
|
||||
#include "Platform/Win32/EditorWindowSupport.h"
|
||||
#include "Support/EmbeddedPngLoader.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App::Internal {
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using App::Internal::LoadEmbeddedPngTexture;
|
||||
using namespace EditorWindowInternal;
|
||||
using App::LoadEmbeddedPngTexture;
|
||||
using namespace EditorWindowSupport;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kFrameTimeSmoothingFactor = 0.12f;
|
||||
|
||||
}
|
||||
|
||||
EditorWindowRuntimeController::EditorWindowRuntimeController(
|
||||
UIEditorWorkspaceController workspaceController)
|
||||
@@ -135,6 +143,7 @@ bool EditorWindowRuntimeController::Initialize(
|
||||
editorContext.DescribeWorkspaceState(
|
||||
m_workspaceController,
|
||||
m_shellRuntime.GetShellInteractionState()));
|
||||
ResetFrameTiming();
|
||||
m_ready = true;
|
||||
|
||||
m_autoScreenshot.Initialize(captureRoot);
|
||||
@@ -148,6 +157,7 @@ bool EditorWindowRuntimeController::Initialize(
|
||||
|
||||
void EditorWindowRuntimeController::Shutdown() {
|
||||
m_ready = false;
|
||||
ResetFrameTiming();
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_shellRuntime.Shutdown();
|
||||
m_renderer.ReleaseTexture(m_titleBarLogoIcon);
|
||||
@@ -158,6 +168,7 @@ void EditorWindowRuntimeController::Shutdown() {
|
||||
|
||||
void EditorWindowRuntimeController::ResetInteractionState() {
|
||||
m_shellRuntime.ResetInteractionState();
|
||||
ResetFrameTiming();
|
||||
}
|
||||
|
||||
bool EditorWindowRuntimeController::ApplyResize(UINT width, UINT height) {
|
||||
@@ -181,7 +192,8 @@ bool EditorWindowRuntimeController::ApplyResize(UINT width, UINT height) {
|
||||
return resizeResult.hasViewportSurfacePresentation;
|
||||
}
|
||||
|
||||
Host::D3D12WindowRenderLoopFrameContext EditorWindowRuntimeController::BeginFrame() const {
|
||||
Host::D3D12WindowRenderLoopFrameContext EditorWindowRuntimeController::BeginFrame() {
|
||||
UpdateFrameTiming();
|
||||
return m_windowRenderLoop.BeginFrame();
|
||||
}
|
||||
|
||||
@@ -223,4 +235,55 @@ std::string EditorWindowRuntimeController::BuildCaptureStatusText() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App::Internal
|
||||
std::string EditorWindowRuntimeController::BuildFrameRateText() const {
|
||||
if (m_displayFps <= 0.0f || m_displayFrameTimeMs <= 0.0f) {
|
||||
return {};
|
||||
}
|
||||
|
||||
char buffer[48] = {};
|
||||
std::snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"FPS %.1f | %.2f ms",
|
||||
m_displayFps,
|
||||
m_displayFrameTimeMs);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void EditorWindowRuntimeController::ResetFrameTiming() {
|
||||
m_lastFrameTime = {};
|
||||
m_hasLastFrameTime = false;
|
||||
m_smoothedDeltaTimeSeconds = 0.0f;
|
||||
m_displayFps = 0.0f;
|
||||
m_displayFrameTimeMs = 0.0f;
|
||||
}
|
||||
|
||||
void EditorWindowRuntimeController::UpdateFrameTiming() {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (!m_hasLastFrameTime) {
|
||||
m_lastFrameTime = now;
|
||||
m_hasLastFrameTime = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const float deltaTime = std::chrono::duration<float>(now - m_lastFrameTime).count();
|
||||
m_lastFrameTime = now;
|
||||
if (deltaTime <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_smoothedDeltaTimeSeconds <= 0.0f) {
|
||||
m_smoothedDeltaTimeSeconds = deltaTime;
|
||||
} else {
|
||||
m_smoothedDeltaTimeSeconds +=
|
||||
(deltaTime - m_smoothedDeltaTimeSeconds) * kFrameTimeSmoothingFactor;
|
||||
}
|
||||
|
||||
m_displayFrameTimeMs = m_smoothedDeltaTimeSeconds * 1000.0f;
|
||||
m_displayFps = m_smoothedDeltaTimeSeconds > 0.0f
|
||||
? 1.0f / m_smoothedDeltaTimeSeconds
|
||||
: 0.0f;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
|
||||
Reference in New Issue
Block a user