docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
# ITask
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
|
|
|
|
|
**命名空间**: `XCEngine::Threading`
|
|
|
|
|
|
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
**类型**: `class` (abstract)
|
|
|
|
|
|
|
|
|
|
|
|
**头文件**: `XCEngine/Threading/Task.h`
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
|
|
|
|
|
**描述**: 任务基类抽象接口和任务状态/优先级枚举定义。
|
|
|
|
|
|
|
|
|
|
|
|
## 概述
|
|
|
|
|
|
|
|
|
|
|
|
`ITask` 是任务系统的核心抽象基类。用户需要继承此类并实现 `Execute()` 方法来定义具体的任务逻辑。任务系统通过引用计数自动管理任务生命周期。
|
|
|
|
|
|
|
|
|
|
|
|
## TaskPriority 枚举
|
|
|
|
|
|
|
|
|
|
|
|
任务优先级枚举(数值越小优先级越高)。
|
|
|
|
|
|
|
|
|
|
|
|
| 值 | 描述 |
|
|
|
|
|
|
|----|------|
|
|
|
|
|
|
| `Critical` | 关键优先级(0) |
|
|
|
|
|
|
| `High` | 高优先级(1) |
|
|
|
|
|
|
| `Normal` | 普通优先级(2) |
|
|
|
|
|
|
| `Low` | 低优先级(3) |
|
|
|
|
|
|
| `Idle` | 空闲优先级(4) |
|
|
|
|
|
|
|
|
|
|
|
|
## TaskStatus 枚举
|
|
|
|
|
|
|
|
|
|
|
|
任务状态枚举。
|
|
|
|
|
|
|
|
|
|
|
|
| 值 | 描述 |
|
|
|
|
|
|
|----|------|
|
|
|
|
|
|
| `Pending` | 等待中 |
|
|
|
|
|
|
| `Scheduled` | 已调度 |
|
|
|
|
|
|
| `Running` | 运行中 |
|
|
|
|
|
|
| `Completed` | 已完成 |
|
|
|
|
|
|
| `Failed` | 失败 |
|
|
|
|
|
|
| `Canceled` | 已取消 |
|
|
|
|
|
|
|
2026-03-19 02:01:18 +08:00
|
|
|
|
## 公共方法
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
|
|
|
|
|
| 方法 | 描述 |
|
|
|
|
|
|
|------|------|
|
2026-03-19 01:14:22 +08:00
|
|
|
|
| `virtual ~ITask()` | 虚析构函数 |
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
| [`Execute`](execute.md) | 任务执行逻辑(纯虚) |
|
docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.
math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.
memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)
core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md
debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md
All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00
|
|
|
|
| [`OnComplete`](on-complete.md) | 任务完成回调(可重写) |
|
|
|
|
|
|
| [`OnCancel`](on-cancel.md) | 任务取消回调(可重写) |
|
|
|
|
|
|
| [`GetPriority`](get-priority.md) | 获取优先级 |
|
|
|
|
|
|
| [`GetStatus`](get-status.md) | 获取状态 |
|
|
|
|
|
|
| [`GetId`](get-id.md) | 获取任务 ID |
|
|
|
|
|
|
| [`SetId`](set-id.md) | 设置任务 ID |
|
|
|
|
|
|
| [`SetPriority`](set-priority.md) | 设置优先级 |
|
|
|
|
|
|
| [`SetStatus`](set-status.md) | 设置状态 |
|
|
|
|
|
|
| [`AddRef`](add-ref.md) | 增加引用计数 |
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
| [`Release`](release.md) | 减少引用计数(引用归零时自动 delete) |
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:24 +08:00
|
|
|
|
## 受保护方法
|
|
|
|
|
|
|
|
|
|
|
|
| 方法 | 描述 |
|
|
|
|
|
|
|------|------|
|
|
|
|
|
|
| `ITask()` | 默认构造函数 |
|
|
|
|
|
|
| `ITask(TaskPriority priority)` | 带优先级的构造函数 |
|
|
|
|
|
|
|
2026-03-18 17:49:22 +08:00
|
|
|
|
## 使用示例
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
class MyTask : public ITask {
|
|
|
|
|
|
public:
|
|
|
|
|
|
explicit MyTask(int data) : m_data(data) {}
|
|
|
|
|
|
|
|
|
|
|
|
void Execute() override {
|
|
|
|
|
|
printf("Task executed with data: %d\n", m_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnComplete() override {
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
printf("Task completed\n");
|
2026-03-18 17:49:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
int m_data;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
auto task = new MyTask(42);
|
|
|
|
|
|
task->SetPriority(TaskPriority::High);
|
|
|
|
|
|
TaskSystem::Get().Submit(std::unique_ptr<ITask>(task));
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
|
2026-03-26 01:30:37 +08:00
|
|
|
|
- [LambdaTask](../lambda-task/lambda-task.md) - Lambda 任务封装
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
- [TaskGroup](../task-group/task-group.md) - 任务组
|
|
|
|
|
|
- [TaskSystem](../task-system/task-system.md) - 任务系统
|
2026-03-26 01:58:45 +08:00
|
|
|
|
- [../threading.md](../threading.md) - 模块总览
|