fennec
Loading...
Searching...
No Matches
event.h
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef FENNEC_CORE_EVENT_H
20#define FENNEC_CORE_EVENT_H
21
22#include <fennec/lang/types.h>
23#include <fennec/rtti/enable.h>
24
25#include <fennec/rtti/typeid.h>
26
27namespace fennec
28{
29
30struct event;
31
35public:
36 virtual ~event_listener() = default;
37 virtual void handle_event(event* event) = 0;
38};
39
42struct event {
43 virtual ~event() = default;
44
49 template<typename EventT>
50 static void add_listener(event_listener* listener) {
51 event::add_listener(listener, typeuuid<EventT, event>());
52 }
53
54 template<typename EventT>
55 static void dispatch(EventT* event) {
56 dispatch(event);
57 }
58
59 static void add_listener(event_listener* listener, uint64_t type);
60 static void remove_listener(event_listener* listener);
61 static void dispatch(event* event);
62
63 FENNEC_RTTI_CLASS_ENABLE() {
64
65 }
66};
67
68}
69
70#endif // FENNEC_CORE_EVENT_H
Class outlining the interface for an object that listens for events.
Definition event.h:34
Main event interface, includes static methods for registering listeners and dispatching events.
Definition event.h:42
static void add_listener(event_listener *listener)
Registers a listener for the event type.
Definition event.h:50
Types