Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
Dispatcher.hpp
1
#pragma once
2
3
#include "Common/Event/EventType.hpp"
4
#include <vector>
5
#include <functional>
6
#include <map>
7
8
namespace
Grindstone {
9
namespace
Events {
10
struct
BaseEvent
;
11
12
using
EventListener = std::function<bool(
BaseEvent
*)>;
13
14
class
Dispatcher {
15
public
:
16
/*struct EventCallback {
17
EventCallback(
18
bool (*fn)(BaseEvent*, void*),
19
void* data
20
) : fn(fn), data(data) {}
21
bool (*fn)(BaseEvent*, void*);
22
void* data;
23
};*/
24
25
Dispatcher();
26
virtual
void
AddEventListener(EventType eventType, std::function<
bool
(
BaseEvent
*)> function);
27
virtual
void
Dispatch(
BaseEvent
*);
28
virtual
void
HandleEvents();
29
private
:
30
void
HandleEvent(
BaseEvent
* eventToHandle);
31
private
:
32
using
EventListenerList = std::vector<std::function<bool(
BaseEvent
*)>>;
33
std::map<Events::EventType, EventListenerList> eventListeners;
34
std::vector<BaseEvent*> eventsToHandle;
35
};
// class Dispatcher
36
}
// namespace Events
37
}
// namespace Grindstone
Grindstone::Events::BaseEvent
Definition
BaseEvent.hpp:7
sources
code
EngineCore
Events
Dispatcher.hpp
Generated by
1.17.0