blob: 1489c182d2573df4bd61b923cdb11a92f0c774c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
typedef uint16_t EventID;
typedef enum EventType {
EVENT_TYPE_PRE,
EVENT_TYPE_POST
} EventType;
typedef enum EventPriority {
EVENT_PRIORITY_LOW,
EVENT_PRIORITY_NORMAL,
EVENT_PRIORITY_HIGH,
} EventPriority;
typedef struct IEvent {
bool cancelled;
} IEvent;
typedef void (*EventCallback)(IEvent*);
// ID Type
// 000000000000000 0
#define EVENT_ID(id, type) ((id << 1) | type)
#ifdef __cplusplus
#include <array>
#include <vector>
class EventSystem {
public:
static EventSystem* Instance;
size_t RegisterListener(EventID id, EventPriority priority, EventCallback callback);
void CallEvent(EventID id, IEvent* event);
private:
std::array<std::vector<EventCallback>, 0xFFFF> mEventListeners;
};
#else
extern size_t EventSystem_RegisterListener(EventID id, EventPriority priority, EventCallback callback);
extern void EventSystem_CallEvent(EventID id, void* event);
#endif
|