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
+8 -13
View File
@@ -14,9 +14,8 @@ namespace Engine {
void Camera::Update(Window& window, ECS::TransformComponent& t, f32 deltaTime)
{
bool dirty = false;
// 鼠标旋转:直接写实体旋转(yaw → rotation.y,pitch → rotation.x)
// 鼠标旋转:直接写实体旋转(yaw → rotation.y,pitch → rotation.x)。
// Set*/成员写后由帧循环的 UpdateTransforms 统一 Compose
if (m_MouseLookEnabled)
{
f32 mouseDX = 0, mouseDY = 0;
@@ -27,7 +26,6 @@ namespace Engine {
t.rotation.y += mouseDX * m_MouseSensitivity;
t.rotation.x = glm::clamp(
t.rotation.x - mouseDY * m_MouseSensitivity, -89.0f, 89.0f);
dirty = true;
}
}
@@ -42,15 +40,12 @@ namespace Engine {
const glm::vec3 right = r * glm::vec3(1, 0, 0);
f32 speed = m_MoveSpeed * deltaTime;
if (window.IsKeyPressed(GLFW_KEY_W)) { t.position += forward * speed; dirty = true; }
if (window.IsKeyPressed(GLFW_KEY_S)) { t.position -= forward * speed; dirty = true; }
if (window.IsKeyPressed(GLFW_KEY_A)) { t.position -= right * speed; dirty = true; }
if (window.IsKeyPressed(GLFW_KEY_D)) { t.position += right * speed; dirty = true; }
if (window.IsKeyPressed(GLFW_KEY_SPACE)) { t.position.y += speed; dirty = true; }
if (window.IsKeyPressed(GLFW_KEY_LEFT_SHIFT)) { t.position.y -= speed; dirty = true; }
// 世界矩阵供 GetView(inverse)与渲染消费
if (dirty) t.Compose();
if (window.IsKeyPressed(GLFW_KEY_W)) { t.position += forward * speed; }
if (window.IsKeyPressed(GLFW_KEY_S)) { t.position -= forward * speed; }
if (window.IsKeyPressed(GLFW_KEY_A)) { t.position -= right * speed; }
if (window.IsKeyPressed(GLFW_KEY_D)) { t.position += right * speed; }
if (window.IsKeyPressed(GLFW_KEY_SPACE)) { t.position.y += speed; }
if (window.IsKeyPressed(GLFW_KEY_LEFT_SHIFT)) { t.position.y -= speed; }
}
glm::mat4 Camera::GetView(const ECS::TransformComponent& t) const