feat: initial DX12 foundation framework

This commit is contained in:
SpecialX
2026-03-19 18:27:49 +08:00
commit 60f73b525d
70 changed files with 8993 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
# Transform 组件分析
## 组件职责
`Transform.*` 负责实体空间变换数据:
- 位置、旋转、朝向、缩放存储;
- 世界矩阵与逆矩阵计算;
- 脏标记记录与批量更新入口。
## 数据布局
`Transform.cpp` 采用并行数组SoA
- `positions / rotations / orientations / scales`
- `to_world / inv_world`
- `has_transform`:矩阵缓存有效位
- `changes_from_previous_frame`:逐帧脏标记
## 创建与绑定
`transform::create(init_info, entity)` 使用 `entity_id` 的索引位定位槽位:
- 若槽位已存在,覆写其数据并标记脏;
- 若槽位不存在,扩容所有并行数组;
- 返回 `transform::component{ transform_id{ entity.get_id() } }`
这说明 Transform 不维护独立 free list而是复用实体索引空间。
## 读写策略
- 写接口(`set_rotation/position/scale`)只改数据与脏标记;
- `get_transform_matrices` 在读取时按需计算矩阵;
- 通过 `has_transform` 避免重复矩阵重算。
## 批量更新机制
`transform::update(cache, count)` 接收 `component_cache` 数组:
- 每条 cache 带 `flags` 指示写哪些字段;
- 逐条落地到内部并行数组;
- 适配脚本系统“先缓存,后统一提交”的帧内流程。
## 设计特点
- 读取快:索引直达;
- 可批处理cache + flags
- 低耦合:外部通过句柄和 cache 交互,不直接暴露内部数组。