22 #ifndef AGS_PLUGINS_PLUGIN_BASE_H 23 #define AGS_PLUGINS_PLUGIN_BASE_H 25 #include "ags/shared/util/string.h" 26 #include "common/hashmap.h" 27 #include "common/hash-str.h" 28 #include "common/textconsole.h" 37 #define SCRIPT_METHOD(NAME, PROC) addMethod(#NAME, &PROC) 39 #define SCRIPT_HASH_MACRO(TheClass, BaseClass, RegisterMethod) \ 41 typedef void (TheClass::*MethodPtr)(ScriptMethodParams ¶ms); \ 42 Common::HashMap<Common::String, MethodPtr> _methods; \ 43 inline void addMethod(const Common::String &name, MethodPtr fn) { \ 44 _methods[name] = fn; \ 45 _engine->RegisterMethod(name.c_str(), this); \ 48 void execMethod(const Common::String &name, ScriptMethodParams ¶ms) override { \ 49 if (_methods.contains(name)) \ 50 (this->*_methods[name])(params); \ 52 BaseClass::execMethod(name, params); \ 54 #define SCRIPT_HASH(TheClass) SCRIPT_HASH_MACRO(TheClass, PluginBase, RegisterScriptFunction) 55 #define BUILT_IN_HASH(TheClass) SCRIPT_HASH_MACRO(TheClass, ScriptContainer, RegisterBuiltInFunction) 56 #define SCRIPT_HASH_SUB(TheClass, BaseClass) SCRIPT_HASH_MACRO(TheClass, BaseClass, RegisterScriptFunction) 58 inline float PARAM_TO_FLOAT(int32 xi) {
60 memcpy(&x, &xi,
sizeof(
float));
64 inline int32 PARAM_FROM_FLOAT(
float x) {
66 memcpy(&xi, &x,
sizeof(
float));
70 #define PARAMS1(T1, N1) \ 72 #define PARAMS2(T1, N1, T2, N2) \ 73 T1 N1 = (T1)params[0]; \ 75 #define PARAMS3(T1, N1, T2, N2, T3, N3) \ 76 T1 N1 = (T1)params[0]; \ 77 T2 N2 = (T2)params[1]; \ 79 #define PARAMS4(T1, N1, T2, N2, T3, N3, T4, N4) \ 80 T1 N1 = (T1)params[0]; \ 81 T2 N2 = (T2)params[1]; \ 82 T3 N3 = (T3)params[2]; \ 84 #define PARAMS5(T1, N1, T2, N2, T3, N3, T4, N4, T5, N5) \ 85 T1 N1 = (T1)params[0]; \ 86 T2 N2 = (T2)params[1]; \ 87 T3 N3 = (T3)params[2]; \ 88 T4 N4 = (T4)params[3]; \ 90 #define PARAMS6(T1, N1, T2, N2, T3, N3, T4, N4, T5, N5, T6, N6) \ 91 T1 N1 = (T1)params[0]; \ 92 T2 N2 = (T2)params[1]; \ 93 T3 N3 = (T3)params[2]; \ 94 T4 N4 = (T4)params[3]; \ 95 T5 N5 = (T5)params[4]; \ 97 #define PARAMS7(T1, N1, T2, N2, T3, N3, T4, N4, T5, N5, T6, N6, T7, N7) \ 98 T1 N1 = (T1)params[0]; \ 99 T2 N2 = (T2)params[1]; \ 100 T3 N3 = (T3)params[2]; \ 101 T4 N4 = (T4)params[3]; \ 102 T5 N5 = (T5)params[4]; \ 103 T6 N6 = (T6)params[5]; \ 104 T7 N7 = (T7)params[6] 105 #define PARAMS8(T1, N1, T2, N2, T3, N3, T4, N4, T5, N5, T6, N6, T7, N7, T8, N8) \ 106 T1 N1 = (T1)params[0]; \ 107 T2 N2 = (T2)params[1]; \ 108 T3 N3 = (T3)params[2]; \ 109 T4 N4 = (T4)params[3]; \ 110 T5 N5 = (T5)params[4]; \ 111 T6 N6 = (T6)params[5]; \ 112 T7 N7 = (T7)params[6]; \ 113 T8 N8 = (T8)params[7] 114 #define PARAMS9(T1, N1, T2, N2, T3, N3, T4, N4, T5, N5, T6, N6, T7, N7, T8, N8, T9, N9) \ 115 T1 N1 = (T1)params[0]; \ 116 T2 N2 = (T2)params[1]; \ 117 T3 N3 = (T3)params[2]; \ 118 T4 N4 = (T4)params[3]; \ 119 T5 N5 = (T5)params[4]; \ 120 T6 N6 = (T6)params[5]; \ 121 T7 N7 = (T7)params[6]; \ 122 T8 N8 = (T8)params[7]; \ 123 T9 N9 = (T9)params[8] 125 class ScriptMethodParams;
126 class ScriptContainer;
128 using string =
const char *;
159 virtual void AGS_EngineStartup(
IAGSEngine *engine) {
164 error(
"Plugin does not contain method - %s", name.c_str());
176 virtual const char *AGS_GetPluginName() = 0;
177 virtual int AGS_PluginV2()
const {
return 1; }
178 virtual int AGS_EditorStartup(
IAGSEditor *) {
return 0; }
179 virtual void AGS_EditorShutdown() {}
180 virtual void AGS_EditorProperties(HWND) {}
181 virtual int AGS_EditorSaveGame(
char *,
int) {
return 0; }
182 virtual void AGS_EditorLoadGame(
char *,
int) {}
183 virtual void AGS_EngineShutdown() {}
184 virtual int64 AGS_EngineOnEvent(
int,
NumberPtr) {
return 0; }
185 virtual int AGS_EngineDebugHook(
const char *,
int,
int) {
return 0; }
186 virtual void AGS_EngineInitGfx(
const char *driverID,
void *
data) {}
196 _sc(sc), _name(name) {
199 operator bool()
const {
200 return _sc !=
nullptr;
204 _sc->execMethod(_name, params);
205 return params._result;
208 NumberPtr operator()(intptr_t val1)
const {
210 _sc->execMethod(_name, params);
211 return params._result;
213 NumberPtr operator()(intptr_t val1, intptr_t val2)
const {
215 _sc->execMethod(_name, params);
216 return params._result;
218 NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3)
const {
220 _sc->execMethod(_name, params);
221 return params._result;
223 NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3, intptr_t val4)
const {
225 _sc->execMethod(_name, params);
226 return params._result;
230 extern PluginBase *pluginOpen(
const char *filename);
234 extern const char *pluginError();
Definition: ags_plugin.h:207
const intptr_t * data() const
Definition: array.h:207
Common::String format(int formatIndex)
Definition: plugin_base.h:171
Definition: plugin_base.h:131
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: ags_plugin.h:296
Definition: plugin_base.h:151
Definition: plugin_base.h:189