refactor: transform world 矩阵改由帧循环统一重算,删除手动 Compose

- Scene::UpdateTransforms():渲染前全量 Compose(UE transform-update
  阶段模式),Application::Run 在 FlushDestroyQueue 后调用
- 用户代码永远不需要手动 Compose——Set*/直接写字段均安全;
  Compose 降级为引擎内部调用
- 选择全量而非 dirty 标记:字段直接写(t.rotation.y = x)无法可靠
  追踪脏,无条件重算零脚枪;万级实体内成本可忽略,更大规模再引入
  dirty+封装
- main.cpp/Camera 所有手动 Compose 调用点删除
This commit is contained in:
2026-09-23 15:26:58 +08:00
parent 1bc44e261b
commit 57ab8901a9
6 changed files with 35 additions and 25 deletions
+6 -3
View File
@@ -34,8 +34,10 @@ namespace Engine::ECS {
std::string name;
};
// 世界变换:可编辑的 SRT 分量 + 派生的世界矩阵。
// 编辑分量后调用 Compose() 重算 world;渲染热路径只读 world。
// 世界变换:可编辑的 SRT 分量 + 派生的 world 矩阵。
// 分量可直接读写(含直接改字段);world 由帧循环的
// Scene::UpdateTransforms() 全量重算(UE transform-update 阶段
// 模式),调用方永远不需要手动 Compose。渲染热路径只读 world。
// 层级(父子变换)留给后续的层级同步系统。
struct TransformComponent {
glm::vec3 position{0.0f};
@@ -47,7 +49,8 @@ namespace Engine::ECS {
TransformComponent& SetRotation(const glm::vec3& r) { rotation = r; return *this; }
TransformComponent& SetScale(const glm::vec3& s) { scale = s; return *this; }
// 分量 → world 矩阵(T * R * S)
// SRT 分量 → world 矩阵(T * R * S)。
// 由 UpdateTransforms 每帧全量调用;勿在用户代码手动调用
TransformComponent& Compose()
{
const glm::mat4 t = glm::translate(glm::mat4(1.0f), position);
+5
View File
@@ -51,6 +51,11 @@ namespace Engine::ECS {
EntityHandle CreateEntity(std::string name = {});
void DestroyEntity(Entity e); // 延迟:帧尾统一销毁
void FlushDestroyQueue(); // 每帧末尾由 Application 调用
// 帧循环统一重算脏 transform 的 world 矩阵(UE transform-update
// 阶段模式)——由 Application 在 OnUpdate 之后、渲染之前调用,
// 用户代码永远不需要手动 Compose
void UpdateTransforms();
bool IsAlive(Entity e) const { return m_Registry.valid(e); }
// 按稳定 UUID 查实体(序列化/跨引用场景);找不到返回 entt::null