Refactor editor scene document ownership into runtime coordinator

This commit is contained in:
2026-04-29 16:24:06 +08:00
parent 749417989a
commit 631bf32db2
9 changed files with 197 additions and 78 deletions

View File

@@ -103,7 +103,6 @@ std::string_view GetSceneToolInteractionLockName(SceneToolInteractionLock lock)
void EditorSceneRuntime::Reset() {
m_projectRoot.clear();
m_startupSceneResult = {};
m_ownedSelectionService.ClearSelection();
m_selectionService = &m_ownedSelectionService;
ResetTransformEditHistory();
@@ -116,15 +115,17 @@ void EditorSceneRuntime::SetBackend(std::unique_ptr<EditorSceneBackend> backend)
Reset();
}
bool EditorSceneRuntime::Initialize(const std::filesystem::path& projectRoot) {
EditorStartupSceneResult EditorSceneRuntime::Initialize(
const std::filesystem::path& projectRoot) {
Reset();
if (m_backend == nullptr) {
return false;
return {};
}
m_projectRoot = projectRoot;
m_startupSceneResult = m_backend->EnsureStartupScene(projectRoot);
const EditorStartupSceneResult startupScene =
m_backend->EnsureStartupScene(projectRoot);
RefreshScene();
return m_startupSceneResult.ready;
return startupScene;
}
void EditorSceneRuntime::BindSelectionService(
@@ -152,10 +153,6 @@ void EditorSceneRuntime::EnsureSceneSelection() {
SelectFirstAvailableGameObject();
}
const EditorStartupSceneResult& EditorSceneRuntime::GetStartupResult() const {
return m_startupSceneResult;
}
EditorSceneHierarchySnapshot EditorSceneRuntime::BuildHierarchySnapshot() const {
return m_backend != nullptr
? m_backend->BuildHierarchySnapshot()
@@ -284,18 +281,6 @@ bool EditorSceneRuntime::NewScene(std::string_view sceneName) {
return false;
}
m_startupSceneResult.ready = true;
m_startupSceneResult.loadedFromDisk = false;
m_startupSceneResult.scenePath = std::filesystem::path();
if (::XCEngine::Components::Scene* activeScene = m_backend->GetActiveScene();
activeScene != nullptr) {
m_startupSceneResult.sceneName = activeScene->GetName();
} else {
m_startupSceneResult.sceneName = sceneName.empty()
? std::string("Untitled")
: std::string(sceneName);
}
ResetTransformEditHistory();
SelectionService().ClearSelection();
IncrementInspectorRevision();
@@ -310,11 +295,6 @@ bool EditorSceneRuntime::OpenSceneAsset(const std::filesystem::path& scenePath)
return false;
}
m_startupSceneResult.ready = true;
m_startupSceneResult.loadedFromDisk = true;
m_startupSceneResult.scenePath = scenePath;
m_startupSceneResult.sceneName = scenePath.stem().string();
ResetTransformEditHistory();
SelectionService().ClearSelection();
IncrementInspectorRevision();
@@ -332,6 +312,15 @@ bool EditorSceneRuntime::SaveScene(const std::filesystem::path& scenePath) {
return m_backend != nullptr ? m_backend->GetActiveScene() : nullptr;
}
std::string EditorSceneRuntime::GetActiveSceneName() const {
if (const ::XCEngine::Components::Scene* activeScene = GetActiveScene();
activeScene != nullptr) {
return activeScene->GetName();
}
return {};
}
std::unique_ptr<EditorScenePlaySession> EditorSceneRuntime::BeginPlaySession() {
return m_backend != nullptr
? m_backend->BeginPlaySession()