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:
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) - 返回类总览
|
||||
101
docs/api/resources/resourcecache/resourcecache.md
Normal file
101
docs/api/resources/resourcecache/resourcecache.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# ResourceCache
|
||||
|
||||
**命名空间**: `XCEngine::Resources`
|
||||
|
||||
**类型**: `class`
|
||||
|
||||
**描述**: 资源缓存管理类,使用 LRU(最近最少使用)策略管理内存压力下的资源驱逐。
|
||||
|
||||
## 概述
|
||||
|
||||
`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()` | 获取当前时间戳 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `ResourceCache()` | 默认构造函数 |
|
||||
| `~ResourceCache()` | 析构函数 |
|
||||
|
||||
### 缓存操作
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `void Add(ResourceGUID guid, IResource* resource)` | 添加资源到缓存 |
|
||||
| `void Remove(ResourceGUID guid)` | 从缓存中移除资源 |
|
||||
| `IResource* Find(ResourceGUID guid) const` | 查找资源 |
|
||||
| `void Touch(ResourceGUID guid)` | 更新资源的访问时间(LRU) |
|
||||
|
||||
### 内存管理
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `size_t GetSize() const` | 获取缓存中资源数量 |
|
||||
| `size_t GetMemoryUsage() const` | 获取缓存内存使用量(字节) |
|
||||
| `void SetMemoryBudget(size_t bytes)` | 设置内存预算 |
|
||||
| `size_t GetMemoryBudget() const` | 获取内存预算 |
|
||||
| `void OnMemoryPressure(size_t requiredBytes)` | 内存压力回调,驱逐资源以释放空间 |
|
||||
| `void OnZeroRefCount(ResourceGUID guid)` | 当引用计数为零时的回调 |
|
||||
|
||||
### 缓存控制
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `void Flush()` | 清空缓存,释放所有资源 |
|
||||
| `void Clear()` | 清空缓存但不释放资源 |
|
||||
|
||||
### LRU 信息
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `Containers::Array<ResourceGUID> GetLRUList(size_t count) const` | 获取最近最少使用的 GUID 列表 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
ResourceCache cache;
|
||||
cache.SetMemoryBudget(512 * 1024 * 1024); // 512MB 预算
|
||||
|
||||
// 添加资源
|
||||
cache.Add(guid, resource);
|
||||
|
||||
// 访问资源(更新 LRU)
|
||||
cache.Touch(guid);
|
||||
|
||||
// 查找资源
|
||||
IResource* res = cache.Find(guid);
|
||||
|
||||
// 内存压力时自动驱逐
|
||||
cache.OnMemoryPressure(100 * 1024 * 1024); // 需要 100MB
|
||||
|
||||
// 获取最少使用的资源
|
||||
auto lruList = cache.GetLRUList(10);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [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) - 返回类总览
|
||||
Reference in New Issue
Block a user