ScummVM API documentation
plugin_event.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef WINTERMUTE_PLUGIN_EVENT_H
23#define WINTERMUTE_PLUGIN_EVENT_H
24
25namespace Wintermute {
26
28// WME events
29typedef enum {
30 WME_EVENT_UPDATE = 0,
31 WME_EVENT_SCENE_DRAW_BEGIN,
32 WME_EVENT_SCENE_DRAW_END,
33 WME_EVENT_SCENE_INIT,
34 WME_EVENT_SCENE_SHUTDOWN,
35 WME_EVENT_GAME_BEFORE_SAVE,
36 WME_EVENT_GAME_AFTER_LOAD,
37 WME_EVENT_MAX
38} EWmeEvent;
39
40typedef void (*PluginApplyEvent)(void *, void *);
41
42typedef struct _PluginEventEntry {
43 EWmeEvent _type;
44 PluginApplyEvent _callback;
45 void *_plugin;
47
49public:
50 PluginEvent() {};
51 ~PluginEvent() {};
52
53 void subscribeEvent(PluginEventEntry &event) {
54 for (auto it = _entries.begin(); it != _entries.end(); ++it) {
55 if (event._type == it->_type && event._callback == it->_callback) {
56 break;
57 }
58 }
59 _entries.push_back(event);
60 }
61
62 void unsubscribeEvent(PluginEventEntry &event) {
63 for (auto it = _entries.begin(); it != _entries.end(); ++it) {
64 if (event._type == it->_type && event._callback == it->_callback) {
65 _entries.erase(it);
66 break;
67 }
68 }
69 }
70
71 void applyEvent(EWmeEvent type, void *eventData) {
72 for (auto it = _entries.begin(); it != _entries.end(); ++it) {
73 if (type == it->_type && it->_callback != nullptr) {
74 it->_callback(eventData, it->_plugin);
75 }
76 }
77 }
78
79 void clearEvents() {
80 _entries.clear();
81 }
82
83private:
85};
86
87} // End of namespace Wintermute
88
89#endif
Definition: list.h:44
Definition: plugin_event.h:48
Definition: plugin_event.h:42