Add deferred async scene asset loading

This commit is contained in:
2026-04-02 18:50:41 +08:00
parent dd08d8969e
commit 86144416af
18 changed files with 1806 additions and 97 deletions

View File

@@ -9,7 +9,9 @@
#include "UI/BuiltInIcons.h"
#include "Platform/Win32Utf8.h"
#include "Platform/WindowsProcessDiagnostics.h"
#include <XCEngine/Core/Asset/ResourceManager.h>
#include <XCEngine/Debug/Logger.h>
#include <chrono>
#include <windows.h>
namespace XCEngine {
@@ -141,12 +143,18 @@ bool Application::Initialize(HWND hwnd) {
return false;
}
auto& resourceManager = ::XCEngine::Resources::ResourceManager::Get();
resourceManager.Initialize();
resourceManager.SetResourceRoot(projectRoot.c_str());
m_resourceManagerInitialized = true;
logger.Info(Debug::LogCategory::General, "Initializing editor context...");
InitializeEditorContext(projectRoot);
logger.Info(Debug::LogCategory::General, "Initializing ImGui backend...");
InitializeImGui(hwnd);
logger.Info(Debug::LogCategory::General, "Attaching editor layer...");
AttachEditorLayer();
m_hasLastFrameTime = false;
logger.Info(Debug::LogCategory::General, "Editor initialization completed.");
m_renderReady = true;
return true;
@@ -154,6 +162,7 @@ bool Application::Initialize(HWND hwnd) {
void Application::Shutdown() {
m_renderReady = false;
m_hasLastFrameTime = false;
DetachEditorLayer();
if (m_editorContext) {
static_cast<EditorContext*>(m_editorContext.get())->SetViewportHostService(nullptr);
@@ -163,6 +172,10 @@ void Application::Shutdown() {
m_imguiBackend.Shutdown();
m_imguiSession.Shutdown();
ShutdownEditorContext();
if (m_resourceManagerInitialized) {
::XCEngine::Resources::ResourceManager::Get().Shutdown();
m_resourceManagerInitialized = false;
}
m_windowRenderer.Shutdown();
}
@@ -170,6 +183,16 @@ void Application::Render() {
if (!m_renderReady) {
return;
}
const auto now = std::chrono::steady_clock::now();
float deltaTime = 0.0f;
if (m_hasLastFrameTime) {
deltaTime = std::chrono::duration<float>(now - m_lastFrameTime).count();
}
m_lastFrameTime = now;
m_hasLastFrameTime = true;
m_layerStack.onUpdate(deltaTime);
RenderEditorFrame();
}
@@ -206,6 +229,8 @@ bool Application::SwitchProject(const std::string& projectPath) {
const std::string infoMessage = "Switched editor project root: " + projectPath;
logger.Info(Debug::LogCategory::General, infoMessage.c_str());
::XCEngine::Resources::ResourceManager::Get().SetResourceRoot(projectPath.c_str());
m_lastWindowTitle.clear();
UpdateWindowTitle();