Files
XCEngine/docs/api/core/event/Invoke.md
ssdfasd de4086dbfe docs: Fix core module documentation discrepancies
Fixed the following issues in XCEngine Core module documentation:
- Added 'using namespace XCEngine::Core;' to all code examples that use
  Core types (Event, FileWriter, etc.) without full namespace qualification
- Added missing '#include <XCEngine/Containers/String.h>' to FileWriter
  examples that use Containers::String
- Added '#include <string>' to Flush.md example using std::to_string

Affected files:
- core/core.md: Added using directive and Containers include
- event/*.md: Added using namespace to all 8 event doc files
- filewriter/*.md: Added using namespace and proper includes to all 6 files
2026-03-19 01:04:30 +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");

相关文档