Update new_editor inspector layout and host rendering

This commit is contained in:
2026-04-21 13:24:03 +08:00
parent d388c3994b
commit 5d81a64ef3
62 changed files with 4417 additions and 151 deletions

View File

@@ -18,6 +18,8 @@ using namespace EditorWindowSupport;
namespace {
constexpr float kFrameTimeSmoothingFactor = 0.12f;
constexpr float kFrameTimingResetThresholdSeconds = 0.5f;
constexpr float kFrameStatsIdleLabelThresholdSeconds = 0.35f;
}
@@ -73,6 +75,7 @@ void EditorWindowRuntimeController::ClearExternalDockHostDropPreview() {
void EditorWindowRuntimeController::SetDpiScale(float dpiScale) {
m_renderer.SetDpiScale(dpiScale);
m_windowRenderLoop.SetDpiScale(dpiScale);
}
Host::NativeRenderer& EditorWindowRuntimeController::GetRenderer() {
@@ -192,13 +195,16 @@ bool EditorWindowRuntimeController::ApplyResize(UINT width, UINT height) {
return resizeResult.hasViewportSurfacePresentation;
}
Host::D3D12WindowRenderLoopFrameContext EditorWindowRuntimeController::BeginFrame() {
UpdateFrameTiming();
Host::D3D12WindowRenderLoopFrameContext EditorWindowRuntimeController::BeginFrame(
bool updateFrameTiming) {
if (updateFrameTiming) {
UpdateFrameTiming();
}
return m_windowRenderLoop.BeginFrame();
}
Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present(
const ::XCEngine::UI::UIDrawData& drawData) const {
const ::XCEngine::UI::UIDrawData& drawData) {
return m_windowRenderLoop.Present(drawData);
}
@@ -240,19 +246,36 @@ std::string EditorWindowRuntimeController::BuildFrameRateText() const {
return {};
}
char buffer[48] = {};
std::snprintf(
buffer,
sizeof(buffer),
"FPS %.1f | %.2f ms",
m_displayFps,
m_displayFrameTimeMs);
const auto now = std::chrono::steady_clock::now();
const float idleSeconds =
m_hasLastMeasuredFrameTime
? std::chrono::duration<float>(now - m_lastMeasuredFrameTime).count()
: 0.0f;
char buffer[72] = {};
if (idleSeconds >= kFrameStatsIdleLabelThresholdSeconds) {
std::snprintf(
buffer,
sizeof(buffer),
"FPS %.1f | %.2f ms | %.1fs ago",
m_displayFps,
m_displayFrameTimeMs,
idleSeconds);
} else {
std::snprintf(
buffer,
sizeof(buffer),
"FPS %.1f | %.2f ms",
m_displayFps,
m_displayFrameTimeMs);
}
return buffer;
}
void EditorWindowRuntimeController::ResetFrameTiming() {
m_lastFrameTime = {};
m_lastMeasuredFrameTime = {};
m_hasLastFrameTime = false;
m_hasLastMeasuredFrameTime = false;
m_smoothedDeltaTimeSeconds = 0.0f;
m_displayFps = 0.0f;
m_displayFrameTimeMs = 0.0f;
@@ -271,6 +294,9 @@ void EditorWindowRuntimeController::UpdateFrameTiming() {
if (deltaTime <= 0.0f) {
return;
}
if (deltaTime > kFrameTimingResetThresholdSeconds) {
return;
}
if (m_smoothedDeltaTimeSeconds <= 0.0f) {
m_smoothedDeltaTimeSeconds = deltaTime;
@@ -283,6 +309,8 @@ void EditorWindowRuntimeController::UpdateFrameTiming() {
m_displayFps = m_smoothedDeltaTimeSeconds > 0.0f
? 1.0f / m_smoothedDeltaTimeSeconds
: 0.0f;
m_lastMeasuredFrameTime = now;
m_hasLastMeasuredFrameTime = true;
}
} // namespace XCEngine::UI::Editor::App