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 个断裂引用
This commit is contained in:
31
docs/api/resources/iloader/canload.md
Normal file
31
docs/api/resources/iloader/canload.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# IResourceLoader::CanLoad
|
||||
|
||||
```cpp
|
||||
bool CanLoad(const Containers::String& path) const
|
||||
```
|
||||
|
||||
检查此加载器是否能加载指定路径的资源。通过比对路径扩展名与支持列表判断。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
|
||||
**返回:** 如果扩展名在支持列表中则返回 true
|
||||
|
||||
**复杂度:** O(k),k 为扩展名数量
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
bool TextureLoader::CanLoad(const Containers::String& path) const {
|
||||
Containers::String ext = GetExtension(path);
|
||||
auto supported = GetSupportedExtensions();
|
||||
for (const auto& s : supported) {
|
||||
if (ext == s) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader 总览](iloader.md) - 返回类总览
|
||||
25
docs/api/resources/iloader/getdefaultsettings.md
Normal file
25
docs/api/resources/iloader/getdefaultsettings.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# IResourceLoader::GetDefaultSettings
|
||||
|
||||
```cpp
|
||||
ImportSettings* GetDefaultSettings() const = 0
|
||||
```
|
||||
|
||||
获取此加载器的默认导入设置。纯虚方法,子类返回其特有的默认设置实例。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 默认 `ImportSettings` 指针,调用者不持有所有权
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ImportSettings* TextureLoader::GetDefaultSettings() const {
|
||||
return new TextureImportSettings();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader 总览](iloader.md) - 返回类总览
|
||||
25
docs/api/resources/iloader/getsupportedextensions.md
Normal file
25
docs/api/resources/iloader/getsupportedextensions.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# IResourceLoader::GetSupportedExtensions
|
||||
|
||||
```cpp
|
||||
Containers::Array<Containers::String> GetSupportedExtensions() const
|
||||
```
|
||||
|
||||
获取此加载器支持的文件扩展名列表。用于 `CanLoad` 判断和编辑器中资源类型识别。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 支持的扩展名数组(如 `{".png", ".jpg", ".bmp"}`)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Containers::Array<Containers::String> TextureLoader::GetSupportedExtensions() const {
|
||||
return {".png", ".jpg", ".jpeg", ".bmp", ".tga", ".dds"};
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader 总览](iloader.md) - 返回类总览
|
||||
115
docs/api/resources/iloader/iloader.md
Normal file
115
docs/api/resources/iloader/iloader.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# IResourceLoader
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `class` (abstract)
|
||||
|
||||
**描述**: 资源加载器抽象接口,定义了资源加载的标准协议。每个资源类型需要提供对应的加载器实现。
|
||||
|
||||
## 概述
|
||||
|
||||
`IResourceLoader` 是资源加载系统的核心抽象接口。它定义了同步和异步加载资源的方法,以及资源类型的查询。`ResourceManager` 通过注册加载器来支持不同类型资源的加载。
|
||||
|
||||
## LoadResult 结构体
|
||||
|
||||
加载操作的返回值结构体。
|
||||
|
||||
```cpp
|
||||
struct LoadResult {
|
||||
IResource* resource = nullptr;
|
||||
bool success = false;
|
||||
Containers::String errorMessage;
|
||||
LoadResult() = default;
|
||||
explicit LoadResult(IResource* res) : resource(res), success(res != nullptr) {}
|
||||
explicit LoadResult(const Containers::String& error) : success(false), errorMessage(error) {}
|
||||
explicit LoadResult(bool inSuccess, const Containers::String& error = "")
|
||||
: success(inSuccess), errorMessage(error) {}
|
||||
operator bool() const { return success && resource != nullptr; }
|
||||
};
|
||||
```
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 资源信息
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `ResourceType GetResourceType() const` | 获取此加载器支持的资源类型 |
|
||||
| `Containers::Array<Containers::String> GetSupportedExtensions() const` | 获取支持的文件扩展名列表 |
|
||||
| `bool CanLoad(const Containers::String& path) const` | 检查此加载器是否能加载指定路径 |
|
||||
| `ImportSettings* GetDefaultSettings() const` | 获取默认导入设置 |
|
||||
|
||||
### 同步加载
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr)` | 同步加载资源 |
|
||||
|
||||
### 异步加载
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `void LoadAsync(const Containers::String& path, const ImportSettings* settings, std::function<void(LoadResult)> callback)` | 异步加载资源(内部默认实现调用同步 Load) |
|
||||
|
||||
### 辅助方法(受保护)
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static Containers::Array<Core::uint8> ReadFileData(const Containers::String& path)` | 读取文件数据 |
|
||||
| `static Containers::String GetExtension(const Containers::String& path)` | 获取文件扩展名 |
|
||||
|
||||
## 宏
|
||||
|
||||
### REGISTER_RESOURCE_LOADER
|
||||
|
||||
自动注册加载器到 ResourceManager 的宏。
|
||||
|
||||
```cpp
|
||||
REGISTER_RESOURCE_LOADER(TextureLoader)
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
class TextureLoader : public IResourceLoader {
|
||||
public:
|
||||
ResourceType GetResourceType() const override {
|
||||
return ResourceType::Texture;
|
||||
}
|
||||
|
||||
Containers::Array<Containers::String> GetSupportedExtensions() const override {
|
||||
return {".png", ".jpg", ".jpeg", ".bmp", ".tga"};
|
||||
}
|
||||
|
||||
bool CanLoad(const Containers::String& path) const override {
|
||||
Containers::String ext = GetExtension(path);
|
||||
return ext == ".png" || ext == ".jpg" || ext == ".bmp";
|
||||
}
|
||||
|
||||
ImportSettings* GetDefaultSettings() const override {
|
||||
return new TextureImportSettings();
|
||||
}
|
||||
|
||||
LoadResult Load(const Containers::String& path,
|
||||
const ImportSettings* settings = nullptr) override {
|
||||
LoadResult result;
|
||||
auto data = ReadFileData(path);
|
||||
if (data.Empty()) {
|
||||
return LoadResult("Failed to read file: " + path);
|
||||
}
|
||||
result.resource = new Texture();
|
||||
result.success = true;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// 注册加载器
|
||||
ResourceManager::Get().RegisterLoader(new TextureLoader());
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [AsyncLoader](../asyncloader/asyncloader.md) - 异步加载器
|
||||
- [ImportSettings](../importsettings/importsettings.md) - 导入设置
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
42
docs/api/resources/iloader/load.md
Normal file
42
docs/api/resources/iloader/load.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# IResourceLoader::Load
|
||||
|
||||
```cpp
|
||||
LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr)
|
||||
```
|
||||
|
||||
同步加载资源。纯虚方法,由具体加载器实现。从指定路径读取文件数据,解析为对应类型的资源对象。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源文件路径
|
||||
- `settings` - 可选的导入设置,用于自定义加载行为
|
||||
|
||||
**返回:** `LoadResult`,包含加载结果(资源指针、是否成功、错误信息等)
|
||||
|
||||
**复杂度:** O(n),取决于文件大小
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
LoadResult TextureLoader::Load(const Containers::String& path,
|
||||
const ImportSettings* settings) {
|
||||
LoadResult result;
|
||||
auto data = ReadFileData(path);
|
||||
if (data.Empty()) {
|
||||
result.errorMessage = "Failed to read file: " + path;
|
||||
return result;
|
||||
}
|
||||
Texture* tex = new Texture();
|
||||
if (!tex->LoadFromData(data.Data(), data.Size(), settings)) {
|
||||
delete tex;
|
||||
result.errorMessage = "Failed to parse texture data";
|
||||
return result;
|
||||
}
|
||||
result.resource = tex;
|
||||
result.success = true;
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader 总览](iloader.md) - 返回类总览
|
||||
34
docs/api/resources/iloader/loadasync.md
Normal file
34
docs/api/resources/iloader/loadasync.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# IResourceLoader::LoadAsync
|
||||
|
||||
```cpp
|
||||
void LoadAsync(const Containers::String& path, const ImportSettings* settings,
|
||||
std::function<void(LoadResult)> callback)
|
||||
```
|
||||
|
||||
异步加载资源。默认实现直接调用同步 `Load` 方法并在当前线程执行回调。子类可重写以实现真正的多线程异步加载。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `settings` - 导入设置(可为 nullptr)
|
||||
- `callback` - 加载完成回调函数
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
void AsyncTextureLoader::LoadAsync(const Containers::String& path,
|
||||
const ImportSettings* settings,
|
||||
std::function<void(LoadResult)> callback) {
|
||||
std::thread([this, path, settings, callback]() {
|
||||
LoadResult result = Load(path, settings);
|
||||
callback(result); // 回调可在工作线程执行
|
||||
}).detach();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader 总览](iloader.md) - 返回类总览
|
||||
Reference in New Issue
Block a user