R-Type  2
Doom but in better
Loading...
Searching...
No Matches
EventDispatcher.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include "GameMessage.hpp"
5
13public:
19 using Callback = std::function<void(const GameMessage&)>;
20
28 void subscribe(Callback callback){
29 listener = callback;
30 }
31
39 void notify(const GameMessage& event){
40 if (listener)
41 listener(event);
42 }
43
44private:
48 Callback listener;
49};
A utility class for dispatching and handling game events.
void notify(const GameMessage &event)
Notifies the subscribed listener of an event.
std::function< void(const GameMessage &)> Callback
Defines the type for event callbacks.
void subscribe(Callback callback)
Subscribes a listener to game events.
A structure representing a game message.