OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
scriptdelegate.h
1/*
2===========================================================================
3Copyright (C) 2025 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// scriptdelegate -- manages function delegate
24
25#include "../qcommon/listener.h"
26#include "../qcommon/delegate.h"
27#include "gamescript.h"
28
30{
31public:
32 void Execute(Listener *object, const Event& ev);
33};
34
39class ScriptRegisteredDelegate_Script : public ScriptRegisteredDelegate
40{
41public:
42 ScriptRegisteredDelegate_Script(const ScriptThreadLabel& inLabel);
43
44 void Execute(Listener *object, const Event& ev);
45
46 bool operator==(const ScriptRegisteredDelegate_Script& registeredDelegate) const;
47
48private:
50};
51
56class ScriptRegisteredDelegate_Code : public ScriptRegisteredDelegate
57{
58public:
59 using DelegateResponse = void (*)(Listener *object, const Event& ev);
60
61public:
62 ScriptRegisteredDelegate_Code(DelegateResponse inResponse);
63
64 void Execute(Listener *object, const Event& ev);
65
66 bool operator==(const ScriptRegisteredDelegate_Code& registeredDelegate) const;
67
68private:
69 DelegateResponse response;
70};
71
77class ScriptRegisteredDelegate_CodeMember : public ScriptRegisteredDelegate
78{
79public:
80 using DelegateClassResponse = void (Class::*)(Listener *object, const Event& ev);
81
82public:
83 ScriptRegisteredDelegate_CodeMember(Class *inObject, DelegateClassResponse inResponse);
84
85 void Execute(Listener *object, const Event& ev);
86
87 bool operator==(const ScriptRegisteredDelegate_CodeMember& registeredDelegate) const;
88
89private:
90 SafePtr<Class> object;
91 DelegateClassResponse response;
92};
93
99class ScriptDelegate
100{
101public:
102 ScriptDelegate(const char *name, const char *description);
103 ~ScriptDelegate();
104
105 static const ScriptDelegate *GetRoot();
106 const ScriptDelegate *GetNext() const;
107
113 void Register(const ScriptThreadLabel& label);
114
120 void Unregister(const ScriptThreadLabel& label);
121
127 void Register(ScriptRegisteredDelegate_Code::DelegateResponse response);
128
134 void Unregister(ScriptRegisteredDelegate_Code::DelegateResponse response);
135
142 void Register(Class *object, ScriptRegisteredDelegate_CodeMember::DelegateClassResponse response);
143
150 void Unregister(Class *object, ScriptRegisteredDelegate_CodeMember::DelegateClassResponse response);
151
157 void Trigger(const Event& ev = Event()) const;
158
164 void Trigger(Listener *object, const Event& ev = Event()) const;
165
169 void Reset();
170
176 static ScriptDelegate *GetScriptDelegate(const char *name);
177 static void ResetAllDelegates();
178
179 // non-movable and non-copyable
180 ScriptDelegate(ScriptDelegate&& other) = delete;
181 ScriptDelegate& operator=(ScriptDelegate&& other) = delete;
182 ScriptDelegate(const ScriptDelegate& other) = delete;
183 ScriptDelegate& operator=(const ScriptDelegate& other) = delete;
184
185private:
186 // Linked-list
187 ScriptDelegate *next;
188 ScriptDelegate *prev;
189 static ScriptDelegate *root;
190 const char *name;
191 const char *description;
192
196};
Definition class.h:276
Definition container.h:85
Definition listener.h:246
Definition listener.h:450
Definition safeptr.h:160
void Unregister(const ScriptThreadLabel &label)
Definition scriptdelegate.cpp:111
void Trigger(const Event &ev=Event()) const
Definition scriptdelegate.cpp:136
void Register(const ScriptThreadLabel &label)
Definition scriptdelegate.cpp:102
static ScriptDelegate * GetScriptDelegate(const char *name)
Definition scriptdelegate.cpp:167
void Reset()
Definition scriptdelegate.cpp:178
Definition scriptdelegate.h:30
Definition gamescript.h:165