XII Release 0.1.0
Loading...
Searching...
No Matches
xiiGlobalEvent Class Reference

A class to broadcast and handle global (system-wide) events. More...

#include <GlobalEvent.h>

Inheritance diagram for xiiGlobalEvent:
[legend]

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 EventMapGetEventStatistics ()
 Returns the map that holds the current statistics about the global events.
 
- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 

Additional Inherited Members

- Protected Attributes inherited from xiiEnumerable< xiiGlobalEvent >
xiiEnumerablem_pNextInstance
 

Detailed Description

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.

Member Function Documentation

◆ Broadcast()

void xiiGlobalEvent::Broadcast ( xiiStringView sEventName,
xiiVariant param0 = xiiVariant(),
xiiVariant param1 = xiiVariant(),
xiiVariant param2 = xiiVariant(),
xiiVariant param3 = xiiVariant() )
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.

◆ PrintGlobalEventStatistics()

void xiiGlobalEvent::PrintGlobalEventStatistics ( )
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.


The documentation for this class was generated from the following files: