Fix editor selection system: SelectionManager ID types and Scene lookup

- SelectionManager now implements ISelectionManager interface with uint64_t IDs
- Remove SelectionManager/SceneManager circular dependency via EventBus
- Add Scene::FindByID() for proper ID-based entity lookup
- SceneManager::GetEntity() now uses FindByID instead of name-based Find
- Fix editor CMakeLists.txt XCEngine.lib path
- EventBus now thread-safe with shared_mutex
This commit is contained in:
2026-03-25 17:51:15 +08:00
parent 6612330347
commit b0d0576763
8 changed files with 77 additions and 39 deletions

View File

@@ -1,5 +1,4 @@
#include "SceneManager.h"
#include "SelectionManager.h"
#include <algorithm>
namespace XCEngine {
@@ -7,10 +6,6 @@ namespace Editor {
SceneManager::SceneManager() = default;
void SceneManager::SetSelectionManager(ISelectionManager* selectionManager) {
m_selectionManager = selectionManager;
}
::XCEngine::Components::GameObject* SceneManager::CreateEntity(const std::string& name, ::XCEngine::Components::GameObject* parent) {
if (!m_scene) {
m_scene = new ::XCEngine::Components::Scene("EditorScene");
@@ -41,12 +36,8 @@ void SceneManager::DeleteEntity(::XCEngine::Components::GameObject::ID id) {
m_rootEntities.erase(std::remove(m_rootEntities.begin(), m_rootEntities.end(), entity), m_rootEntities.end());
}
if (m_selectionManager && m_selectionManager->GetSelectedEntity() == entity->GetID()) {
m_selectionManager->ClearSelection();
}
m_scene->DestroyGameObject(entity);
OnEntityDeleted.Invoke(id);
OnEntityDeleted.Invoke(entity->GetID());
}
SceneManager::ClipboardData SceneManager::CopyEntityRecursive(const ::XCEngine::Components::GameObject* entity) {

View File

@@ -13,14 +13,11 @@
#include <XCEngine/Components/GameObject.h>
#include <XCEngine/Scene/Scene.h>
#include "Core/ISelectionManager.h"
#include "Core/ISceneManager.h"
namespace XCEngine {
namespace Editor {
class ISelectionManager;
class SceneManager : public ISceneManager {
public:
SceneManager();
@@ -28,11 +25,11 @@ public:
::XCEngine::Components::GameObject* CreateEntity(const std::string& name, ::XCEngine::Components::GameObject* parent = nullptr);
::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) {
return m_scene ? m_scene->Find(std::to_string(id)) : nullptr;
return m_scene ? m_scene->FindByID(id) : nullptr;
}
const ::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) const {
return m_scene ? m_scene->Find(std::to_string(id)) : nullptr;
return m_scene ? m_scene->FindByID(id) : nullptr;
}
const std::vector<::XCEngine::Components::GameObject*>& GetRootEntities() const {
@@ -51,8 +48,6 @@ public:
void CreateDemoScene();
bool HasClipboardData() const { return m_clipboard.has_value(); }
void SetSelectionManager(ISelectionManager* selectionManager);
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityCreated;
::XCEngine::Core::Event<::XCEngine::Components::GameObject::ID> OnEntityDeleted;
@@ -74,7 +69,6 @@ private:
::XCEngine::Components::Scene* m_scene = nullptr;
std::vector<::XCEngine::Components::GameObject*> m_rootEntities;
std::optional<ClipboardData> m_clipboard;
ISelectionManager* m_selectionManager = nullptr;
};
}