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:
26
docs/api/resources/filesystem/exists.md
Normal file
26
docs/api/resources/filesystem/exists.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# ResourceFileSystem::Exists
|
||||
|
||||
```cpp
|
||||
bool Exists(const Containers::String& relativePath) const
|
||||
```
|
||||
|
||||
检查资源文件是否存在。优先在归档包中查找,其次在目录中查找。
|
||||
|
||||
**参数:**
|
||||
- `relativePath` - 资源相对路径
|
||||
|
||||
**返回:** 如果存在则返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (ResourceFileSystem::Get().Exists("shaders/default.vert")) {
|
||||
// 文件存在...
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceFileSystem 总览](filesystem.md) - 返回类总览
|
||||
117
docs/api/resources/filesystem/filesystem.md
Normal file
117
docs/api/resources/filesystem/filesystem.md
Normal file
@@ -0,0 +1,117 @@
|
||||
# ResourceFileSystem
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `class`
|
||||
|
||||
**描述**: 资源文件系统,负责资源文件的查找、读取和虚拟文件系统(支持目录和归档包)管理。
|
||||
|
||||
## 概述
|
||||
|
||||
`ResourceFileSystem` 实现了虚拟资源文件系统,支持从多个目录和归档包(如 `.zip`、`.pak`)中查找和读取资源。它通过 `IArchive` 接口支持不同的归档格式,并提供资源信息缓存。
|
||||
|
||||
## 单例访问
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static ResourceFileSystem& Get()` | 获取单例实例 |
|
||||
|
||||
## IArchive 接口
|
||||
|
||||
抽象归档接口,用于封装单个归档包或目录的读取操作。
|
||||
|
||||
### 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `virtual bool Open(const Containers::String& path)` | 打开归档 |
|
||||
| `virtual void Close()` | 关闭归档 |
|
||||
| `virtual bool Read(const Containers::String& fileName, void* buffer, size_t size, size_t offset) const` | 从归档中读取文件 |
|
||||
| `virtual size_t GetSize(const Containers::String& fileName) const` | 获取文件大小 |
|
||||
| `virtual bool Exists(const Containers::String& fileName) const` | 检查文件是否存在 |
|
||||
| `virtual void Enumerate(const Containers::String& pattern, Containers::Array<Containers::String>& outFiles) const` | 枚举匹配的文件 |
|
||||
| `virtual bool IsValid() const` | 是否有效 |
|
||||
|
||||
## ResourceInfo 结构体
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `path` | `Containers::String` | 资源相对路径 |
|
||||
| `size` | `size_t` | 文件大小(字节) |
|
||||
| `modifiedTime` | `Core::uint64` | 修改时间戳 |
|
||||
| `inArchive` | `bool` | 是否在归档包中 |
|
||||
| `archivePath` | `Containers::String` | 所属归档路径 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `void Initialize(const Containers::String& rootPath)` | 初始化,设置资源根目录 |
|
||||
| `void Shutdown()` | 关闭,释放所有归档 |
|
||||
|
||||
### 归档和目录管理
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool AddArchive(const Containers::String& archivePath)` | 添加归档包(优先查找) |
|
||||
| `bool AddDirectory(const Containers::String& directoryPath)` | 添加资源目录 |
|
||||
| `void RemoveArchive(const Containers::String& archivePath)` | 移除归档包 |
|
||||
|
||||
### 资源查找
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool FindResource(const Containers::String& relativePath, Containers::String& outAbsolutePath) const` | 查找资源的绝对路径 |
|
||||
| `bool Exists(const Containers::String& relativePath) const` | 检查资源是否存在 |
|
||||
| `Containers::Array<Core::uint8> ReadResource(const Containers::String& relativePath) const` | 读取资源文件内容(字节数组) |
|
||||
|
||||
### 资源信息
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool GetResourceInfo(const Containers::String& relativePath, ResourceInfo& outInfo) const` | 获取资源信息 |
|
||||
| `void EnumerateResources(const Containers::String& pattern, Containers::Array<ResourceInfo>& outResources) const` | 枚举匹配的资源 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
// 初始化资源文件系统
|
||||
ResourceFileSystem::Get().Initialize("resources/");
|
||||
|
||||
// 添加归档包(优先于目录)
|
||||
ResourceFileSystem::Get().AddArchive("data/resources.pak");
|
||||
|
||||
// 添加额外资源目录
|
||||
ResourceFileSystem::Get().AddDirectory("user_content/");
|
||||
|
||||
// 检查资源是否存在
|
||||
if (ResourceFileSystem::Get().Exists("textures/player.png")) {
|
||||
// 读取资源
|
||||
auto data = ResourceFileSystem::Get().ReadResource("textures/player.png");
|
||||
// 使用数据...
|
||||
}
|
||||
|
||||
// 获取资源信息
|
||||
ResourceInfo info;
|
||||
if (ResourceFileSystem::Get().GetResourceInfo("shaders/default.vert", info)) {
|
||||
printf("Size: %zu, InArchive: %s\n", info.size, info.inArchive ? "yes" : "no");
|
||||
}
|
||||
|
||||
// 枚举资源
|
||||
Containers::Array<ResourceInfo> textures;
|
||||
ResourceFileSystem::Get().EnumerateResources("textures/*.png", textures);
|
||||
for (const auto& tex : textures) {
|
||||
printf("Found: %s\n", tex.path.CStr());
|
||||
}
|
||||
|
||||
// 关闭
|
||||
ResourceFileSystem::Get().Shutdown();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [IResourceLoader](../iloader/iloader.md) - 资源加载器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
24
docs/api/resources/filesystem/initialize.md
Normal file
24
docs/api/resources/filesystem/initialize.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# ResourceFileSystem::Initialize
|
||||
|
||||
```cpp
|
||||
void Initialize(const Containers::String& rootPath)
|
||||
```
|
||||
|
||||
初始化资源文件系统。设置资源根目录,准备虚拟文件系统。
|
||||
|
||||
**参数:**
|
||||
- `rootPath` - 资源根目录路径
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceFileSystem::Get().Initialize("resources/");
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceFileSystem 总览](filesystem.md) - 返回类总览
|
||||
27
docs/api/resources/filesystem/readresource.md
Normal file
27
docs/api/resources/filesystem/readresource.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceFileSystem::ReadResource
|
||||
|
||||
```cpp
|
||||
Containers::Array<Core::uint8> ReadResource(const Containers::String& relativePath) const
|
||||
```
|
||||
|
||||
读取资源文件内容。优先从归档包中读取,其次从目录中查找。
|
||||
|
||||
**参数:**
|
||||
- `relativePath` - 资源相对路径
|
||||
|
||||
**返回:** 文件内容的字节数组,读取失败返回空数组
|
||||
|
||||
**复杂度:** O(n),n 为文件大小
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
auto data = ResourceFileSystem::Get().ReadResource("textures/player.png");
|
||||
if (!data.Empty()) {
|
||||
// 使用数据...
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceFileSystem 总览](filesystem.md) - 返回类总览
|
||||
Reference in New Issue
Block a user