feat: 引入 RenderGraph、Application 框架、ECS 与资产句柄系统
架构分层(自上而下):
App(SandboxApp) → Application(生命周期+事件) → Scene(ECS) / AssetManager(句柄) → Renderer → RenderGraph → Vulkan 模块
- RenderGraph:声明式帧图。虚拟资源+生成号句柄、死 pass 剔除、
拓扑排序、资源生命周期、barrier 编译期预算(Synchronization2)、
物理镜像池按帧槽位隔离(帧间竞争从根上消除)
- 帧同步修复:per-frame-slot 命令缓冲与 UBO ring(原先单份存在
数据竞争);统一 kMaxFramesInFlight / FrameContext
- Application:生命周期钩子(OnInit/OnUpdate/OnRender/OnShutdown)
+ 事件系统(GLFW 回调 → POD 事件 → 类型化钩子);main 只 new 派生类
- ECS:自研稀疏集 Registry(Entity=(index,generation) 防悬空,
O(1) 增删查,Each 取最小池遍历);Scene 延迟销毁队列;
IdComponent{UUID} 稳定外部身份
- Assets:AssetManager + AssetHandle。组件存句柄不存裸指针/Ref
(单一所有者 + 多使用者),Renderer 删除 LoadModel 改为纯消费
- 修复退出析构:成员析构前 GPU waitIdle(资产层先于 Renderer
析构导致 VUID-00922 资源销毁时仍在使用)
- 引入 entt 子模块备用
validation 全程零错误零警告(RTX 5060 实测)
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Created by atdunbg on 2026/9/22.
|
||||
//
|
||||
|
||||
#include <Engine/Renderer/Camera.h>
|
||||
#include <Engine/Core/Window.h>
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
namespace Engine {
|
||||
|
||||
void Camera::Update(Window& window, f32 deltaTime)
|
||||
{
|
||||
// 鼠标旋转(需显式启用,配合 cursor capture 使用)
|
||||
if (m_MouseLookEnabled)
|
||||
{
|
||||
f32 mouseDX = 0, mouseDY = 0;
|
||||
window.GetMouseDelta(mouseDX, mouseDY);
|
||||
|
||||
if (mouseDX != 0 || mouseDY != 0)
|
||||
{
|
||||
m_Yaw += mouseDX * m_MouseSensitivity;
|
||||
m_Pitch -= mouseDY * m_MouseSensitivity;
|
||||
m_Pitch = glm::clamp(m_Pitch, -89.0f, 89.0f);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateBasis();
|
||||
|
||||
f32 speed = m_MoveSpeed * deltaTime;
|
||||
if (window.IsKeyPressed(GLFW_KEY_W)) m_Position += m_Forward * speed;
|
||||
if (window.IsKeyPressed(GLFW_KEY_S)) m_Position -= m_Forward * speed;
|
||||
if (window.IsKeyPressed(GLFW_KEY_A)) m_Position -= m_Right * speed;
|
||||
if (window.IsKeyPressed(GLFW_KEY_D)) m_Position += m_Right * speed;
|
||||
if (window.IsKeyPressed(GLFW_KEY_SPACE)) m_Position.y += speed;
|
||||
if (window.IsKeyPressed(GLFW_KEY_LEFT_SHIFT)) m_Position.y -= speed;
|
||||
}
|
||||
|
||||
void Camera::UpdateBasis()
|
||||
{
|
||||
m_Forward.x = cosf(glm::radians(m_Yaw)) * cosf(glm::radians(m_Pitch));
|
||||
m_Forward.y = sinf(glm::radians(m_Pitch));
|
||||
m_Forward.z = sinf(glm::radians(m_Yaw)) * cosf(glm::radians(m_Pitch));
|
||||
m_Forward = glm::normalize(m_Forward);
|
||||
|
||||
m_Right = glm::normalize(glm::cross(m_Forward, glm::vec3(0, 1, 0)));
|
||||
m_Up = glm::normalize(glm::cross(m_Right, m_Forward));
|
||||
}
|
||||
|
||||
glm::mat4 Camera::GetView() const
|
||||
{
|
||||
return glm::lookAt(m_Position, m_Position + m_Forward, m_Up);
|
||||
}
|
||||
|
||||
glm::mat4 Camera::GetProjection(f32 aspect, f32 nearZ, f32 farZ) const
|
||||
{
|
||||
auto proj = glm::perspective(glm::radians(45.0f), aspect, nearZ, farZ);
|
||||
proj[1][1] *= -1.0f; // Vulkan Y 翻转
|
||||
return proj;
|
||||
}
|
||||
|
||||
} // namespace Engine
|
||||
Reference in New Issue
Block a user