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:
@@ -28,6 +28,22 @@
|
||||
| `settings` | `ImportSettings*` | 导入设置(可为 nullptr) |
|
||||
| `requestId` | `Core::uint64` | 请求唯一标识符 |
|
||||
|
||||
### 构造方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LoadRequest()` | 默认构造 |
|
||||
| `LoadRequest(const Containers::String& p, ResourceType t, std::function<void(LoadResult)> cb, ImportSettings* s = nullptr)` | 从参数构造 |
|
||||
| `LoadRequest(LoadRequest&& other) noexcept` | 移动构造 |
|
||||
| `LoadRequest(const LoadRequest&) = default` | 拷贝构造 |
|
||||
|
||||
### 赋值
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LoadRequest& operator=(LoadRequest&& other) noexcept` | 移动赋值 |
|
||||
| `LoadRequest& operator=(const LoadRequest&) = default` | 拷贝赋值 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
@@ -95,5 +111,6 @@ AsyncLoader::Get().Shutdown();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResourceLoader](./resources-iloader.md) - 资源加载器接口
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [IResourceLoader](../iloader/iloader.md) - 资源加载器接口
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
26
docs/api/resources/asyncloader/cancelall.md
Normal file
26
docs/api/resources/asyncloader/cancelall.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# AsyncLoader::CancelAll
|
||||
|
||||
```cpp
|
||||
void CancelAll()
|
||||
```
|
||||
|
||||
取消所有待处理的加载请求。清空待处理队列,不会触发任何回调。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 场景切换时取消所有加载请求
|
||||
void OnSceneChange() {
|
||||
AsyncLoader::Get().CancelAll();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AsyncLoader 总览](asyncloader.md) - 返回类总览
|
||||
24
docs/api/resources/asyncloader/getprogress.md
Normal file
24
docs/api/resources/asyncloader/getprogress.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# AsyncLoader::GetProgress
|
||||
|
||||
```cpp
|
||||
float GetProgress() const
|
||||
```
|
||||
|
||||
获取整体加载进度。返回已完成加载数与总请求数的比值,范围 0.0f ~ 1.0f。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 加载进度(0.0f ~ 1.0f)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
float progress = AsyncLoader::Get().GetProgress();
|
||||
printf("Loading: %.1f%%\n", progress * 100.0f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AsyncLoader 总览](asyncloader.md) - 返回类总览
|
||||
35
docs/api/resources/asyncloader/submit.md
Normal file
35
docs/api/resources/asyncloader/submit.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# AsyncLoader::Submit
|
||||
|
||||
```cpp
|
||||
void Submit(const Containers::String& path, ResourceType type,
|
||||
std::function<void(LoadResult)> callback)
|
||||
void Submit(const Containers::String& path, ResourceType type, ImportSettings* settings,
|
||||
std::function<void(LoadResult)> callback)
|
||||
```
|
||||
|
||||
提交异步加载请求。将请求加入待处理队列,由工作线程在后台执行加载。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `type` - 资源类型
|
||||
- `settings` - 导入设置(可为 nullptr)
|
||||
- `callback` - 加载完成回调
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
AsyncLoader::Get().Submit("textures/player.png", ResourceType::Texture,
|
||||
[](LoadResult result) {
|
||||
if (result.success) {
|
||||
ResourceHandle<Texture> tex(result.resource);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AsyncLoader 总览](asyncloader.md) - 返回类总览
|
||||
27
docs/api/resources/asyncloader/update.md
Normal file
27
docs/api/resources/asyncloader/update.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# AsyncLoader::Update
|
||||
|
||||
```cpp
|
||||
void Update()
|
||||
```
|
||||
|
||||
更新函数,在主线程调用。处理完成的加载请求,将结果从完成队列取出并在主线程执行回调。必须在主线程调用以确保线程安全。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),n 为完成队列中的请求数
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 在主循环中调用
|
||||
while (running) {
|
||||
AsyncLoader::Get().Update(); // 分发完成的加载回调
|
||||
RenderFrame();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AsyncLoader 总览](asyncloader.md) - 返回类总览
|
||||
@@ -127,5 +127,6 @@ bool loop = sfx->IsLoop();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
29
docs/api/resources/audioclip/setaudiodata.md
Normal file
29
docs/api/resources/audioclip/setaudiodata.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# AudioClip::SetAudioData
|
||||
|
||||
```cpp
|
||||
void SetAudioData(const Containers::Array<Core::uint8>& data)
|
||||
```
|
||||
|
||||
设置音频原始样本数据。
|
||||
|
||||
**参数:**
|
||||
- `data` - 音频数据字节数组
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
auto wavData = ResourceFileSystem::Get().ReadResource("sounds/explosion.wav");
|
||||
AudioClip* clip = new AudioClip();
|
||||
clip->SetAudioData(wavData);
|
||||
clip->SetSampleRate(44100);
|
||||
clip->SetChannels(2);
|
||||
clip->SetBitsPerSample(16);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AudioClip 总览](audioclip.md) - 返回类总览
|
||||
27
docs/api/resources/dependencygraph/adddependency.md
Normal file
27
docs/api/resources/dependencygraph/adddependency.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceDependencyGraph::AddDependency
|
||||
|
||||
```cpp
|
||||
void AddDependency(ResourceGUID owner, ResourceGUID dependency)
|
||||
```
|
||||
|
||||
添加资源依赖关系。表示 `owner` 资源依赖 `dependency` 资源。依赖关系是单向的。
|
||||
|
||||
**参数:**
|
||||
- `owner` - 拥有依赖关系的主体资源
|
||||
- `dependency` - 被依赖的资源
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// Material 依赖 Texture 和 Shader
|
||||
graph.AddDependency(materialGuid, textureGuid);
|
||||
graph.AddDependency(materialGuid, shaderGuid);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceDependencyGraph 总览](dependencygraph.md) - 返回类总览
|
||||
27
docs/api/resources/dependencygraph/addnode.md
Normal file
27
docs/api/resources/dependencygraph/addnode.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceDependencyGraph::AddNode
|
||||
|
||||
```cpp
|
||||
void AddNode(ResourceGUID guid, ResourceType type)
|
||||
```
|
||||
|
||||
向依赖图中添加一个新节点。如果节点已存在则忽略。
|
||||
|
||||
**参数:**
|
||||
- `guid` - 资源的全局唯一标识符
|
||||
- `type` - 资源类型
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceDependencyGraph graph;
|
||||
graph.AddNode(textureGuid, ResourceType::Texture);
|
||||
graph.AddNode(materialGuid, ResourceType::Material);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceDependencyGraph 总览](dependencygraph.md) - 返回类总览
|
||||
@@ -10,6 +10,16 @@
|
||||
|
||||
`ResourceDependencyGraph` 维护了所有资源之间的依赖关系图。它支持添加/移除依赖节点、查询依赖关系、循环依赖检测、拓扑排序(用于正确的加载/卸载顺序)等功能。
|
||||
|
||||
## DependencyNode 结构体
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `guid` | `ResourceGUID` | 资源全局唯一标识符 |
|
||||
| `type` | `ResourceType` | 资源类型 |
|
||||
| `dependencies` | `Containers::Array<ResourceGUID>` | 此资源依赖的其他资源 |
|
||||
| `dependents` | `Containers::Array<ResourceGUID>` | 依赖此资源的其他资源 |
|
||||
| `refCount` | `Core::uint32` | 引用计数 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 节点管理
|
||||
@@ -57,16 +67,6 @@
|
||||
|------|------|
|
||||
| `void Clear()` | 清空所有节点和依赖关系 |
|
||||
|
||||
## DependencyNode 结构体
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `guid` | `ResourceGUID` | 资源全局唯一标识符 |
|
||||
| `type` | `ResourceType` | 资源类型 |
|
||||
| `dependencies` | `Containers::Array<ResourceGUID>` | 此资源依赖的其他资源 |
|
||||
| `dependents` | `Containers::Array<ResourceGUID>` | 依赖此资源的其他资源 |
|
||||
| `refCount` | `Core::uint32` | 引用计数 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
@@ -106,5 +106,6 @@ graph.DecrementRefCount(guid);
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [ResourceHandle](./resources-resourcehandle.md) - 资源句柄
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [ResourceHandle](../resourcehandle/resourcehandle.md) - 资源句柄
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
25
docs/api/resources/dependencygraph/getdependencies.md
Normal file
25
docs/api/resources/dependencygraph/getdependencies.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# ResourceDependencyGraph::GetDependencies
|
||||
|
||||
```cpp
|
||||
Containers::Array<ResourceGUID> GetDependencies(ResourceGUID guid) const
|
||||
```
|
||||
|
||||
获取指定资源直接依赖的所有资源列表。不包含传递依赖。
|
||||
|
||||
**参数:**
|
||||
- `guid` - 资源全局唯一标识符
|
||||
|
||||
**返回:** 直接依赖的 GUID 数组
|
||||
|
||||
**复杂度:** O(k),k 为直接依赖数量
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
auto deps = graph.GetDependencies(materialGuid);
|
||||
// 返回 Material 直接依赖的资源(Texture、Shader 等)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceDependencyGraph 总览](dependencygraph.md) - 返回类总览
|
||||
31
docs/api/resources/dependencygraph/hascirculardependency.md
Normal file
31
docs/api/resources/dependencygraph/hascirculardependency.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# ResourceDependencyGraph::HasCircularDependency
|
||||
|
||||
```cpp
|
||||
bool HasCircularDependency(ResourceGUID guid, Containers::Array<ResourceGUID>& outCycle) const
|
||||
```
|
||||
|
||||
检测是否存在以指定节点为起点的循环依赖。使用 DFS 遍历依赖图,检测回路。
|
||||
|
||||
**参数:**
|
||||
- `guid` - 起始节点
|
||||
- `outCycle` - 输出参数,检测到的循环路径(包含形成环的节点 GUID)
|
||||
|
||||
**返回:** 如果存在循环依赖则返回 true,否则返回 false
|
||||
|
||||
**复杂度:** O(n + e)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Containers::Array<ResourceGUID> cycle;
|
||||
if (graph.HasCircularDependency(guid, cycle)) {
|
||||
printf("Circular dependency detected: ");
|
||||
for (const auto& g : cycle) {
|
||||
printf("%llu ", g.value);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceDependencyGraph 总览](dependencygraph.md) - 返回类总览
|
||||
28
docs/api/resources/dependencygraph/topologicalsort.md
Normal file
28
docs/api/resources/dependencygraph/topologicalsort.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# ResourceDependencyGraph::TopologicalSort
|
||||
|
||||
```cpp
|
||||
Containers::Array<ResourceGUID> TopologicalSort() const
|
||||
```
|
||||
|
||||
拓扑排序。按依赖顺序返回所有节点,确保被依赖的资源排在依赖者之前。用于确定正确的加载和卸载顺序。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 按依赖顺序排序的 GUID 数组
|
||||
|
||||
**复杂度:** O(n + e),n 为节点数,e 为边数
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
auto loadOrder = graph.TopologicalSort();
|
||||
// loadOrder[0] 是最底层依赖(如 Texture)
|
||||
// loadOrder[last] 是最顶层资源(如 Material)
|
||||
for (const auto& guid : loadOrder) {
|
||||
ResourceManager::Get().Load(guid);
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceDependencyGraph 总览](dependencygraph.md) - 返回类总览
|
||||
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) - 返回类总览
|
||||
@@ -10,6 +10,12 @@
|
||||
|
||||
`ResourceFileSystem` 实现了虚拟资源文件系统,支持从多个目录和归档包(如 `.zip`、`.pak`)中查找和读取资源。它通过 `IArchive` 接口支持不同的归档格式,并提供资源信息缓存。
|
||||
|
||||
## 单例访问
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static ResourceFileSystem& Get()` | 获取单例实例 |
|
||||
|
||||
## IArchive 接口
|
||||
|
||||
抽象归档接口,用于封装单个归档包或目录的读取操作。
|
||||
@@ -20,10 +26,10 @@
|
||||
|------|------|
|
||||
| `virtual bool Open(const Containers::String& path)` | 打开归档 |
|
||||
| `virtual void Close()` | 关闭归档 |
|
||||
| `virtual bool Read(fileName, buffer, size, offset)` | 从归档中读取文件 |
|
||||
| `virtual size_t GetSize(fileName)` | 获取文件大小 |
|
||||
| `virtual bool Exists(fileName)` | 检查文件是否存在 |
|
||||
| `virtual void Enumerate(pattern, outFiles)` | 枚举匹配的文件 |
|
||||
| `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 结构体
|
||||
@@ -36,12 +42,6 @@
|
||||
| `inArchive` | `bool` | 是否在归档包中 |
|
||||
| `archivePath` | `Containers::String` | 所属归档路径 |
|
||||
|
||||
## 单例访问
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static ResourceFileSystem& Get()` | 获取单例实例 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
@@ -63,22 +63,20 @@
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool FindResource(const Containers::String& relativePath, Containers::String& outAbsolutePath)` | 查找资源的绝对路径 |
|
||||
| `bool Exists(const Containers::String& relativePath)` | 检查资源是否存在 |
|
||||
| `Containers::Array<Core::uint8> ReadResource(const Containers::String& relativePath)` | 读取资源文件内容(字节数组) |
|
||||
| `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)` | 获取资源信息 |
|
||||
| `void EnumerateResources(const Containers::String& pattern, Containers::Array<ResourceInfo>& outResources)` | 枚举匹配的资源 |
|
||||
| `bool GetResourceInfo(const Containers::String& relativePath, ResourceInfo& outInfo) const` | 获取资源信息 |
|
||||
| `void EnumerateResources(const Containers::String& pattern, Containers::Array<ResourceInfo>& outResources) const` | 枚举匹配的资源 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Resources/ResourceFileSystem.h>
|
||||
|
||||
// 初始化资源文件系统
|
||||
ResourceFileSystem::Get().Initialize("resources/");
|
||||
|
||||
@@ -114,5 +112,6 @@ ResourceFileSystem::Get().Shutdown();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResourceLoader](./resources-iloader.md) - 资源加载器
|
||||
- [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) - 返回类总览
|
||||
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) - 返回类总览
|
||||
@@ -135,7 +135,7 @@
|
||||
|
||||
// 纹理导入设置
|
||||
TextureImportSettings texSettings;
|
||||
texSettings.SetTextureType(RHI::TextureType::Texture2D);
|
||||
texSettings.SetTextureType(TextureType::Texture2D);
|
||||
texSettings.SetGenerateMipmaps(true);
|
||||
texSettings.SetSRGB(true);
|
||||
texSettings.SetCompressionQuality(CompressionQuality::High);
|
||||
@@ -160,5 +160,6 @@ ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("model.fbx", &mesh
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResourceLoader](./resources-iloader.md) - 资源加载器
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResourceLoader](../iloader/iloader.md) - 资源加载器
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
34
docs/api/resources/iresource/initialize.md
Normal file
34
docs/api/resources/iresource/initialize.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# IResource::Initialize
|
||||
|
||||
```cpp
|
||||
void Initialize(const ConstructParams& params)
|
||||
```
|
||||
|
||||
使用构造参数初始化资源。将参数中的名称、路径、GUID 和内存大小写入对应成员变量,并将资源标记为有效状态。
|
||||
|
||||
**参数:**
|
||||
- `params` - 包含资源名称、路径、GUID 和内存大小的构造参数结构体
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
class MyResource : public IResource {
|
||||
public:
|
||||
MyResource() {
|
||||
ConstructParams params;
|
||||
params.name = "player_texture";
|
||||
params.path = "textures/player.png";
|
||||
params.guid = ResourceGUID::Generate(params.path);
|
||||
params.memorySize = 1024 * 1024; // 1MB
|
||||
Initialize(params);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle](./resources-resourcehandle.md) - 资源句柄
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [ResourceTypes](./resources-resourcetypes.md) - 资源类型定义
|
||||
- [ResourceHandle](../resourcehandle/resourcehandle.md) - 资源句柄
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [ResourceTypes](../resourcetypes/resourcetypes.md) - 资源类型定义
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
33
docs/api/resources/iresource/release.md
Normal file
33
docs/api/resources/iresource/release.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# IResource::Release
|
||||
|
||||
```cpp
|
||||
virtual void Release() = 0
|
||||
```
|
||||
|
||||
释放资源引用。纯虚方法,由具体资源类实现,用于执行资源特有的清理逻辑(如释放 GPU 资源、释放内存等)。在 `ResourceHandle` 析构或调用 `Reset()` 时会自动触发。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1) 或 O(n),取决于具体实现
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
class Texture : public IResource {
|
||||
public:
|
||||
void Release() override {
|
||||
if (m_rhiTexture) {
|
||||
m_rhiTexture->Release();
|
||||
m_rhiTexture = nullptr;
|
||||
}
|
||||
m_pixelData.Clear();
|
||||
m_isValid = false;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
28
docs/api/resources/iresource/setinvalid.md
Normal file
28
docs/api/resources/iresource/setinvalid.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# IResource::SetInvalid
|
||||
|
||||
```cpp
|
||||
void SetInvalid()
|
||||
```
|
||||
|
||||
将资源标记为无效状态。此方法用于在加载失败或资源损坏时将 `m_isValid` 设为 false,之后调用 `IsValid()` 将返回 false。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
void LoadFailed() {
|
||||
texture->SetInvalid();
|
||||
if (!texture->IsValid()) {
|
||||
// 处理资源无效情况
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
@@ -141,6 +141,7 @@ auto cbData = mat->GetConstantBufferData();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [Shader](./resources-shader.md) - 着色器资源
|
||||
- [Texture](./resources-texture.md) - 纹理资源
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [Shader](../shader/shader.md) - 着色器资源
|
||||
- [Texture](../texture/texture.md) - 纹理资源
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
27
docs/api/resources/material/setfloat.md
Normal file
27
docs/api/resources/material/setfloat.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Material::SetFloat
|
||||
|
||||
```cpp
|
||||
void SetFloat(const Containers::String& name, float value)
|
||||
```
|
||||
|
||||
设置材质浮点属性。
|
||||
|
||||
**参数:**
|
||||
- `name` - 属性名称
|
||||
- `value` - 属性值
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
mat->SetFloat("roughness", 0.5f);
|
||||
mat->SetFloat("metallic", 0.0f);
|
||||
mat->SetFloat("emissionStrength", 2.0f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Material 总览](material.md) - 返回类总览
|
||||
26
docs/api/resources/material/setshader.md
Normal file
26
docs/api/resources/material/setshader.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Material::SetShader
|
||||
|
||||
```cpp
|
||||
void SetShader(const ResourceHandle<Shader>& shader)
|
||||
```
|
||||
|
||||
设置材质使用的着色器。
|
||||
|
||||
**参数:**
|
||||
- `shader` - 着色器资源句柄
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Shader> vs = ResourceManager::Get().Load<Shader>("shaders/vertex.glsl");
|
||||
ResourceHandle<Shader> fs = ResourceManager::Get().Load<Shader>("shaders/fragment.glsl");
|
||||
mat->SetShader(vs);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Material 总览](material.md) - 返回类总览
|
||||
28
docs/api/resources/material/settexture.md
Normal file
28
docs/api/resources/material/settexture.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Material::SetTexture
|
||||
|
||||
```cpp
|
||||
void SetTexture(const Containers::String& name, const ResourceHandle<Texture>& texture)
|
||||
```
|
||||
|
||||
设置材质纹理属性。
|
||||
|
||||
**参数:**
|
||||
- `name` - 属性名称
|
||||
- `texture` - 纹理资源句柄
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> albedoTex = ResourceManager::Get().Load<Texture>("textures/albedo.png");
|
||||
ResourceHandle<Texture> normalTex = ResourceManager::Get().Load<Texture>("textures/normal.png");
|
||||
mat->SetTexture("albedoMap", albedoTex);
|
||||
mat->SetTexture("normalMap", normalTex);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Material 总览](material.md) - 返回类总览
|
||||
26
docs/api/resources/material/updateconstantbuffer.md
Normal file
26
docs/api/resources/material/updateconstantbuffer.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Material::UpdateConstantBuffer
|
||||
|
||||
```cpp
|
||||
void UpdateConstantBuffer()
|
||||
```
|
||||
|
||||
更新材质常量缓冲区。将所有属性值打包到常量缓冲区的二进制数据中,供 GPU 着色器使用。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),n 为属性数量
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
mat->SetFloat("roughness", 0.5f);
|
||||
mat->SetFloat3("albedo", Math::Vector3(1.0f, 0.8f, 0.6f));
|
||||
mat->UpdateConstantBuffer();
|
||||
auto cbData = mat->GetConstantBufferData();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Material 总览](material.md) - 返回类总览
|
||||
30
docs/api/resources/mesh/addsection.md
Normal file
30
docs/api/resources/mesh/addsection.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Mesh::AddSection
|
||||
|
||||
```cpp
|
||||
void AddSection(const MeshSection& section)
|
||||
```
|
||||
|
||||
添加网格分段(Submesh)。一个 Mesh 可以包含多个分段,每个分段对应一组索引和不同的材质。
|
||||
|
||||
**参数:**
|
||||
- `section` - 网格分段描述结构体
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
MeshSection section;
|
||||
section.baseVertex = 0;
|
||||
section.vertexCount = 1000;
|
||||
section.startIndex = 0;
|
||||
section.indexCount = 3000;
|
||||
section.materialID = 0;
|
||||
mesh->AddSection(section);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Mesh 总览](mesh.md) - 返回类总览
|
||||
@@ -143,6 +143,7 @@ auto sections = mesh->GetSections();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [Material](./resources-material.md) - 材质资源
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [Material](../material/material.md) - 材质资源
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
30
docs/api/resources/mesh/setindexdata.md
Normal file
30
docs/api/resources/mesh/setindexdata.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Mesh::SetIndexData
|
||||
|
||||
```cpp
|
||||
void SetIndexData(const void* data, size_t size, Core::uint32 indexCount, bool use32Bit)
|
||||
```
|
||||
|
||||
设置网格索引数据。复制索引缓冲数据到内部存储。
|
||||
|
||||
**参数:**
|
||||
- `data` - 索引数据指针
|
||||
- `size` - 数据大小(字节)
|
||||
- `indexCount` - 索引数量
|
||||
- `use32Bit` - 是否使用 32 位索引(否则使用 16 位)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),n 为索引数据大小
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Containers::Array<uint32_t> indices;
|
||||
// ... 填充索引数据 ...
|
||||
mesh->SetIndexData(indices.Data(), indices.Size() * sizeof(uint32_t),
|
||||
indices.Size(), true);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Mesh 总览](mesh.md) - 返回类总览
|
||||
37
docs/api/resources/mesh/setvertexdata.md
Normal file
37
docs/api/resources/mesh/setvertexdata.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Mesh::SetVertexData
|
||||
|
||||
```cpp
|
||||
void SetVertexData(const void* data, size_t size, Core::uint32 vertexCount,
|
||||
Core::uint32 vertexStride, VertexAttribute attributes)
|
||||
```
|
||||
|
||||
设置网格顶点数据。复制顶点缓冲数据到内部存储。
|
||||
|
||||
**参数:**
|
||||
- `data` - 顶点数据指针
|
||||
- `size` - 数据大小(字节)
|
||||
- `vertexCount` - 顶点数量
|
||||
- `vertexStride` - 单个顶点结构体大小(字节)
|
||||
- `attributes` - 顶点属性标志组合
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),n 为顶点数据大小
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
struct Vertex {
|
||||
float position[3];
|
||||
float normal[3];
|
||||
float uv[2];
|
||||
};
|
||||
|
||||
mesh->SetVertexData(vertices.Data(), vertices.Size() * sizeof(Vertex),
|
||||
vertexCount, sizeof(Vertex),
|
||||
VertexAttribute::Position | VertexAttribute::Normal | VertexAttribute::UV0);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Mesh 总览](mesh.md) - 返回类总览
|
||||
25
docs/api/resources/resourcecache/add.md
Normal file
25
docs/api/resources/resourcecache/add.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# ResourceCache::Add
|
||||
|
||||
```cpp
|
||||
void Add(ResourceGUID guid, IResource* resource)
|
||||
```
|
||||
|
||||
添加资源到缓存。将资源和 GUID 关联并记录内存大小、访问时间。线程安全。
|
||||
|
||||
**参数:**
|
||||
- `guid` - 资源全局唯一标识符
|
||||
- `resource` - 资源指针
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
cache.Add(guid, resource);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceCache 总览](resourcecache.md) - 返回类总览
|
||||
23
docs/api/resources/resourcecache/flush.md
Normal file
23
docs/api/resources/resourcecache/flush.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# ResourceCache::Flush
|
||||
|
||||
```cpp
|
||||
void Flush()
|
||||
```
|
||||
|
||||
清空缓存,释放所有资源。将所有缓存条目标记为待释放状态,调用每个资源的 `Release()` 方法。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
cache.Flush();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceCache 总览](resourcecache.md) - 返回类总览
|
||||
27
docs/api/resources/resourcecache/getlrulist.md
Normal file
27
docs/api/resources/resourcecache/getlrulist.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceCache::GetLRUList
|
||||
|
||||
```cpp
|
||||
Containers::Array<ResourceGUID> GetLRUList(size_t count) const
|
||||
```
|
||||
|
||||
获取最近最少使用的 GUID 列表。按 LRU 顺序返回前 `count` 个资源 GUID。
|
||||
|
||||
**参数:**
|
||||
- `count` - 要获取的 GUID 数量
|
||||
|
||||
**返回:** 最近最少使用的 GUID 数组
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
auto lruList = cache.GetLRUList(10);
|
||||
for (const auto& guid : lruList) {
|
||||
// 标记或处理这些资源...
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceCache 总览](resourcecache.md) - 返回类总览
|
||||
25
docs/api/resources/resourcecache/onmemorypressure.md
Normal file
25
docs/api/resources/resourcecache/onmemorypressure.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# ResourceCache::OnMemoryPressure
|
||||
|
||||
```cpp
|
||||
void OnMemoryPressure(size_t requiredBytes)
|
||||
```
|
||||
|
||||
内存压力回调。当系统内存紧张时调用此方法,从 LRU 列表头部开始驱逐资源,直到释放足够空间。
|
||||
|
||||
**参数:**
|
||||
- `requiredBytes` - 需要释放的字节数
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 需要 100MB 空间
|
||||
cache.OnMemoryPressure(100 * 1024 * 1024);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceCache 总览](resourcecache.md) - 返回类总览
|
||||
@@ -10,6 +10,26 @@
|
||||
|
||||
`ResourceCache` 实现了资源的内存缓存管理。它跟踪每个资源的访问时间和访问次数,在内存压力下自动驱逐最近最少使用的资源,确保内存使用不超过预算。
|
||||
|
||||
## CacheEntry 结构体
|
||||
|
||||
缓存条目结构体。
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `resource` | `IResource*` | 资源指针 |
|
||||
| `guid` | `ResourceGUID` | 全局唯一标识符 |
|
||||
| `memorySize` | `size_t` | 内存大小 |
|
||||
| `lastAccessTime` | `Core::uint64` | 上次访问时间戳 |
|
||||
| `accessCount` | `Core::uint32` | 访问次数 |
|
||||
|
||||
### 构造与静态方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `CacheEntry()` | 默认构造 |
|
||||
| `CacheEntry(IResource* res, size_t size)` | 从资源和大小构造 |
|
||||
| `static Core::uint64 GetCurrentTick()` | 获取当前时间戳 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
@@ -52,24 +72,6 @@
|
||||
|------|------|
|
||||
| `Containers::Array<ResourceGUID> GetLRUList(size_t count) const` | 获取最近最少使用的 GUID 列表 |
|
||||
|
||||
## CacheEntry 结构体
|
||||
|
||||
缓存条目结构体。
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `resource` | `IResource*` | 资源指针 |
|
||||
| `guid` | `ResourceGUID` | 全局唯一标识符 |
|
||||
| `memorySize` | `size_t` | 内存大小 |
|
||||
| `lastAccessTime` | `Core::uint64` | 上次访问时间戳 |
|
||||
| `accessCount` | `Core::uint32` | 访问次数 |
|
||||
|
||||
### 静态方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static Core::uint64 GetCurrentTick()` | 获取当前时间戳 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
@@ -94,5 +96,6 @@ auto lruList = cache.GetLRUList(10);
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
27
docs/api/resources/resourcecache/touch.md
Normal file
27
docs/api/resources/resourcecache/touch.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceCache::Touch
|
||||
|
||||
```cpp
|
||||
void Touch(ResourceGUID guid)
|
||||
```
|
||||
|
||||
更新资源的最近访问时间。当缓存条目被命中时调用,用于 LRU 驱逐算法判断资源的访问热度。
|
||||
|
||||
**参数:**
|
||||
- `guid` - 资源全局唯一标识符
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
IResource* res = cache.Find(guid);
|
||||
if (res) {
|
||||
cache.Touch(guid); // 更新 LRU
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceCache 总览](resourcecache.md) - 返回类总览
|
||||
27
docs/api/resources/resourcehandle/get.md
Normal file
27
docs/api/resources/resourcehandle/get.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceHandle::Get
|
||||
|
||||
```cpp
|
||||
T* Get() const
|
||||
```
|
||||
|
||||
获取资源裸指针。返回句柄内部持有的资源指针,不进行任何引用计数操作。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 资源裸指针,可能为 `nullptr`(当句柄为空时)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("tex.png");
|
||||
Texture* raw = tex.Get();
|
||||
if (raw != nullptr) {
|
||||
uint32_t w = raw->GetWidth();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle 总览](resourcehandle.md) - 返回类总览
|
||||
27
docs/api/resources/resourcehandle/getguid.md
Normal file
27
docs/api/resources/resourcehandle/getguid.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceHandle::GetGUID
|
||||
|
||||
```cpp
|
||||
ResourceGUID GetGUID() const
|
||||
```
|
||||
|
||||
获取资源的全局唯一标识符。如果内部指针为空,则返回一个值为 0 的空 GUID。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 资源的 `ResourceGUID`,如果句柄为空则返回 `ResourceGUID(0)`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("tex.png");
|
||||
ResourceGUID guid = tex.GetGUID();
|
||||
if (guid.IsValid()) {
|
||||
printf("GUID: %s\n", guid.ToString().CStr());
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle 总览](resourcehandle.md) - 返回类总览
|
||||
29
docs/api/resources/resourcehandle/isvalid.md
Normal file
29
docs/api/resources/resourcehandle/isvalid.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# ResourceHandle::IsValid
|
||||
|
||||
```cpp
|
||||
bool IsValid() const
|
||||
```
|
||||
|
||||
检查句柄是否持有有效资源。判断条件为:内部指针非空且资源的 `IsValid()` 返回 true。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 如果持有有效资源则返回 true,否则返回 false
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("tex.png");
|
||||
if (tex.IsValid()) {
|
||||
// 安全访问资源
|
||||
tex->GenerateMipmaps();
|
||||
} else {
|
||||
printf("Texture load failed!\n");
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle 总览](resourcehandle.md) - 返回类总览
|
||||
31
docs/api/resources/resourcehandle/reset.md
Normal file
31
docs/api/resources/resourcehandle/reset.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# ResourceHandle::Reset
|
||||
|
||||
```cpp
|
||||
void Reset()
|
||||
```
|
||||
|
||||
释放当前持有的资源引用。如果内部持有的资源指针非空,则调用 `ResourceManager::Release()` 减少引用计数,并将内部指针置为 `nullptr`。析构函数会自动调用此方法。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("tex.png");
|
||||
// 使用纹理...
|
||||
tex.Reset(); // 释放引用,引用计数 -1
|
||||
|
||||
// 或者让句柄离开作用域自动释放
|
||||
{
|
||||
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("model.fbx");
|
||||
// 使用网格...
|
||||
} // mesh 自动 Reset()
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle 总览](resourcehandle.md) - 返回类总览
|
||||
@@ -95,6 +95,7 @@ tex.Reset(); // 手动释放
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [ResourceCache](./resources-resourcecache.md) - 资源缓存
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [ResourceCache](../resourcecache/resourcecache.md) - 资源缓存
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
30
docs/api/resources/resourcehandle/swap.md
Normal file
30
docs/api/resources/resourcehandle/swap.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# ResourceHandle::Swap
|
||||
|
||||
```cpp
|
||||
void Swap(ResourceHandle& other)
|
||||
```
|
||||
|
||||
交换两个句柄持有的资源指针。使用 `std::swap` 交换内部指针,不会改变任何引用计数。此操作常用于在不影响引用计数的情况下安全地交换两个句柄的内容。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要交换的另一个 ResourceHandle 引用
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex1 = ResourceManager::Get().Load<Texture>("a.png");
|
||||
ResourceHandle<Texture> tex2 = ResourceManager::Get().Load<Texture>("b.png");
|
||||
|
||||
// 交换后 tex1 持有 b.png,tex2 持有 a.png
|
||||
tex1.Swap(tex2);
|
||||
|
||||
// 引用计数不变
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle 总览](resourcehandle.md) - 返回类总览
|
||||
28
docs/api/resources/resourcemanager/exists.md
Normal file
28
docs/api/resources/resourcemanager/exists.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# ResourceManager::Exists
|
||||
|
||||
```cpp
|
||||
bool Exists(const Containers::String& path) const
|
||||
bool Exists(ResourceGUID guid) const
|
||||
```
|
||||
|
||||
检查资源是否已加载。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `guid` - 资源全局唯一标识符
|
||||
|
||||
**返回:** 如果资源在缓存中则返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (ResourceManager::Get().Exists("textures/player.png")) {
|
||||
auto tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
29
docs/api/resources/resourcemanager/find.md
Normal file
29
docs/api/resources/resourcemanager/find.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# ResourceManager::Find
|
||||
|
||||
```cpp
|
||||
IResource* Find(const Containers::String& path)
|
||||
IResource* Find(ResourceGUID guid)
|
||||
```
|
||||
|
||||
在资源缓存中查找资源。返回裸指针,不增加引用计数。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `guid` - 资源全局唯一标识符
|
||||
|
||||
**返回:** 找到则返回资源指针,否则返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
IResource* res = ResourceManager::Get().Find("textures/player.png");
|
||||
if (res && res->IsValid()) {
|
||||
Texture* tex = static_cast<Texture*>(res);
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
27
docs/api/resources/resourcemanager/getloader.md
Normal file
27
docs/api/resources/resourcemanager/getloader.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ResourceManager::GetLoader
|
||||
|
||||
```cpp
|
||||
IResourceLoader* GetLoader(ResourceType type) const
|
||||
```
|
||||
|
||||
获取指定类型的资源加载器。
|
||||
|
||||
**参数:**
|
||||
- `type` - 资源类型
|
||||
|
||||
**返回:** 对应的加载器指针,未找到则返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
IResourceLoader* texLoader = ResourceManager::Get().GetLoader(ResourceType::Texture);
|
||||
if (texLoader) {
|
||||
auto extensions = texLoader->GetSupportedExtensions();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
32
docs/api/resources/resourcemanager/load.md
Normal file
32
docs/api/resources/resourcemanager/load.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# ResourceManager::Load
|
||||
|
||||
```cpp
|
||||
template<typename T>
|
||||
ResourceHandle<T> Load(const Containers::String& path, ImportSettings* settings = nullptr)
|
||||
```
|
||||
|
||||
同步加载资源。模板方法,根据路径生成 GUID,先在缓存中查找是否已加载;若未加载则查找对应类型的加载器并同步加载,然后将结果加入缓存。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `settings` - 导入设置(可选)
|
||||
|
||||
**返回:** `ResourceHandle<T>`,持有加载的资源
|
||||
|
||||
**复杂度:** O(n),取决于加载器实现
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
||||
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("models/player.fbx");
|
||||
ResourceHandle<Material> mat = ResourceManager::Get().Load<Material>("materials/player.mat");
|
||||
|
||||
if (tex.IsValid()) {
|
||||
// 使用纹理...
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
44
docs/api/resources/resourcemanager/loadasync.md
Normal file
44
docs/api/resources/resourcemanager/loadasync.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# ResourceManager::LoadAsync
|
||||
|
||||
```cpp
|
||||
void LoadAsync(const Containers::String& path, ResourceType type,
|
||||
std::function<void(LoadResult)> callback)
|
||||
void LoadAsync(const Containers::String& path, ResourceType type,
|
||||
ImportSettings* settings, std::function<void(LoadResult)> callback)
|
||||
```
|
||||
|
||||
异步加载资源。将加载请求提交到 `AsyncLoader`,在后台工作线程执行加载,完成后在主线程通过回调通知。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `type` - 资源类型
|
||||
- `settings` - 导入设置(可为 nullptr)
|
||||
- `callback` - 加载完成回调
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** 提交 O(1),实际加载 O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceManager::Get().LoadAsync("textures/terrain.png", ResourceType::Texture,
|
||||
[](LoadResult result) {
|
||||
if (result.success) {
|
||||
ResourceHandle<Texture> tex(result.resource);
|
||||
printf("Loaded: %s\n", tex->GetPath().CStr());
|
||||
}
|
||||
});
|
||||
|
||||
ResourceManager::Get().LoadAsync("models/player.fbx", ResourceType::Mesh,
|
||||
nullptr,
|
||||
[](LoadResult result) {
|
||||
if (result.success) {
|
||||
ResourceHandle<Mesh> mesh(result.resource);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
35
docs/api/resources/resourcemanager/loadgroup.md
Normal file
35
docs/api/resources/resourcemanager/loadgroup.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# ResourceManager::LoadGroup
|
||||
|
||||
```cpp
|
||||
template<typename T>
|
||||
void LoadGroup(const Containers::Array<Containers::String>& paths,
|
||||
std::function<void(ResourceHandle<T>)> callback)
|
||||
```
|
||||
|
||||
批量异步加载同类资源。为路径数组中的每个路径提交一个异步加载请求,所有加载完成时通过回调通知。
|
||||
|
||||
**参数:**
|
||||
- `paths` - 资源路径数组
|
||||
- `callback` - 每个资源加载完成时的回调
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(k),k 为路径数量(每个加载为 O(n))
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Containers::Array<Containers::String> texPaths = {
|
||||
"textures/a.png", "textures/b.png", "textures/c.png"
|
||||
};
|
||||
ResourceManager::Get().LoadGroup<Texture>(texPaths,
|
||||
[](ResourceHandle<Texture> tex) {
|
||||
if (tex.IsValid()) {
|
||||
printf("Loaded: %s\n", tex->GetPath().CStr());
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
26
docs/api/resources/resourcemanager/registerloader.md
Normal file
26
docs/api/resources/resourcemanager/registerloader.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# ResourceManager::RegisterLoader
|
||||
|
||||
```cpp
|
||||
void RegisterLoader(IResourceLoader* loader)
|
||||
```
|
||||
|
||||
注册资源加载器。管理器持有加载器指针所有权。
|
||||
|
||||
**参数:**
|
||||
- `loader` - 加载器实例指针
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceManager::Get().RegisterLoader(new TextureLoader());
|
||||
ResourceManager::Get().RegisterLoader(new MeshLoader());
|
||||
ResourceManager::Get().RegisterLoader(new MaterialLoader());
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
@@ -107,15 +107,6 @@
|
||||
| `Containers::Array<Containers::String> GetResourcePaths() const` | 获取所有已加载资源的路径列表 |
|
||||
| `void UnloadGroup(const Containers::Array<ResourceGUID>& guids)` | 按 GUID 批量卸载 |
|
||||
|
||||
## 私有方法(内部使用)
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `IResource* FindInCache(ResourceGUID guid)` | 在缓存中查找资源 |
|
||||
| `void AddToCache(ResourceGUID guid, IResource* resource)` | 添加到缓存 |
|
||||
| `IResourceLoader* FindLoader(ResourceType type)` | 查找加载器 |
|
||||
| `void ReloadResource(ResourceGUID guid)` | 重新加载资源 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
@@ -133,7 +124,7 @@ ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/pla
|
||||
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("models/player.fbx");
|
||||
|
||||
// 异步加载
|
||||
ResourceManager::Get().LoadAsync<Texture>("textures/terrain.png",
|
||||
ResourceManager::Get().LoadAsync("textures/terrain.png", ResourceType::Texture,
|
||||
[](LoadResult result) {
|
||||
if (result.success) {
|
||||
ResourceHandle<Texture> tex(result.resource);
|
||||
@@ -160,7 +151,8 @@ ResourceManager::Get().Shutdown();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceHandle](./resources-resourcehandle.md) - 资源句柄
|
||||
- [ResourceCache](./resources-resourcecache.md) - 资源缓存
|
||||
- [AsyncLoader](./resources-asyncloader.md) - 异步加载器
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [ResourceHandle](../resourcehandle/resourcehandle.md) - 资源句柄
|
||||
- [ResourceCache](../resourcecache/resourcecache.md) - 资源缓存
|
||||
- [AsyncLoader](../asyncloader/asyncloader.md) - 异步加载器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
24
docs/api/resources/resourcemanager/setmemorybudget.md
Normal file
24
docs/api/resources/resourcemanager/setmemorybudget.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# ResourceManager::SetMemoryBudget
|
||||
|
||||
```cpp
|
||||
void SetMemoryBudget(size_t bytes)
|
||||
```
|
||||
|
||||
设置资源管理的内存预算上限。当缓存中资源的总内存占用超过预算时,会触发 LRU 驱逐策略释放内存。
|
||||
|
||||
**参数:**
|
||||
- `bytes` - 内存预算大小(字节)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceManager::Get().SetMemoryBudget(1024 * 1024 * 1024); // 1GB 预算
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
31
docs/api/resources/resourcemanager/unload.md
Normal file
31
docs/api/resources/resourcemanager/unload.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# ResourceManager::Unload
|
||||
|
||||
```cpp
|
||||
void Unload(const Containers::String& path)
|
||||
void Unload(ResourceGUID guid)
|
||||
```
|
||||
|
||||
卸载指定资源。按路径或 GUID 查找资源,如果引用计数降至零则释放资源内存。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
- `guid` - 资源全局唯一标识符
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1) 查找
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 按路径卸载
|
||||
ResourceManager::Get().Unload("textures/player.png");
|
||||
|
||||
// 按 GUID 卸载
|
||||
ResourceGUID guid = tex.GetGUID();
|
||||
ResourceManager::Get().Unload(guid);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
26
docs/api/resources/resourcemanager/unloadunused.md
Normal file
26
docs/api/resources/resourcemanager/unloadunused.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# ResourceManager::UnloadUnused
|
||||
|
||||
```cpp
|
||||
void UnloadUnused()
|
||||
```
|
||||
|
||||
卸载所有无引用的资源。遍历资源缓存,将引用计数为零的资源全部释放。常在场景切换或内存紧张时调用。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 切换场景时清理无用资源
|
||||
void OnSceneUnload() {
|
||||
ResourceManager::Get().UnloadUnused();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager 总览](resourcemanager.md) - 返回类总览
|
||||
@@ -1,112 +0,0 @@
|
||||
# IResourceLoader
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `class` (abstract)
|
||||
|
||||
**描述**: 资源加载器抽象接口,定义了资源加载的标准协议。每个资源类型需要提供对应的加载器实现。
|
||||
|
||||
## 概述
|
||||
|
||||
`IResourceLoader` 是资源加载系统的核心抽象接口。它定义了同步和异步加载资源的方法,以及资源类型的查询和依赖信息的获取。`ResourceManager` 通过注册加载器来支持不同类型资源的加载。
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 资源信息
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `ResourceType GetResourceType() const` | 获取此加载器支持的资源类型 |
|
||||
| `const Containers::String& GetResourceTypeName() const` | 获取资源类型的字符串名称 |
|
||||
| `size_t GetResourceSize(const Containers::String& path) const` | 获取资源文件大小 |
|
||||
|
||||
### 同步加载
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LoadResult Load(const Containers::String& path, ImportSettings* settings)` | 同步加载资源 |
|
||||
| `bool Save(const Containers::String& path, IResource* resource)` | 保存资源到文件 |
|
||||
|
||||
### 异步加载
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LoadResult LoadAsync(const Containers::String& path, ImportSettings* settings)` | 异步加载资源(内部使用) |
|
||||
|
||||
### 依赖管理
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `Containers::Array<Containers::String> GetDependencies(const Containers::String& path) const` | 获取资源依赖的文件路径列表 |
|
||||
|
||||
### 资源操作
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool Reload(IResource* resource, const Containers::String& path)` | 重新加载资源 |
|
||||
| `void Unload(IResource* resource)` | 卸载资源 |
|
||||
|
||||
### 文件系统
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `bool Exists(const Containers::String& path) const` | 检查资源文件是否存在 |
|
||||
| `Containers::String ResolvePath(const Containers::String& relativePath) const` | 解析资源路径 |
|
||||
|
||||
## LoadResult 结构体
|
||||
|
||||
加载操作的返回值结构体。
|
||||
|
||||
```cpp
|
||||
struct LoadResult {
|
||||
IResource* resource = nullptr; // 加载的资源对象
|
||||
bool success = false; // 是否成功
|
||||
Containers::String errorMessage; // 错误信息
|
||||
size_t memorySize = 0; // 资源内存大小
|
||||
Containers::Array<Containers::String> dependencies; // 依赖列表
|
||||
};
|
||||
```
|
||||
|
||||
### 布尔转换
|
||||
|
||||
| 转换 | 描述 |
|
||||
|------|------|
|
||||
| `explicit operator bool() const` | `success == true` 时返回 true |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
class TextureLoader : public IResourceLoader {
|
||||
public:
|
||||
ResourceType GetResourceType() const override {
|
||||
return ResourceType::Texture;
|
||||
}
|
||||
|
||||
const Containers::String& GetResourceTypeName() const override {
|
||||
static Containers::String name = "Texture";
|
||||
return name;
|
||||
}
|
||||
|
||||
LoadResult Load(const Containers::String& path,
|
||||
ImportSettings* settings) override {
|
||||
LoadResult result;
|
||||
// 实现加载逻辑...
|
||||
result.success = true;
|
||||
result.resource = new Texture();
|
||||
return result;
|
||||
}
|
||||
|
||||
Containers::Array<Containers::String>
|
||||
GetDependencies(const Containers::String& path) const override {
|
||||
return {}; // 纹理通常无依赖
|
||||
}
|
||||
};
|
||||
|
||||
// 注册加载器
|
||||
ResourceManager::Get().RegisterLoader(new TextureLoader());
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [AsyncLoader](./resources-asyncloader.md) - 异步加载器
|
||||
@@ -1,101 +0,0 @@
|
||||
# ResourceTypes
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `enums` / `structs`
|
||||
|
||||
**描述**: 资源模块中使用的所有类型定义,包括资源类型枚举、GUID 结构体等。
|
||||
|
||||
## 概述
|
||||
|
||||
本文档汇总了 Resources 模块中的所有类型定义,包括资源类型枚举、GUID 结构体等基础类型。
|
||||
|
||||
---
|
||||
|
||||
## ResourceType
|
||||
|
||||
资源类型枚举。
|
||||
|
||||
| 值 | 描述 |
|
||||
|----|------|
|
||||
| `Unknown` | 未知类型 |
|
||||
| `Texture` | 纹理资源 |
|
||||
| `Mesh` | 网格/模型资源 |
|
||||
| `Material` | 材质资源 |
|
||||
| `Shader` | 着色器资源 |
|
||||
| `AudioClip` | 音频资源 |
|
||||
| `Binary` | 二进制数据 |
|
||||
| `AnimationClip` | 动画片段 |
|
||||
| `Skeleton` | 骨骼 |
|
||||
| `Font` | 字体 |
|
||||
| `ParticleSystem` | 粒子系统 |
|
||||
| `Scene` | 场景 |
|
||||
| `Prefab` | 预制体 |
|
||||
|
||||
---
|
||||
|
||||
## ResourceGUID
|
||||
|
||||
全局唯一标识符结构体,用于唯一标识每个资源。
|
||||
|
||||
```cpp
|
||||
struct ResourceGUID {
|
||||
uint64_t value = 0;
|
||||
};
|
||||
```
|
||||
|
||||
### 构造方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `ResourceGUID()` | 默认构造(值为 0) |
|
||||
| `explicit ResourceGUID(uint64_t value)` | 从整数值构造 |
|
||||
|
||||
### 比较运算
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|------|------|
|
||||
| `operator==(ResourceGUID, ResourceGUID)` | 判断相等 |
|
||||
| `operator!=(ResourceGUID, ResourceGUID)` | 判断不等 |
|
||||
|
||||
### 哈希支持
|
||||
|
||||
`ResourceGUID` 可作为 HashMap 的键使用。
|
||||
|
||||
### 静态方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static ResourceGUID Generate(const Containers::String& path)` | 从资源路径生成唯一 GUID |
|
||||
|
||||
---
|
||||
|
||||
## 辅助函数
|
||||
|
||||
| 函数 | 描述 |
|
||||
|------|------|
|
||||
| `const char* GetResourceTypeName(ResourceType type)` | 获取资源类型的字符串名称 |
|
||||
|
||||
---
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
// 使用 ResourceGUID
|
||||
ResourceGUID texGuid = ResourceGUID::Generate("textures/player.png");
|
||||
ResourceGUID meshGuid = ResourceGUID::Generate("models/player.fbx");
|
||||
|
||||
// GUID 比较
|
||||
if (texGuid == meshGuid) {
|
||||
// 相同资源
|
||||
}
|
||||
|
||||
// 在 HashMap 中使用
|
||||
Containers::HashMap<ResourceGUID, IResource*> cache;
|
||||
cache[texGuid] = texture;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
@@ -16,24 +16,24 @@ Resources 模块提供了一套完整的资源管理解决方案,支持同步
|
||||
|
||||
| 组件 | 文件 | 描述 |
|
||||
|------|------|------|
|
||||
| [IResource](./resources-iresource.md) | `IResource.h` | 资源基类 |
|
||||
| [ResourceHandle](./resources-resourcehandle.md) | `ResourceHandle.h` | 资源句柄模板 |
|
||||
| [IResourceLoader](./resources-iloader.md) | `IResourceLoader.h` | 资源加载器接口 |
|
||||
| [ResourceManager](./resources-resourcemanager.md) | `ResourceManager.h` | 资源管理器 |
|
||||
| [ResourceCache](./resources-resourcecache.md) | `ResourceCache.h` | 资源缓存 |
|
||||
| [AsyncLoader](./resources-asyncloader.md) | `AsyncLoader.h` | 异步加载器 |
|
||||
| [ResourceDependencyGraph](./resources-dependencygraph.md) | `ResourceDependencyGraph.h` | 依赖图 |
|
||||
| [ResourceTypes](./resources-resourcetypes.md) | `ResourceTypes.h` | 资源类型定义 |
|
||||
| [IResource](iresource/iresource.md) | `IResource.h` | 资源基类 |
|
||||
| [ResourceHandle](resourcehandle/resourcehandle.md) | `ResourceHandle.h` | 资源句柄模板 |
|
||||
| [IResourceLoader](iloader/iloader.md) | `IResourceLoader.h` | 资源加载器接口 |
|
||||
| [ResourceManager](resourcemanager/resourcemanager.md) | `ResourceManager.h` | 资源管理器 |
|
||||
| [ResourceCache](resourcecache/resourcecache.md) | `ResourceCache.h` | 资源缓存 |
|
||||
| [AsyncLoader](asyncloader/asyncloader.md) | `AsyncLoader.h` | 异步加载器 |
|
||||
| [ResourceDependencyGraph](dependencygraph/dependencygraph.md) | `ResourceDependencyGraph.h` | 依赖图 |
|
||||
| [ResourceTypes](resourcetypes/resourcetypes.md) | `ResourceTypes.h` | 资源类型定义 |
|
||||
|
||||
### 具体资源类型
|
||||
|
||||
| 组件 | 文件 | 描述 |
|
||||
|------|------|------|
|
||||
| [Texture](./resources-texture.md) | `Texture.h` | 纹理资源 |
|
||||
| [Mesh](./resources-mesh.md) | `Mesh.h` | 网格资源 |
|
||||
| [Material](./resources-material.md) | `Material.h` | 材质资源 |
|
||||
| [Shader](./resources-shader.md) | `Shader.h` | 着色器资源 |
|
||||
| [AudioClip](./resources-audioclip.md) | `AudioClip.h` | 音频资源 |
|
||||
| [Texture](texture/texture.md) | `Texture.h` | 纹理资源 |
|
||||
| [Mesh](mesh/mesh.md) | `Mesh.h` | 网格资源 |
|
||||
| [Material](material/material.md) | `Material.h` | 材质资源 |
|
||||
| [Shader](shader/shader.md) | `Shader.h` | 着色器资源 |
|
||||
| [AudioClip](audioclip/audioclip.md) | `AudioClip.h` | 音频资源 |
|
||||
|
||||
## 资源类型
|
||||
|
||||
@@ -79,4 +79,4 @@ mesh.Reset();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [RHI 模块](../rhi/rhi-overview.md) - GPU 资源创建
|
||||
- [RHI 模块](../rhi/rhi.md) - GPU 资源创建
|
||||
26
docs/api/resources/resourcetypes/generate.md
Normal file
26
docs/api/resources/resourcetypes/generate.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# ResourceGUID::Generate
|
||||
|
||||
```cpp
|
||||
static ResourceGUID Generate(const char* path)
|
||||
static ResourceGUID Generate(const Containers::String& path)
|
||||
```
|
||||
|
||||
从资源路径生成唯一的全局标识符。通过哈希算法将路径字符串转换为唯一的 64 位整数。
|
||||
|
||||
**参数:**
|
||||
- `path` - 资源路径
|
||||
|
||||
**返回:** 生成的 `ResourceGUID`
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceGUID guid = ResourceGUID::Generate("textures/player.png");
|
||||
ResourceGUID guid2 = ResourceGUID::Generate("models/player.fbx");
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceTypes 总览](resourcetypes.md) - 返回类总览
|
||||
25
docs/api/resources/resourcetypes/getresourcetypename.md
Normal file
25
docs/api/resources/resourcetypes/getresourcetypename.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# GetResourceTypeName
|
||||
|
||||
```cpp
|
||||
constexpr const char* GetResourceTypeName(ResourceType type)
|
||||
```
|
||||
|
||||
获取资源类型的字符串名称。通过 switch 语句返回对应的类型名字符串。
|
||||
|
||||
**参数:**
|
||||
- `type` - 资源类型枚举值
|
||||
|
||||
**返回:** 类型名字符串(如 `"Texture"`、`"Mesh"` 等)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
const char* name = GetResourceTypeName(ResourceType::Texture); // "Texture"
|
||||
const char* name2 = GetResourceTypeName(ResourceType::Shader); // "Shader"
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceTypes 总览](resourcetypes.md) - 返回类总览
|
||||
127
docs/api/resources/resourcetypes/resourcetypes.md
Normal file
127
docs/api/resources/resourcetypes/resourcetypes.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# ResourceTypes
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `enums` / `structs`
|
||||
|
||||
**描述**: 资源模块中使用的所有类型定义,包括资源类型枚举、GUID 结构体等。
|
||||
|
||||
## 概述
|
||||
|
||||
本文档汇总了 Resources 模块中的所有类型定义,包括资源类型枚举、GUID 结构体等基础类型。
|
||||
|
||||
---
|
||||
|
||||
## ResourceType
|
||||
|
||||
资源类型枚举。
|
||||
|
||||
| 值 | 描述 |
|
||||
|----|------|
|
||||
| `Unknown` | 未知类型 |
|
||||
| `Texture` | 纹理资源 |
|
||||
| `Mesh` | 网格/模型资源 |
|
||||
| `Material` | 材质资源 |
|
||||
| `Shader` | 着色器资源 |
|
||||
| `AudioClip` | 音频资源 |
|
||||
| `Binary` | 二进制数据 |
|
||||
| `AnimationClip` | 动画片段 |
|
||||
| `Skeleton` | 骨骼 |
|
||||
| `Font` | 字体 |
|
||||
| `ParticleSystem` | 粒子系统 |
|
||||
| `Scene` | 场景 |
|
||||
| `Prefab` | 预制体 |
|
||||
|
||||
---
|
||||
|
||||
## ResourceGUID
|
||||
|
||||
全局唯一标识符结构体,用于唯一标识每个资源。
|
||||
|
||||
```cpp
|
||||
struct ResourceGUID {
|
||||
Core::uint64 value;
|
||||
|
||||
ResourceGUID() : value(0) {}
|
||||
explicit ResourceGUID(Core::uint64 v) : value(v) {}
|
||||
|
||||
bool IsValid() const { return value != 0; }
|
||||
bool operator==(const ResourceGUID& other) const { return value == other.value; }
|
||||
bool operator!=(const ResourceGUID& other) const { return value != other.value; }
|
||||
|
||||
static ResourceGUID Generate(const char* path);
|
||||
static ResourceGUID Generate(const Containers::String& path);
|
||||
|
||||
Containers::String ToString() const;
|
||||
};
|
||||
```
|
||||
|
||||
### 比较运算
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|------|------|
|
||||
| `operator==(ResourceGUID, ResourceGUID)` | 判断相等 |
|
||||
| `operator!=(ResourceGUID, ResourceGUID)` | 判断不等 |
|
||||
|
||||
### 哈希支持
|
||||
|
||||
`ResourceGUID` 可作为 HashMap 的键使用(特化了 `std::hash`)。
|
||||
|
||||
### 静态方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `static ResourceGUID Generate(const char* path)` | 从资源路径生成唯一 GUID |
|
||||
| `static ResourceGUID Generate(const Containers::String& path)` | 从资源路径生成唯一 GUID |
|
||||
| `Containers::String ToString() const` | 转换为字符串 |
|
||||
|
||||
### 辅助函数
|
||||
|
||||
| 函数 | 描述 |
|
||||
|------|------|
|
||||
| `constexpr const char* GetResourceTypeName(ResourceType type)` | 获取资源类型的字符串名称 |
|
||||
|
||||
### 模板特化
|
||||
|
||||
```cpp
|
||||
template<> inline ResourceType GetResourceType<class Texture>() { return ResourceType::Texture; }
|
||||
template<> inline ResourceType GetResourceType<class Mesh>() { return ResourceType::Mesh; }
|
||||
template<> inline ResourceType GetResourceType<class Material>() { return ResourceType::Material; }
|
||||
template<> inline ResourceType GetResourceType<class Shader>() { return ResourceType::Shader; }
|
||||
template<> inline ResourceType GetResourceType<class AudioClip>() { return ResourceType::AudioClip; }
|
||||
template<> inline ResourceType GetResourceType<class BinaryResource>() { return ResourceType::Binary; }
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
// 使用 ResourceGUID
|
||||
ResourceGUID texGuid = ResourceGUID::Generate("textures/player.png");
|
||||
ResourceGUID meshGuid = ResourceGUID::Generate("models/player.fbx");
|
||||
|
||||
// GUID 比较
|
||||
if (texGuid == meshGuid) {
|
||||
// 相同资源
|
||||
}
|
||||
|
||||
// 有效性检查
|
||||
if (texGuid.IsValid()) {
|
||||
// GUID 有效
|
||||
}
|
||||
|
||||
// 在 HashMap 中使用
|
||||
Containers::HashMap<ResourceGUID, IResource*> cache;
|
||||
cache[texGuid] = texture;
|
||||
|
||||
// 获取类型名称
|
||||
const char* name = GetResourceTypeName(ResourceType::Texture); // "Texture"
|
||||
|
||||
// 使用模板获取类型
|
||||
ResourceType type = GetResourceType<Texture>(); // ResourceType::Texture
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
29
docs/api/resources/shader/addattribute.md
Normal file
29
docs/api/resources/shader/addattribute.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Shader::AddAttribute
|
||||
|
||||
```cpp
|
||||
void AddAttribute(const ShaderAttribute& attribute)
|
||||
```
|
||||
|
||||
添加顶点属性描述。
|
||||
|
||||
**参数:**
|
||||
- `attribute` - 属性描述结构体
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ShaderAttribute attr;
|
||||
attr.name = "position";
|
||||
attr.location = 0;
|
||||
attr.size = sizeof(float) * 3;
|
||||
attr.type = 0;
|
||||
vs->AddAttribute(attr);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Shader 总览](shader.md) - 返回类总览
|
||||
29
docs/api/resources/shader/adduniform.md
Normal file
29
docs/api/resources/shader/adduniform.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Shader::AddUniform
|
||||
|
||||
```cpp
|
||||
void AddUniform(const ShaderUniform& uniform)
|
||||
```
|
||||
|
||||
添加 Uniform 变量描述。
|
||||
|
||||
**参数:**
|
||||
- `uniform` - Uniform 描述结构体
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ShaderUniform uniform;
|
||||
uniform.name = "modelMatrix";
|
||||
uniform.location = 0;
|
||||
uniform.size = sizeof(float) * 16;
|
||||
uniform.type = 0;
|
||||
vs->AddUniform(uniform);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Shader 总览](shader.md) - 返回类总览
|
||||
@@ -144,6 +144,7 @@ RHIShader* rhiShader = vs->GetRHIResource();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [RHIShader](../rhi/rhi-shader.md) - RHI 着色器接口
|
||||
- [Material](./resources-material.md) - 材质资源
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [RHIShader](../../rhi/shader/shader.md) - RHI 着色器接口
|
||||
- [Material](../material/material.md) - 材质资源
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
39
docs/api/resources/texture/create.md
Normal file
39
docs/api/resources/texture/create.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Texture::Create
|
||||
|
||||
```cpp
|
||||
bool Create(Core::uint32 width, Core::uint32 height, Core::uint32 depth,
|
||||
Core::uint32 mipLevels, TextureType type, TextureFormat format,
|
||||
const void* data, size_t dataSize)
|
||||
```
|
||||
|
||||
创建纹理资源。设置纹理的尺寸、格式和像素数据,并分配 GPU 资源。
|
||||
|
||||
**参数:**
|
||||
- `width` - 纹理宽度(像素)
|
||||
- `height` - 纹理高度(像素)
|
||||
- `depth` - 纹理深度(3D 纹理设为 1)
|
||||
- `mipLevels` - Mipmap 级别数(0 表示自动生成所有级别)
|
||||
- `type` - 纹理类型
|
||||
- `format` - 纹理格式
|
||||
- `data` - 像素数据指针
|
||||
- `dataSize` - 像素数据大小
|
||||
|
||||
**返回:** 创建成功返回 true
|
||||
|
||||
**复杂度:** O(n),n 为像素数量
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Texture tex;
|
||||
bool ok = tex.Create(
|
||||
1024, 1024, 1, 0,
|
||||
TextureType::Texture2D,
|
||||
TextureFormat::RGBA8_UNORM,
|
||||
pixelData, pixelDataSize
|
||||
);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Texture 总览](texture.md) - 返回类总览
|
||||
24
docs/api/resources/texture/generatemipmaps.md
Normal file
24
docs/api/resources/texture/generatemipmaps.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Texture::GenerateMipmaps
|
||||
|
||||
```cpp
|
||||
bool GenerateMipmaps()
|
||||
```
|
||||
|
||||
生成纹理的 Mipmap 链。根据基础级别纹理自动生成所有下采样级别,用于纹理在缩小渲染时避免闪烁。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 生成成功返回 true
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
tex.Create(1024, 1024, 1, 1, TextureType::Texture2D, TextureFormat::RGBA8_UNORM, data, size);
|
||||
tex.GenerateMipmaps();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Texture 总览](texture.md) - 返回类总览
|
||||
@@ -147,6 +147,7 @@ uint32_t h = tex.GetHeight();
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource](./resources-iresource.md) - 资源基类
|
||||
- [ResourceManager](./resources-resourcemanager.md) - 资源管理器
|
||||
- [RHITexture](../rhi/rhi-texture.md) - RHI 纹理接口
|
||||
- [IResource](../iresource/iresource.md) - 资源基类
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [RHITexture](../../rhi/texture/texture.md) - RHI 纹理接口
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
Reference in New Issue
Block a user