fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
This commit is contained in:
69
docs/api/core/event/event.md
Normal file
69
docs/api/core/event/event.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# Event
|
||||
|
||||
**命名空间**: `XCEngine::Core`
|
||||
|
||||
**类型**: `class` (template)
|
||||
|
||||
**描述**: 事件系统模板类,提供类型安全的多订阅者事件/委托系统。
|
||||
|
||||
## 概述
|
||||
|
||||
`Event<Args...>` 是一个类型安全的事件发布-订阅系统。它支持多个回调订阅、退订和线程安全的调用。非常适合用于游戏引擎中的事件驱动通信。
|
||||
|
||||
## 模板参数
|
||||
|
||||
| 参数 | 描述 |
|
||||
|------|------|
|
||||
| `Args...` | 事件回调的参数类型 |
|
||||
|
||||
## 类型别名
|
||||
|
||||
| 别名 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `Callback` | `std::function<void(Args...)>` | 回调函数类型 |
|
||||
| `Listener` | `std::pair<uint64_t, Callback>` | 监听器条目 |
|
||||
| `Iterator` | `std::vector<Listener>::iterator` | 迭代器类型 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Subscribe`](Subscribe.md) | 订阅事件回调,返回订阅 ID |
|
||||
| [`Unsubscribe`](Unsubscribe.md) | 退订事件(延迟生效) |
|
||||
| [`ProcessUnsubscribes`](ProcessUnsubscribes.md) | 处理积压的退订请求 |
|
||||
| [`Clear`](Clear.md) | 清空所有订阅 |
|
||||
| [`Invoke`](Invoke.md) | 调用所有订阅的回调 |
|
||||
| [`begin`](begin.md) | 获取开始迭代器 |
|
||||
| [`end`](end.md) | 获取结束迭代器 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Core/Event.h>
|
||||
|
||||
using namespace XCEngine::Core;
|
||||
|
||||
// 定义事件(无参数)
|
||||
Event<> frameStartEvent;
|
||||
|
||||
// 定义事件(带参数)
|
||||
Event<int, float> damageEvent;
|
||||
|
||||
// 订阅
|
||||
uint64_t id = damageEvent.Subscribe([](int damage, float time) {
|
||||
printf("Damage: %d at time %f\n", damage, time);
|
||||
});
|
||||
|
||||
// 触发事件
|
||||
damageEvent.Invoke(100, 3.14f);
|
||||
|
||||
// 退订
|
||||
damageEvent.Unsubscribe(id);
|
||||
|
||||
// 清空
|
||||
frameStartEvent.Clear();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Core 模块总览](../core.md) - 返回模块总览
|
||||
Reference in New Issue
Block a user