A singleton class that creates a communication interface between separate parts of a program through event dispatching.
More...
A singleton class that creates a communication interface between separate parts of a program through event dispatching.
The global event emitter is available to anything class that needs it (class, function etc..).
Its responsibility is to decouple classes from one another. You can emit a signal and anyone listening for that signal will pick it up without knowing and caring where the signal came from. Here is a simple example:
engine.popScene();
engine.pushScene(gameplayScene);
}));
engine.pushScene(loadingScene);
engine.run();
EventDispatcher::instance::dispatchEvent("loadingComplete");
static EventDispatcher::Ptr instance()
Get class instance.
- Note
- This classes instance is accessible from anywhere withing the program, however the instance is destroyed when the last pointer to it goes out of scope. This means that all event listeners that have been registered will be destroyed and a call to dispatchEvent will not do anything. Therefore there must be at least one pointer to the class instance that keeps it alive for as long as its being used. The Engine keeps an instance alive for as long as it is running, therefore you should use the global dispatcher only when the engine is running or keep an instance alive yourself
Definition at line 38 of file EventDispatcher.h.