diff --git a/docs/blueprint-skill.md b/docs/blueprint-skill.md new file mode 100644 index 00000000..02c0cd24 --- /dev/null +++ b/docs/blueprint-skill.md @@ -0,0 +1,469 @@ +# XCEngine 蓝图文档编写与校验 Skill + +## 用途 + +根据 XCEngine C++ 引擎源码生成符合规范的蓝图文档(系统架构设计文档),用于在 XCSDD 中 +以 3D 可视化图谱方式展示系统的模块结构、子系统依赖关系和接口定义。 + +在开始编写任何蓝图文档之前,必须先完整阅读并深刻理解目标系统的源码上下文——包括设计目的、 +模块划分、依赖关系、数据流、边界条件等。切忌在未读懂系统架构的情况下仅凭目录结构或猜测 +来编写蓝图文档。 + +--- + +## 文档目录结构 + +``` +docs/ +├── blueprint.md # 蓝图总文档 +├── plan/ # 规划类文档 +└── api/ # API 文档(由 api-skill 管理) +``` + +**文件命名:** 蓝图文档统一命名为 `blueprint.md`,放在 `docs/` 目录下。 + +--- + +## 文档整体结构 + +蓝图文档由多个 YAML 代码块通过 Markdown 标题分隔组成,所有 YAML 代码块共同构成 +系统的完整蓝图定义。文档结构如下: + +```markdown +# {系统名称} 蓝图 + +--- + +# SYSTEM_META + +```yaml +# 系统元信息 +``` + +--- + +# SYSTEM_STRUCTURE + +```yaml +# 系统结构定义(核心必填) +``` + +--- + +# EVOLUTION_MODE + +```yaml +# 演化模式 +``` + +--- + +# REQUIREMENTS + +```yaml +# 需求列表 +``` + +--- + +# MVS_DEFINITION + +```yaml +# 最小可行方案定义 +``` + +--- + +# DATA_MODELS + +```yaml +# 数据模型定义 +``` + +--- + +# EVOLUTION_PLAN + +```yaml +# 演化计划 +``` + +--- + +## 页面类型与模板 + +### 1. SYSTEM_META(元信息) + +SYSTEM_META 是整个蓝图文档的元信息区,必须完整填写。 + +```yaml +name: {系统名称} +version: {版本号} +type: {系统类型} +description: "{系统一句话描述}" +target_runtime: {目标运行时} +``` + +### 2. SYSTEM_STRUCTURE(系统结构)—— 核心必填 + +SYSTEM_STRUCTURE 定义系统的子系统和模块结构,是 XCSDD 3D 可视化的核心数据来源。 +`subsystems` 和 `modules` 两个数组都被解析为 3D 图谱节点,依赖关系(`depends_on`)被解析为连线。 + +```yaml +root: {根模块名} + +subsystems: + - name: {子系统名} + responsibilities: + - "{职责描述1}" + - "{职责描述2}" + provides: [{提供的接口1}, {提供的接口2}] + depends_on: [{依赖的子系统名}] + boundary: + inputs: [{输入}] + outputs: [{输出}] + +modules: + - name: {模块名} + parent_subsystem: {所属子系统名} + responsibility: "{模块职责描述}" + public_api: + - fn: {函数名} + params: + - name: {参数名} + type: {参数类型} + returns: type: {返回类型} +``` + +### 3. EVOLUTION_MODE(演化模式) + +```yaml +mode: {build|evolve|maintain} +description: "{模式描述}" +context: | + {多行上下文说明} +``` + +### 4. REQUIREMENTS(需求列表) + +```yaml +- id: {REQ-ID} + title: {需求标题} + description: "{需求描述}" + source: {user|constraint} + type: {functional|non-functional} + acceptance_criteria: + - "{验收标准1}" + priority: {P0|P1|P2} +``` + +### 5. MVS_DEFINITION(MVS 最小可行方案) + +```yaml +mvs_solutions: + - id: {MVS-ID} + name: {方案名称} + goal: "{目标描述}" + + verification_criteria: + - "{验证标准1}" + + scope: + - subsystem: {子系统名} + components: [{组件名}] + - external: [{外部依赖}] + + code_structure: + - file: {文件名} + purpose: "{文件用途}" + contains: + - "{包含的功能1}" + standalone: {true|false} + + integration_plan: + - step: "{集成步骤1}" + + status: {pending|in_progress|completed} +``` + +### 6. DATA_MODELS(数据模型) + +```yaml +- name: {模型名} + description: "{模型描述}" + fields: + - name: {字段名} + type: {类型} + default: {默认值} + constraints: {required|optional} +``` + +### 7. EVOLUTION_PLAN(演化计划) + +```yaml +fix_plan: + - issue_id: {BUG-ID} + description: "{问题描述}" + root_cause: "{根本原因}" + minimal_change: + - file: {文件路径} + verification: "{验证方法}" + +refactor_plan: + - target: "{重构目标}" + constraints: ["{约束条件}"] + steps: ["{步骤1}"] + +feature_plan: + - feature_id: {FEAT-ID} + name: "{功能名称}" + addition: "{功能描述}" + integration_point: "{集成点}" + steps: ["{步骤1}"] +``` + +--- + +## 元信息字段规范 + +### SYSTEM_META + +| 字段 | 必需 | 说明 | +|------|------|------| +| `name` | 是 | 系统名称,唯一标识 | +| `version` | 是 | 版本号,格式 x.y.z | +| `type` | 是 | 系统类型,如 `game-engine`、`web-framework`、`api-service` | +| `description` | 是 | 系统一句话功能描述 | +| `target_runtime` | 否 | 目标运行时,如 `C++17`、`WebAssembly`、`Python 3.10` | + +### SYSTEM_STRUCTURE + +#### subsystems 数组 + +| 字段 | 必需 | 说明 | +|------|------|------| +| `name` | 是 | 子系统名称,唯一标识 | +| `responsibilities` | 是 | 职责列表,至少 1 项 | +| `provides` | 是 | 提供的接口列表,表示该子系统对外暴露的能力 | +| `depends_on` | 是 | 依赖的子系统列表,引用的子系统必须存在 | +| `boundary` | 否 | 边界定义 | +| `boundary.inputs` | 否 | 该子系统的外部输入项 | +| `boundary.outputs` | 否 | 该子系统的外部输出项 | + +#### modules 数组 + +| 字段 | 必需 | 说明 | +|------|------|------| +| `name` | 是 | 模块名称,唯一标识 | +| `parent_subsystem` | 是 | 所属子系统名称,引用的子系统必须存在 | +| `responsibility` | 是 | 模块职责描述 | +| `public_api` | 是 | 公共 API 列表,至少 1 项 | +| `public_api[].fn` | 是 | 函数名 | +| `public_api[].params` | 是 | 参数列表 | +| `public_api[].params[].name` | 是 | 参数名 | +| `public_api[].params[].type` | 是 | 参数类型 | +| `public_api[].returns` | 否 | 返回值定义 | +| `public_api[].returns.type` | 是(当有 returns 时) | 返回类型 | + +### EVOLUTION_MODE + +| 字段 | 必需 | 说明 | +|------|------|------| +| `mode` | 是 | `build`(从零构建)、`evolve`(演进迭代)、`maintain`(维护修复) | +| `description` | 是 | 模式一句话描述 | +| `context` | 是 | 多行详细上下文说明,使用 `\|` 语法 | + +### REQUIREMENTS + +| 字段 | 必需 | 说明 | +|------|------|------| +| `id` | 是 | 需求 ID,格式 `REQ-XXX` | +| `title` | 是 | 需求标题,简短明确 | +| `description` | 是 | 需求详细描述 | +| `source` | 是 | `user`(用户需求)、`constraint`(约束条件) | +| `type` | 是 | `functional`(功能性)、`non-functional`(非功能性) | +| `acceptance_criteria` | 是 | 验收标准,至少 1 项 | +| `priority` | 是 | `P0`(关键,阻塞开发)、`P1`(重要)、`P2`(次要) | + +### MVS_DEFINITION + +| 字段 | 必需 | 说明 | +|------|------|------| +| `id` | 是 | MVS ID,格式 `MVS-XXX` | +| `name` | 是 | 最小可行方案名称 | +| `goal` | 是 | 目标描述 | +| `verification_criteria` | 是 | 验证标准,至少 1 项 | +| `scope` | 是 | 涉及范围(子系统 + 外部依赖) | +| `code_structure` | 是 | 代码结构文件列表,至少 1 项 | +| `code_structure[].file` | 是 | 文件名 | +| `code_structure[].purpose` | 是 | 文件用途描述 | +| `code_structure[].contains` | 是 | 包含的功能列表 | +| `code_structure[].standalone` | 是 | 是否独立可运行 | +| `integration_plan` | 是 | 集成计划步骤 | +| `status` | 是 | `pending`(待开始)、`in_progress`(进行中)、`completed`(已完成) | + +### DATA_MODELS + +| 字段 | 必需 | 说明 | +|------|------|------| +| `name` | 是 | 模型名称 | +| `description` | 是 | 模型描述 | +| `fields` | 是 | 字段列表 | +| `fields[].name` | 是 | 字段名 | +| `fields[].type` | 是 | 字段类型 | +| `fields[].default` | 否 | 默认值 | +| `fields[].constraints` | 否 | `required`(必填)或 `optional`(可选) | + +### EVOLUTION_PLAN + +| 字段 | 必需 | 说明 | +|------|------|------| +| `issue_id` | 是(在 fix_plan 项中) | 缺陷 ID,格式 `BUG-XXX` | +| `description` | 是 | 问题描述 | +| `root_cause` | 是(在 fix_plan 项中) | 根本原因 | +| `minimal_change` | 是(在 fix_plan 项中) | 最小修改文件列表 | +| `verification` | 是(在 fix_plan 项中) | 验证方法 | +| `target` | 是(在 refactor_plan 项中) | 重构目标 | +| `constraints` | 是(在 refactor_plan 项中) | 约束条件列表 | +| `steps` | 是(在 refactor_plan 项中) | 重构步骤列表 | +| `feature_id` | 是(在 feature_plan 项中) | 特性 ID,格式 `FEAT-XXX` | +| `name` | 是(在 feature_plan 项中) | 功能名称 | +| `addition` | 是(在 feature_plan 项中) | 功能描述 | +| `integration_point` | 是(在 feature_plan 项中) | 集成点 | + +--- + +## 必需章节规范 + +### SYSTEM_META + +1. `name` — 系统名称 +2. `version` — 版本号 +3. `type` — 系统类型 +4. `description` — 系统描述 +5. `target_runtime` — 目标运行时 + +### SYSTEM_STRUCTURE + +1. `root` — 根模块名 +2. `subsystems` — 子系统列表,每个子系统至少包含 name、responsibilities、provides、depends_on +3. `modules` — 模块列表,每个模块至少包含 name、parent_subsystem、responsibility、public_api + +### EVOLUTION_MODE + +1. `mode` — 演化模式 +2. `description` — 模式描述 +3. `context` — 详细上下文 + +### REQUIREMENTS + +每个需求项至少包含 id、title、description、source、type、acceptance_criteria、priority。 + +### MVS_DEFINITION + +每个 MVS 方案至少包含 id、name、goal、verification_criteria、scope、code_structure、integration_plan、status。 + +### DATA_MODELS + +每个数据模型至少包含 name、description、fields。 + +### EVOLUTION_PLAN + +fix_plan、refactor_plan、feature_plan 至少包含各自必需字段。 + +--- + +## 依赖关系规范 + +### 子系统依赖 + +- `subsystems[].depends_on` 中引用的子系统名称必须在 `subsystems` 数组中存在 +- 不允许循环依赖(A → B → A),应在校验阶段检测并报告 +- 每个子系统的 `provides` 接口应当被其他子系统的 `depends_on` 引用(强推荐) + +### 模块归属 + +- `modules[].parent_subsystem` 引用的子系统必须在 `subsystems` 数组中存在 + +--- + +## 命名规范 + +### 驼峰命名(必需) + +所有标识符(子系统名、模块名)必须使用**驼峰命名法**,严禁使用下划线分隔。 + +| 正确示例 | 错误示例 | +|---------|---------| +| `CoreTypes` | `Core_Types`、`CoreTypes_` | +| `MathVector` | `Math_Vector`、`mathvector` | +| `RHICommandList` | `RHI_CommandList`、`RHICommand_List` | +| `DebugLogger` | `Debug_Logger` | +| `ResourcesManager` | `Resources_Manager` | + +**规则:** +- 子系统名:`{子系统}{子模块}` 或直接 `{子系统}`(如 `Core`、`Math`、`RHI`) +- 模块名:`{子系统}{功能描述}`(如 `CoreTypes`、`MathVector`、`RHICommandList`) +- 若子系统名本身是多词组合(如 `RHI_D3D12`),模块名前缀应使用完整子系统名(如 `RHID3D12Device`) + +### ID 格式 + +| 对象 | ID 格式 | 示例 | +|------|---------|------| +| 需求 | `REQ-XXX` | `REQ-001`、`REQ-002` | +| MVS 方案 | `MVS-XXX` | `MVS-001`、`MVS-002` | +| 缺陷 | `BUG-XXX` | `BUG-001`、`BUG-002` | +| 特性 | `FEAT-XXX` | `FEAT-001`、`FEAT-002` | + +--- + +## 文档一致性检查 + +生成或修改蓝图文档时,需检查: + +1. **驼峰命名规范** — 所有子系统名和模块名必须使用驼峰命名,严禁下划线 +2. **SYSTEM_STRUCTURE 一致性** — `modules[].parent_subsystem` 引用的子系统必须存在 +3. **依赖关系一致性** — `subsystems[].depends_on` 引用的子系统必须存在,无循环依赖 +4. **命名唯一性** — `subsystems[].name` 和 `modules[].name` 在各自数组内唯一 +5. **ID 格式一致性** — 所有 ID 字段遵循统一格式(REQ-XXX、MVS-XXX 等) +6. **provides/depends_on 配对** — 子系统的对外接口最好被依赖方引用 +7. **MVS 与 REQUIREMENTS 关联** — MVS 的 scope 应覆盖对应 REQ 涉及的所有子系统 +8. **YAML 语法正确性** — YAML 代码块可正常解析,无缩进错误、无重复键 + +--- + +## 生成流程 + +> **核心原则:在动手写蓝图文档之前,必须先完整阅读并深刻理解系统源码上下文。** + +1. **阅读源码**:完整阅读目标系统的核心头文件和关键实现,理解设计目的、模块划分、 + 数据流、依赖关系、边界条件。不要只看目录结构就写蓝图。 +2. **识别子系统**:根据功能边界和依赖关系,划分子系统。每个子系统应有明确的职责边界 + 和对外接口。子系统划分不宜过粗(导致职责重叠)也不宜过细(导致过度碎片化)。 +3. **提取模块和接口**:从代码中提取核心模块及其 public API(函数签名、参数、返回值)。 +4. **构建依赖图**:分析子系统间的依赖关系,确保无循环依赖。 +5. **生成 SYSTEM_META**:填写系统元信息。 +6. **生成 SYSTEM_STRUCTURE**:构建 subsystems 和 modules,确保依赖关系准确。 +7. **生成 REQUIREMENTS**:从源码 TODO、BUG 注释、需求文档中提取需求。 +8. **生成 MVS_DEFINITION**:为关键功能生成最小可行方案,指导分阶段实现。 +9. **补充可选章节**:根据需要补充 DATA_MODELS 和 EVOLUTION_PLAN。 +10. **校验输出**:运行所有一致性检查,检查依赖关系和命名一致性。 +11. **输出报告**:列出生成内容、子系统划分理由、缺失信息和发现的问题。 + +--- + +## 使用示例 + +用户输入: +``` +为 XCEngine 生成蓝图文档 +``` + +AI 执行: +1. 扫描 XCEngine 源码目录,分析代码结构和模块划分 +2. 识别核心子系统(Core、Rendering、Physics、Resource、Scripting 等) +3. 提取各子系统的模块和 public API +4. 分析子系统间的依赖关系,构建依赖图 +5. 生成 `blueprint.md` 文件 +6. 运行校验检查 YAML 结构和依赖关系 +7. 输出报告:子系统划分理由、生成内容、缺失信息 diff --git a/docs/blueprint.md b/docs/blueprint.md new file mode 100644 index 00000000..190f76af --- /dev/null +++ b/docs/blueprint.md @@ -0,0 +1,1020 @@ +# XCEngine 蓝图 + +--- + +# SYSTEM_META + +```yaml +name: XCEngine +version: 0.1.0 +type: game-engine +description: "模块化的 C++17 游戏引擎,支持 D3D12 和 OpenGL 双图形后端" +target_runtime: C++17 +``` + +--- + +# SYSTEM_STRUCTURE + +```yaml +root: XCEngine + +subsystems: + - name: Core + responsibilities: + - "提供基础类型别名和断言机制" + - "实现引用计数智能指针" + - "提供线程安全的事件发布/订阅系统" + - "提供文件写入 RAII 封装" + provides: [RefCounted, Event, FileWriter, SmartPtr] + depends_on: [] + boundary: + inputs: [] + outputs: [类型系统] + + - name: Math + responsibilities: + - "实现向量、矩阵、四元数数学运算" + - "提供变换(Transform)层次组合" + - "实现几何基元(平面、球体、盒子、射线、视锥体)" + provides: [Vector, Matrix, Quaternion, Transform, Geometry] + depends_on: [Core] + boundary: + inputs: [Core 类型] + outputs: [数学计算结果] + + - name: Containers + responsibilities: + - "提供动态数组模板" + - "提供字符串处理功能" + - "提供基于开放寻址的哈希表" + provides: [Array, String, HashMap] + depends_on: [Core, Memory] + boundary: + inputs: [Core 类型] + outputs: [容器实例] + + - name: Memory + responsibilities: + - "定义内存分配器抽象接口" + - "实现线性分配器(栈式)" + - "实现池分配器(固定大小块)" + - "提供代理分配器(统计追踪)" + - "管理全局内存系统" + provides: [IAllocator, LinearAllocator, PoolAllocator, ProxyAllocator, MemoryManager] + depends_on: [Core] + boundary: + inputs: [分配请求] + outputs: [内存块] + + - name: Threading + responsibilities: + - "封装线程 RAII 管理" + - "提供互斥锁、自旋锁、读写锁" + - "实现任务系统和线程池" + - "支持任务依赖和优先级调度" + provides: [Thread, Mutex, TaskSystem, TaskGroup] + depends_on: [Core, Containers] + boundary: + inputs: [任务函数] + outputs: [执行结果] + + - name: Debug + responsibilities: + - "提供多层级分类日志系统" + - "支持多种日志输出目标(控制台、文件)" + - "实现性能分析器和 Chrome 追踪导出" + provides: [Logger, Profiler, ILogSink] + depends_on: [Core, Containers, Threading] + boundary: + inputs: [日志消息] + outputs: [日志输出] + + - name: Resources + responsibilities: + - "管理所有游戏资源的生命周期" + - "实现资源加载器框架和多种格式支持" + - "提供 LRU 缓存和内存预算控制" + - "支持异步加载和依赖图管理" + - "管理资源文件系统路径和资源包" + provides: [IResource, ResourceManager, ResourceHandle, AsyncLoader] + depends_on: [Core, Containers, Memory, Threading, Math, Debug] + boundary: + inputs: [资源路径] + outputs: [资源对象] + + - name: RHI + responsibilities: + - "抽象渲染硬件接口,统一不同图形 API" + - "封装 GPU 资源(缓冲区、纹理、着色器)" + - "提供命令列表录制和提交机制" + - "管理描述符堆和管线状态" + provides: [RHIDevice, RHIBuffer, RHITexture, RHIShader, RHICommandList] + depends_on: [Core] + boundary: + inputs: [渲染命令] + outputs: [GPU 调用] + + - name: RHI_D3D12 + responsibilities: + - "实现 DirectX 12 后端" + - "封装 D3D12 设备和资源" + - "管理描述符堆和根签名" + provides: [D3D12Device, D3D12Buffer, D3D12Texture] + depends_on: [Core, RHI] + boundary: + inputs: [RHI 调用] + outputs: [D3D12 API] + + - name: RHI_OpenGL + responsibilities: + - "实现 OpenGL 4.6+ 后端" + - "封装 OpenGL 设备和资源" + - "管理 VAO 和采样器状态" + provides: [OpenGLDevice, OpenGLBuffer, OpenGLTexture] + depends_on: [Core, RHI] + boundary: + inputs: [RHI 调用] + outputs: [OpenGL API] + +modules: + - name: CoreTypes + parent_subsystem: Core + responsibility: "定义基础类型别名(int8、uint32 等)和断言宏" + public_api: + - fn: Assert + params: + - name: condition + type: bool + - name: message + type: const char* + returns: type: void + + - name: CoreSmartPtr + parent_subsystem: Core + responsibility: "实现引用计数智能指针 Ref 和 UniqueRef" + public_api: + - fn: MakeRef + params: + - name: args + type: Args... + returns: type: Ref + - fn: MakeUnique + params: + - name: args + type: Args... + returns: type: UniqueRef + + - name: CoreEvent + parent_subsystem: Core + responsibility: "提供线程安全的事件发布/订阅系统" + public_api: + - fn: Subscribe + params: + - name: callback + type: std::function + returns: type: uint32 + - fn: Unsubscribe + params: + - name: id + type: uint32 + returns: type: void + - fn: Invoke + params: + - name: args + type: Args... + returns: type: void + + - name: MathVector + parent_subsystem: Math + responsibility: "实现 Vector2、Vector3、Vector4 及其运算" + public_api: + - fn: Dot + params: + - name: a + type: const Vector3& + - name: b + type: const Vector3& + returns: type: float + - fn: Cross + params: + - name: a + type: const Vector3& + - name: b + type: const Vector3& + returns: type: Vector3 + - fn: Normalize + params: + - name: v + type: const Vector3& + returns: type: Vector3 + - fn: Lerp + params: + - name: a + type: const Vector3& + - name: b + type: const Vector3& + - name: t + type: float + returns: type: Vector3 + + - name: MathMatrix + parent_subsystem: Math + responsibility: "实现 Matrix3x3、Matrix4x4 及其运算" + public_api: + - fn: Perspective + params: + - name: fov + type: float + - name: aspect + type: float + - name: near + type: float + - name: far + type: float + returns: type: Matrix4x4 + - fn: LookAt + params: + - name: eye + type: const Vector3& + - name: target + type: const Vector3& + - name: up + type: const Vector3& + returns: type: Matrix4x4 + - fn: Inverse + params: + - name: m + type: const Matrix4x4& + returns: type: Matrix4x4 + + - name: MathQuaternion + parent_subsystem: Math + responsibility: "实现四元数和旋转变换" + public_api: + - fn: FromAxisAngle + params: + - name: axis + type: const Vector3& + - name: angle + type: float + returns: type: Quaternion + - fn: FromEulerAngles + params: + - name: pitch + type: float + - name: yaw + type: float + - name: roll + type: float + returns: type: Quaternion + - fn: Slerp + params: + - name: a + type: const Quaternion& + - name: b + type: const Quaternion& + - name: t + type: float + returns: type: Quaternion + + - name: MathTransform + parent_subsystem: Math + responsibility: "实现位置/旋转/缩放变换层次" + public_api: + - fn: Translate + params: + - name: position + type: const Vector3& + returns: type: Transform& + - fn: Rotate + params: + - name: rotation + type: const Quaternion& + returns: type: Transform& + - fn: Scale + params: + - name: scale + type: const Vector3& + returns: type: Transform& + - fn: ToMatrix + returns: type: Matrix4x4 + + - name: MathGeometry + parent_subsystem: Math + responsibility: "实现几何基元(Plane、Sphere、Box、Ray、Frustum、AABB、OBB)" + public_api: + - fn: Intersects + params: + - name: ray + type: const Ray& + - name: sphere + type: const Sphere& + returns: type: bool + - fn: Contains + params: + - name: frustum + type: const Frustum& + - name: point + type: const Vector3& + returns: type: bool + + - name: ContainersArray + parent_subsystem: Containers + responsibility: "提供模板动态数组" + public_api: + - fn: push + params: + - name: value + type: const T& + returns: type: void + - fn: emplace + params: + - name: args + type: Args... + returns: type: T& + - fn: Size + returns: type: uint32 + + - name: ContainersString + parent_subsystem: Containers + responsibility: "提供字符串处理功能" + public_api: + - fn: Substring + params: + - name: start + type: uint32 + - name: length + type: uint32 + returns: type: String + - fn: Trim + returns: type: String + - fn: Find + params: + - name: str + type: const String& + returns: type: int32 + + - name: ContainersHashMap + parent_subsystem: Containers + responsibility: "提供基于开放寻址的哈希表" + public_api: + - fn: Insert + params: + - name: key + type: const K& + - name: value + type: const V& + returns: type: bool + - fn: Find + params: + - name: key + type: const K& + returns: type: Iterator + - fn: Remove + params: + - name: key + type: const K& + returns: type: bool + + - name: MemoryAllocators + parent_subsystem: Memory + responsibility: "实现线性分配器、池分配器、代理分配器" + public_api: + - fn: Allocate + params: + - name: size + type: size_t + returns: type: void* + - fn: Free + params: + - name: ptr + type: void* + returns: type: void + - fn: Clear + returns: type: void + + - name: MemoryManager + parent_subsystem: Memory + responsibility: "管理全局内存分配器和追踪统计" + public_api: + - fn: Get + returns: type: MemoryManager& + - fn: CreateLinearAllocator + params: + - name: size + type: size_t + returns: type: LinearAllocator + - fn: CreatePoolAllocator + params: + - name: blockSize + type: size_t + - name: blockCount + type: uint32 + returns: type: PoolAllocator + + - name: ThreadingPrimitives + parent_subsystem: Threading + responsibility: "提供线程、互斥锁、自旋锁、读写锁" + public_api: + - fn: Thread + params: + - name: func + type: std::function + returns: type: void + - fn: Lock + returns: type: void + - fn: Unlock + returns: type: void + + - name: ThreadingTaskSystem + parent_subsystem: Threading + responsibility: "实现任务调度和线程池" + public_api: + - fn: Get + returns: type: TaskSystem& + - fn: ParallelFor + params: + - name: begin + type: uint32 + - name: end + type: uint32 + - name: func + type: std::function + returns: type: void + - fn: Submit + params: + - name: task + type: ITask* + returns: type: void + - fn: Wait + returns: type: void + + - name: DebugLogger + parent_subsystem: Debug + responsibility: "提供多层级分类日志系统" + public_api: + - fn: Get + returns: type: Logger& + - fn: Log + params: + - name: category + type: const char* + - name: level + type: LogLevel + - name: message + type: const char* + returns: type: void + + - name: DebugProfiler + parent_subsystem: Debug + responsibility: "实现性能分析器" + public_api: + - fn: Get + returns: type: Profiler& + - fn: BeginSession + params: + - name: name + type: const char* + returns: type: void + - fn: EndSession + returns: type: void + - fn: ExportChromeTracing + params: + - name: path + type: const char* + returns: type: void + + - name: ResourcesIResource + parent_subsystem: Resources + responsibility: "定义资源基接口" + public_api: + - fn: GetType + returns: type: ResourceType + - fn: GetName + returns: type: const String& + - fn: GetPath + returns: type: const String& + - fn: GetGUID + returns: type: const ResourceGUID& + + - name: ResourcesManager + parent_subsystem: Resources + responsibility: "管理资源生命周期、加载、卸载" + public_api: + - fn: Get + returns: type: ResourceManager& + - fn: Load + params: + - name: path + type: const String& + returns: type: LoadResult + - fn: LoadAsync + params: + - name: path + type: const String& + - name: callback + type: std::function)> + returns: type: void + - fn: Unload + params: + - name: guid + type: const ResourceGUID& + returns: type: void + + - name: ResourcesLoaders + parent_subsystem: Resources + responsibility: "实现各类资源加载器" + public_api: + - fn: Load + params: + - name: path + type: const String& + returns: type: IResource* + - fn: GetSupportedExtensions + returns: type: Array + - fn: CanLoad + params: + - name: path + type: const String& + returns: type: bool + + - name: ResourcesFileSystem + parent_subsystem: Resources + responsibility: "管理资源路径和资源包" + public_api: + - fn: Get + returns: type: ResourceFileSystem& + - fn: RegisterLoader + params: + - name: loader + type: IResourceLoader* + returns: type: void + - fn: LoadPackage + params: + - name: path + type: const String& + returns: type: bool + + - name: RHIDevice + parent_subsystem: RHI + responsibility: "创建和管理 RHI 设备及资源" + public_api: + - fn: CreateBuffer + params: + - name: desc + type: const RHIBufferDesc& + returns: type: RHIBuffer* + - fn: CreateTexture + params: + - name: desc + type: const RHITextureDesc& + returns: type: RHITexture* + - fn: CreateShader + params: + - name: desc + type: const RHIShaderDesc& + returns: type: RHIShader* + - fn: CreateCommandList + returns: type: RHICommandList* + - fn: GetCapabilities + returns: type: const RHICapabilities& + + - name: RHICommandList + parent_subsystem: RHI + responsibility: "录制和提交图形命令" + public_api: + - fn: Draw + params: + - name: vertexCount + type: uint32 + - name: instanceCount + type: uint32 + returns: type: void + - fn: DrawIndexed + params: + - name: indexCount + type: uint32 + - name: instanceCount + type: uint32 + returns: type: void + - fn: Dispatch + params: + - name: x + type: uint32 + - name: y + type: uint32 + - name: z + type: uint32 + returns: type: void + - fn: SetPipelineState + params: + - name: state + type: RHIPipelineState* + returns: type: void + + - name: RHIFactory + parent_subsystem: RHI + responsibility: "静态工厂创建后端设备" + public_api: + - fn: CreateRHIDevice + params: + - name: type + type: RHIDeviceType + returns: type: RHIDevice* + + - name: RHIBuffer + parent_subsystem: RHI + responsibility: "封装 GPU 缓冲区" + public_api: + - fn: Map + params: + - name: offset + type: size_t + - name: size + type: size_t + returns: type: void* + - fn: Unmap + returns: type: void + + - name: RHITexture + parent_subsystem: RHI + responsibility: "封装 GPU 纹理" + public_api: + - fn: GetWidth + returns: type: uint32 + - fn: GetHeight + returns: type: uint32 + - fn: GetFormat + returns: type: PixelFormat +``` + +--- + +# EVOLUTION_MODE + +```yaml +mode: build +description: "XCEngine 处于早期构建阶段,核心基础设施正在逐步完善" +context: | + XCEngine 是一个正在开发中的游戏引擎项目,当前版本 0.1.0 专注于建立核心基础设施。 + 核心模块(Core、Math、Containers、Memory)已基本完成,提供了游戏引擎所需的基础构建块。 + + 渲染系统(RHI)已完成双后端支持(D3D12 和 OpenGL),但高级渲染特性(如光线追踪、 + 网格着色器)尚未实现。 + + 资源管理系统(Resources)已具备完整的加载框架,支持异步加载、缓存和依赖管理, + 但仅支持基础格式(纹理、网格、着色器)。 + + 缺少的子系统:物理系统、脚本系统、实体组件系统(ECS)、音频系统、UI 系统。 + 这些将在后续迭代中逐步添加。 +``` + +--- + +# REQUIREMENTS + +- id: REQ-001 + title: "核心数学库完善" + description: "扩展数学库以支持 SIMD 优化,提供更高效的向量/矩阵运算" + source: user + type: non-functional + acceptance_criteria: + - "向量运算支持 SSE/AVX 加速" + - "矩阵运算支持 SIMD 优化" + - "性能基准测试显示 2x 以上的性能提升" + priority: P1 + +- id: REQ-002 + title: "资源系统扩展" + description: "增加更多资源格式支持,包括音频、动画、骨骼网格" + source: user + type: functional + acceptance_criteria: + - "支持 WAV 音频加载" + - "支持 glTF 格式模型导入" + - "支持骨骼动画数据" + priority: P1 + +- id: REQ-003 + title: "异步任务系统增强" + description: "支持任务优先级、任务亲和性、任务追踪" + source: user + type: functional + acceptance_criteria: + - "支持高/中/低三档任务优先级" + - "支持将任务分配到特定线程" + - "提供任务执行状态查询接口" + priority: P2 + +- id: REQ-004 + title: "内存追踪和泄漏检测" + description: "增强内存管理器,提供分配追踪和泄漏检测功能" + source: user + type: non-functional + acceptance_criteria: + - "记录每次分配的调用栈" + - "检测并报告内存泄漏" + - "生成内存使用报告" + priority: P1 + +- id: REQ-005 + title: "渲染管线扩展" + description: "增加 Compute Shader 支持、GPU 驱动的剔除、延迟渲染管线" + source: user + type: functional + acceptance_criteria: + - "支持 Compute Shader 执行" + - "实现视锥体剔除" + - "提供延迟渲染模板" + priority: P2 + +- id: REQ-006 + title: "日志系统国际化" + description: "支持多语言日志输出" + source: user + type: functional + acceptance_criteria: + - "支持日志消息参数化" + - "支持格式化字符串" + - "提供本地化接口" + priority: P2 + +--- + +# MVS_DEFINITION + +```yaml +mvs_solutions: + - id: MVS-001 + name: "SIMD 数学优化" + goal: "为数学库添加 SIMD 加速,提升渲染和物理计算性能" + verification_criteria: + - "矩阵乘法性能提升 2x 以上" + - "向量点积/叉积性能提升 2x 以上" + - "不破坏现有 API 兼容性" + scope: + - subsystem: Math + components: [Vector, Matrix, Quaternion] + - external: [SSE4.2, AVX2] + code_structure: + - file: "engine/include/XCEngine/Math/Vector3.inl" + purpose: "SIMD 向量实现" + contains: + - "SSE/AVX 向量运算内联函数" + - "跨平台 SIMD 选择宏" + standalone: true + - file: "engine/include/XCEngine/Math/Matrix4x4.inl" + purpose: "SIMD 矩阵实现" + contains: + - "SSE/AVX 矩阵乘法" + - "SIMD 矩阵求逆" + standalone: true + integration_plan: + - step: "定义 SIMD 抽象层选择宏(XC_USE_SSE/AVX)" + - step: "在 Vector3.h 中引入条件编译的 SIMD 实现" + - step: "在 Matrix4x4.h 中引入 SIMD 乘法实现" + - step: "添加性能基准测试" + status: pending + + - id: MVS-002 + name: "音频资源加载器" + goal: "实现 WAV 格式音频加载,为后续音频系统打基础" + verification_criteria: + - "成功加载标准 WAV 文件" + - "正确解析音频参数(采样率、声道、位深)" + - "提供 AudioClip 资源对象" + scope: + - subsystem: Resources + components: [AudioLoader, AudioClip] + - external: [stb_vorbis, libwav] + code_structure: + - file: "engine/include/XCEngine/Resources/AudioClip.h" + purpose: "音频数据资源" + contains: + - "AudioClip 类定义" + - "音频格式枚举" + standalone: true + - file: "engine/src/Resources/AudioLoader.cpp" + purpose: "WAV 加载器实现" + contains: + - "WAV 文件解析" + - "音频数据解码" + standalone: false + integration_plan: + - step: "创建 AudioClip 资源类" + - step: "实现 WAV 解析器" + - step: "注册 AudioLoader 到 ResourceManager" + - step: "添加单元测试" + status: pending + + - id: MVS-003 + name: "内存泄漏检测器" + goal: "为 Memory 模块添加分配追踪和泄漏报告功能" + verification_criteria: + - "记录所有分配操作和调用栈" + - "在程序结束时输出泄漏报告" + - "支持泄漏检测白名单" + scope: + - subsystem: Memory + components: [AllocationTracker, MemoryReport] + - external: [DbgHelp.dll, walkmacros] + code_structure: + - file: "engine/include/XCEngine/Memory/AllocationTracker.h" + purpose: "分配追踪器" + contains: + - "AllocationTracker 单例" + - "调用栈记录器" + standalone: true + - file: "engine/src/Memory/AllocationTracker.cpp" + purpose: "追踪器实现" + contains: + - "DbgHelp 调用栈捕获" + - "泄漏检测算法" + standalone: false + integration_plan: + - step: "创建 AllocationTracker 类" + - step: "修改 ProxyAllocator 集成追踪器" + - step: "实现泄漏报告生成器" + - step: "在程序退出时自动输出报告" + status: pending +``` + +--- + +# DATA_MODELS + +```yaml +- name: ResourceHandle + description: "类型安全的资源智能指针,自动引用计数" + fields: + - name: m_resource + type: T* + default: nullptr + constraints: optional + - name: m_refCount + type: uint32* + default: nullptr + constraints: optional + +- name: ResourceGUID + description: "资源的全局唯一标识符,由路径哈希生成" + fields: + - name: m_hash + type: uint64 + default: 0 + constraints: required + +- name: LoadResult + description: "资源加载结果" + fields: + - name: success + type: bool + default: false + constraints: required + - name: resource + type: IResource* + default: nullptr + constraints: optional + - name: errorMessage + type: String + default: "" + constraints: optional + +- name: RHICapabilities + description: "GPU 硬件能力查询" + fields: + - name: raytracing + type: bool + default: false + constraints: optional + - name: meshShaders + type: bool + default: false + constraints: optional + - name: tessellation + type: bool + default: false + constraints: optional + - name: maxTextureSize + type: uint32 + default: 4096 + constraints: optional + +- name: Transform + description: "位置、旋转、缩放的三维变换" + fields: + - name: m_position + type: Vector3 + default: (0,0,0) + constraints: required + - name: m_rotation + type: Quaternion + default: identity + constraints: required + - name: m_scale + type: Vector3 + default: (1,1,1) + constraints: required + +- name: Frustum + description: "视锥体,用于裁剪检测" + fields: + - name: m_planes + type: Array + default: [] + constraints: required + - name: m_corners + type: Array + default: [] + constraints: required + +- name: IResource + description: "所有资源的基接口" + fields: + - name: m_type + type: ResourceType + constraints: required + - name: m_name + type: String + constraints: required + - name: m_path + type: String + constraints: required + - name: m_guid + type: ResourceGUID + constraints: required +``` + +--- + +# EVOLUTION_PLAN + +```yaml +fix_plan: + - issue_id: BUG-001 + description: "LinearAllocator Clear 后重新分配时可能返回重叠内存" + root_cause: "Clear 仅重置指针,未清理旧内存映射" + minimal_change: + - file: "engine/src/Memory/LinearAllocator.cpp" + verification: "连续 Clear 和分配,检查内存区域不重叠" + + - issue_id: BUG-002 + description: "Event 在多线程同时订阅/取消订阅时存在竞态条件" + root_cause: "订阅列表操作未加锁保护" + minimal_change: + - file: "engine/include/XCEngine/Core/Event.h" + verification: "压力测试多线程订阅场景,无崩溃和数据错误" + +refactor_plan: + - target: "统一内存分配接口" + constraints: + - "保持向后兼容" + - "不引入运行时开销" + steps: + - "提取 IAllocator 接口的最小子集" + - "将 MakeRef/MakeUnique 重构为使用分配器参数" + - "添加便捷宏 XE_NEW/T_XE_DELETE" + + - target: "RHI 资源状态转换自动化" + constraints: + - "保持性能" + - "兼容现有渲染器" + steps: + - "引入资源状态跟踪器" + - "自动插入转换 barriers" + - "暴露手动控制接口" + +feature_plan: + - feature_id: FEAT-001 + name: "实体组件系统(ECS)" + addition: "实现高性能 ECS 架构,支持 archetypes 和 query" + integration_point: "Engine 层,位于 Resources 和 Gameplay 之间" + steps: + - "定义 Component、Entity、World 接口" + - "实现 Archetype 存储" + - "实现 Query 系统" + - "集成到引擎主循环" + + - feature_id: FEAT-002 + name: "物理子系统" + addition: "集成物理引擎,支持刚体、碰撞体" + integration_point: "Core 层下方,独立子系统" + steps: + - "评估物理引擎集成(Bullet/PhysX)" + - "封装物理世界接口" + - "实现碰撞检测和响应" + - "集成到渲染管线" + + - feature_id: FEAT-003 + name: "脚本系统" + addition: "支持 Lua 脚本和自定义脚本语言绑定" + integration_point: "Core 层上方,独立子系统" + steps: + - "集成 Lua 虚拟机" + - "绑定核心引擎 API" + - "实现脚本组件" + - "支持热重载" +``` + +---