![]() |
XII Release 0.1.0
|
A class to broadcast and handle global (system-wide) events. More...
#include <GlobalEvent.h>
Classes | |
struct | EventData |
Public Types | |
using | EventMap = xiiMap<xiiString, EventData> |
using | XII_GLOBAL_EVENT_HANDLER = void (*)(const xiiVariant&, const xiiVariant&, const xiiVariant&, const xiiVariant&) |
[internal] Use the macro XII_ON_GLOBAL_EVENT or XII_ON_GLOBAL_EVENT_ONCE to create an event handler. | |
Public Member Functions | |
xiiGlobalEvent (xiiStringView sEventName, XII_GLOBAL_EVENT_HANDLER eventHandler, bool bOnlyOnce) | |
[internal] Use the macro XII_ON_GLOBAL_EVENT or XII_ON_GLOBAL_EVENT_ONCE to create an event handler. | |
Static Public Member Functions | |
static void | Broadcast (xiiStringView sEventName, xiiVariant param0=xiiVariant(), xiiVariant param1=xiiVariant(), xiiVariant param2=xiiVariant(), xiiVariant param3=xiiVariant()) |
This function will broadcast a system wide event to all event handlers that are registered to handle this specific type of event. | |
static void | PrintGlobalEventStatistics () |
This function will output (via xiiLog) some statistics about which events are used and how often. | |
static void | UpdateGlobalEventStatistics () |
Updates all global event statistics. | |
static const EventMap & | GetEventStatistics () |
Returns the map that holds the current statistics about the global events. | |
![]() | |
static const xiiRTTI * | GetStaticRTTI () |
Additional Inherited Members | |
![]() | |
xiiEnumerable * | m_pNextInstance |
A class to broadcast and handle global (system-wide) events.
A global event is an event that will be sent to all instances of xiiGlobalEvent (or rather their respective handler functions), without the need to first register these event-handlers anywhere. Thus they are very useful to notify sub-systems of certain important events, such as that some kind of initialization will be done shortly, which means they can react by preparing properly. For example the xiiStartup-class will send certain events before doing startup and shutdown steps, which allows code to free resources before a sub-system might be shut down. xiiGlobalEvent's should be used when there is a kind of event that should be propagated throughout the entire engine, without knowledge which systems might want to know about it. These systems can then use an xiiGlobalEvent-instance to hook themselves into the global-event pipeline and react accordingly. Global events should mostly be used for startup / configuration / shutdown procedures. Also one should never assume any specific order of execution, all event handlers should be completely independent from each other.
To create a global event handler, simply add this code inside a cpp file:
XII_ON_GLOBAL_EVENT(EventName) { ... do something ... }
You can also use XII_ON_GLOBAL_EVENT_ONCE, if the handler should only be executed the first time the event is sent. This is more efficient than filtering out duplicate events inside the event handler.
|
static |
This function will broadcast a system wide event to all event handlers that are registered to handle this specific type of event.
The string specifies the event type, the parameters are optional and can be used to send additional event specific data.
|
static |
This function will output (via xiiLog) some statistics about which events are used and how often.
This allows to figure out which events are used throughout the engine and which events might be fired too often.