refactor: 实体句柄表皮——实体自己管理组件的 API 形态

- 新增 EntityHandle:e.AddComponent<T>() / e.GetComponent<T>() /
  e.Destroy() / e.GetUUID(),转发 entt registry,零存储开销
- Scene::CreateEntity 返回 EntityHandle;Scene 层组件接口保留
  (给渲染器/系统批量遍历用)
- 语义分层:应用层"实体管组件"(句柄表皮),
  数据层组件存储仍集中在 registry(ECS 性能根基)
This commit is contained in:
2026-09-22 13:59:18 +08:00
parent b73e197783
commit 394bfd3d0c
4 changed files with 150 additions and 23 deletions
+3 -2
View File
@@ -3,11 +3,12 @@
//
#include <Engine/ECS/Scene.h>
#include <Engine/ECS/EntityHandle.h>
#include <Engine/Core/Log.h>
namespace Engine::ECS {
Entity Scene::CreateEntity(std::string name)
EntityHandle Scene::CreateEntity(std::string name)
{
Entity e = m_Registry.create();
// IdComponent 自动挂载:每个实体出生即有稳定 UUID
@@ -15,7 +16,7 @@ namespace Engine::ECS {
if (!name.empty()) {
m_Registry.emplace<NameComponent>(e, NameComponent{std::move(name)});
}
return e;
return EntityHandle{this, e};
}
Entity Scene::FindEntityByUUID(UUID uuid)