OpenMoHAA ..
Loading...
Searching...
No Matches
scriptdelegate.h
1/*
2===========================================================================
3Copyright (C) 2026 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#pragma once
26
27#include "../corepp/listener.h"
28#include "../corepp/delegate.h"
29#include "gamescript.h"
30
32{
33public:
34 void Execute(Listener *object, const Event& ev);
35};
36
41class ScriptRegisteredDelegate_Script : public ScriptRegisteredDelegate
42{
43public:
44 ScriptRegisteredDelegate_Script(const ScriptThreadLabel& inLabel);
45
46 ScriptVariable Execute(Listener *object, const Event& ev);
47
48 bool operator==(const ScriptRegisteredDelegate_Script& registeredDelegate) const;
49
50private:
52};
53
58class ScriptRegisteredDelegate_Code : public ScriptRegisteredDelegate
59{
60public:
61 using DelegateResponse = void (*)(Listener *object, const Event& ev);
62
63public:
64 ScriptRegisteredDelegate_Code(DelegateResponse inResponse);
65
66 void Execute(Listener *object, const Event& ev);
67
68 bool operator==(const ScriptRegisteredDelegate_Code& registeredDelegate) const;
69
70private:
71 DelegateResponse response;
72};
73
79class ScriptRegisteredDelegate_CodeMember : public ScriptRegisteredDelegate
80{
81public:
82 using DelegateClassResponse = void (Class::*)(Listener *object, const Event& ev);
83
84public:
85 ScriptRegisteredDelegate_CodeMember(Class *inObject, DelegateClassResponse inResponse);
86
87 void Execute(Listener *object, const Event& ev);
88
89 bool operator==(const ScriptRegisteredDelegate_CodeMember& registeredDelegate) const;
90
91private:
92 SafePtr<Class> object;
93 DelegateClassResponse response;
94};
95
101class ScriptDelegate
102{
103public:
104 ScriptDelegate(const char *name, const char *description);
105 ~ScriptDelegate();
106
107 static const ScriptDelegate *GetRoot();
108 const ScriptDelegate *GetNext() const;
109
115 void Register(const ScriptThreadLabel& label);
116
122 void Unregister(const ScriptThreadLabel& label);
123
129 void Register(ScriptRegisteredDelegate_Code::DelegateResponse response);
130
136 void Unregister(ScriptRegisteredDelegate_Code::DelegateResponse response);
137
144 void Register(Class *object, ScriptRegisteredDelegate_CodeMember::DelegateClassResponse response);
145
152 void Unregister(Class *object, ScriptRegisteredDelegate_CodeMember::DelegateClassResponse response);
153
159 ScriptVariable Trigger(const Event& ev = Event()) const;
160
166 ScriptVariable Trigger(Listener *object, const Event& ev = Event()) const;
167
171 void Reset();
172
178 static ScriptDelegate *GetScriptDelegate(const char *name);
179 static void ResetAllDelegates();
180
181 // non-movable and non-copyable
182 ScriptDelegate(ScriptDelegate&& other) = delete;
183 ScriptDelegate& operator=(ScriptDelegate&& other) = delete;
184 ScriptDelegate(const ScriptDelegate& other) = delete;
185 ScriptDelegate& operator=(const ScriptDelegate& other) = delete;
186
187private:
188 // Linked-list
189 ScriptDelegate *next;
190 ScriptDelegate *prev;
191 static ScriptDelegate *root;
192 const char *name;
193 const char *description;
194
198};
Definition g_local.h:81
void Unregister(const ScriptThreadLabel &label)
Definition scriptdelegate.cpp:122
void Register(const ScriptThreadLabel &label)
Definition scriptdelegate.cpp:113
static ScriptDelegate * GetScriptDelegate(const char *name)
Definition scriptdelegate.cpp:186
ScriptVariable Trigger(const Event &ev=Event()) const
Definition scriptdelegate.cpp:152
void Reset()
Definition scriptdelegate.cpp:197
Definition scriptdelegate.h:32
Definition gamescript.h:165
Definition scriptvariable.h:75