docs: update resources API docs
This commit is contained in:
29
docs/api/resources/iresource/getguid.md
Normal file
29
docs/api/resources/iresource/getguid.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# IResource::GetGUID
|
||||
|
||||
```cpp
|
||||
virtual ResourceGUID GetGUID() const = 0
|
||||
```
|
||||
|
||||
获取全局唯一标识符。纯虚方法,由具体资源类实现,返回资源的唯一 GUID。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `ResourceGUID` - 资源的全局唯一标识符
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Material> mat = ResourceManager::Get().Load<Material>("materials/player.mat");
|
||||
ResourceGUID guid = mat->GetGUID();
|
||||
// guid 是根据路径生成的唯一标识符
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
29
docs/api/resources/iresource/getmemorysize.md
Normal file
29
docs/api/resources/iresource/getmemorysize.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# IResource::GetMemorySize
|
||||
|
||||
```cpp
|
||||
virtual size_t GetMemorySize() const = 0
|
||||
```
|
||||
|
||||
获取资源占用的内存大小。纯虚方法,由具体资源类实现,返回资源在内存中的字节数。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `size_t` - 资源占用的内存大小(字节)
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("models/player.fbx");
|
||||
size_t size = mesh->GetMemorySize();
|
||||
// size == 内存占用字节数
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
29
docs/api/resources/iresource/getname.md
Normal file
29
docs/api/resources/iresource/getname.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# IResource::GetName
|
||||
|
||||
```cpp
|
||||
virtual const Containers::String& GetName() const = 0
|
||||
```
|
||||
|
||||
获取资源名称。纯虚方法,由具体资源类实现,返回资源的显示名称。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `const Containers::String&` - 资源名称的常量引用
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Mesh> mesh = ResourceManager::Get().Load<Mesh>("models/player.fbx");
|
||||
const Containers::String& name = mesh->GetName();
|
||||
// name == "player"
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
29
docs/api/resources/iresource/getpath.md
Normal file
29
docs/api/resources/iresource/getpath.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# IResource::GetPath
|
||||
|
||||
```cpp
|
||||
virtual const Containers::String& GetPath() const = 0
|
||||
```
|
||||
|
||||
获取资源路径。纯虚方法,由具体资源类实现,返回资源在文件系统中的相对路径。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `const Containers::String&` - 资源路径的常量引用
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
||||
const Containers::String& path = tex->GetPath();
|
||||
// path == "textures/player.png"
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
30
docs/api/resources/iresource/gettype.md
Normal file
30
docs/api/resources/iresource/gettype.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# IResource::GetType
|
||||
|
||||
```cpp
|
||||
virtual ResourceType GetType() const = 0
|
||||
```
|
||||
|
||||
获取资源类型。纯虚方法,由具体资源类实现,返回该资源所属的类型枚举值。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `ResourceType` - 资源类型枚举
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
||||
ResourceType type = tex->GetType();
|
||||
// type == ResourceType::Texture
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
- [ResourceTypes](../resourcetypes/resourcetypes.md) - 资源类型定义
|
||||
@@ -11,6 +11,10 @@ void Initialize(const ConstructParams& params)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
**类型**: `class` (abstract)
|
||||
|
||||
**头文件**: `XCEngine/Resources/IResource.h`
|
||||
|
||||
**描述**: 资源基类接口,所有具体资源类型(Texture、Mesh、Material 等)都必须继承自此类。
|
||||
|
||||
## 概述
|
||||
@@ -14,25 +16,24 @@
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `ResourceType GetType() const` | 获取资源类型 |
|
||||
| `const Containers::String& GetName() const` | 获取资源名称 |
|
||||
| `const Containers::String& GetPath() const` | 获取资源路径 |
|
||||
| `ResourceGUID GetGUID() const` | 获取全局唯一标识符 |
|
||||
| `bool IsValid() const` | 检查资源是否有效 |
|
||||
| `size_t GetMemorySize() const` | 获取资源占用的内存大小(字节) |
|
||||
| `void Release()` | 释放资源引用 |
|
||||
| `void Initialize(const ConstructParams& params)` | 使用构造参数初始化资源 |
|
||||
| `void SetInvalid()` | 将资源标记为无效 |
|
||||
| [`GetType()`](gettype.md) | 获取资源类型 |
|
||||
| [`GetName()`](getname.md) | 获取资源名称 |
|
||||
| [`GetPath()`](getpath.md) | 获取资源路径 |
|
||||
| [`GetGUID()`](getguid.md) | 获取全局唯一标识符 |
|
||||
| [`IsValid()`](isvalid.md) | 检查资源是否有效 |
|
||||
| [`GetMemorySize()`](getmemorysize.md) | 获取资源占用的内存大小(字节) |
|
||||
| [`Release()`](release.md) | 释放资源引用 |
|
||||
| [`Initialize()`](initialize.md) | 使用构造参数初始化资源 |
|
||||
| [`SetInvalid()`](setinvalid.md) | 将资源标记为无效 |
|
||||
|
||||
### 构造参数
|
||||
### 构造参数结构体 `ConstructParams`
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `m_name` | `Containers::String` | 资源名称 |
|
||||
| `m_path` | `Containers::String` | 资源路径 |
|
||||
| `m_guid` | `ResourceGUID` | 全局唯一标识符 |
|
||||
| `m_isValid` | `bool` | 资源是否有效 |
|
||||
| `m_memorySize` | `size_t` | 内存占用大小 |
|
||||
| `name` | `Containers::String` | 资源名称 |
|
||||
| `path` | `Containers::String` | 资源路径 |
|
||||
| `guid` | `ResourceGUID` | 全局唯一标识符 |
|
||||
| `memorySize` | `size_t` | 内存占用大小(字节),默认 0 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
@@ -51,7 +52,4 @@ public:
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ResourceHandle](../resourcehandle/resourcehandle.md) - 资源句柄
|
||||
- [ResourceManager](../resourcemanager/resourcemanager.md) - 资源管理器
|
||||
- [ResourceTypes](../resourcetypes/resourcetypes.md) - 资源类型定义
|
||||
- [Resources 总览](../resources.md) - 返回模块总览
|
||||
|
||||
33
docs/api/resources/iresource/isvalid.md
Normal file
33
docs/api/resources/iresource/isvalid.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# IResource::IsValid
|
||||
|
||||
```cpp
|
||||
virtual bool IsValid() const = 0
|
||||
```
|
||||
|
||||
检查资源是否有效。纯虚方法,由具体资源类实现,返回资源当前的有效状态。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `bool` - 资源有效返回 `true`,无效返回 `false`
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
ResourceHandle<Texture> tex = ResourceManager::Get().Load<Texture>("textures/player.png");
|
||||
if (tex->IsValid()) {
|
||||
// 资源加载成功,可以使用
|
||||
} else {
|
||||
// 资源加载失败或已被释放
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [IResource 总览](iresource.md) - 返回类总览
|
||||
- [SetInvalid](setinvalid.md) - 将资源标记为无效
|
||||
@@ -10,6 +10,10 @@ virtual void Release() = 0
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1) 或 O(n),取决于具体实现
|
||||
|
||||
**示例:**
|
||||
|
||||
@@ -10,6 +10,10 @@ void SetInvalid()
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
Reference in New Issue
Block a user