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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user