Files
XCSDD/docs/api/core/event/Invoke.md
ssdfasd 58a83f445a 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
2026-03-19 12:44:08 +08:00

977 B

Event::Invoke

void Invoke(Args... args);

调用所有订阅的回调。

描述

依次调用所有已订阅的回调函数。在调用前会自动处理待退订的回调。回调是在锁外执行的,因此可以在回调中安全地进行订阅/退订操作。线程安全。

参数:

  • args - 传递给回调的参数

复杂度: O(n) 其中 n 为订阅数量

示例:

#include <XCEngine/Core/Event.h>

using namespace XCEngine::Core;

// 无参数事件
Event<> frameEndEvent;
frameEndEvent.Subscribe([]() {
    printf("Frame ended\n");
});

// 带参数事件
Event<int, const char*> playerDiedEvent;
playerDiedEvent.Subscribe([](int playerId, const char* reason) {
    printf("Player %d died: %s\n", playerId, reason);
});

// 触发事件
frameEndEvent.Invoke();
playerDiedEvent.Invoke(1, "fell off a cliff");

相关文档