[Scummvm-git-logs] scummvm master -> ae1814553f48feba4f58c0317fe04ae4913eb77c

dreammaster dreammaster at scummvm.org
Mon Jul 19 04:49:24 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ae1814553f AGS: Implement PluginMethod class as proxy for calling script methods


Commit: ae1814553f48feba4f58c0317fe04ae4913eb77c
    https://github.com/scummvm/scummvm/commit/ae1814553f48feba4f58c0317fe04ae4913eb77c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-07-18T21:47:45-07:00

Commit Message:
AGS: Implement PluginMethod class as proxy for calling script methods

Changed paths:
    engines/ags/engine/script/script_runtime.cpp
    engines/ags/engine/script/script_runtime.h
    engines/ags/plugins/ags_creditz/ags_creditz.cpp
    engines/ags/plugins/ags_creditz/ags_creditz.h
    engines/ags/plugins/ags_creditz/ags_creditz2.cpp
    engines/ags/plugins/ags_pal_render/ags_pal_render.cpp
    engines/ags/plugins/ags_pal_render/raycast.cpp
    engines/ags/plugins/ags_plugin.cpp
    engines/ags/plugins/ags_plugin.h
    engines/ags/plugins/ags_waves/ags_waves.cpp
    engines/ags/plugins/ags_waves/vars.h
    engines/ags/plugins/plugin_base.cpp
    engines/ags/plugins/plugin_base.h


diff --git a/engines/ags/engine/script/script_runtime.cpp b/engines/ags/engine/script/script_runtime.cpp
index 27f60814d2..09b5e58cfb 100644
--- a/engines/ags/engine/script/script_runtime.cpp
+++ b/engines/ags/engine/script/script_runtime.cpp
@@ -102,18 +102,19 @@ bool ccAddExternalFunctionForPlugin(const String &name, Plugins::ScriptContainer
 	return _GP(simp_for_plugin).add(name, RuntimeScriptValue().SetPluginMethod(sc, name), nullptr) == 0;
 }
 
-void *ccGetSymbolAddressForPlugin(const String &name) {
+Plugins::PluginMethod ccGetSymbolAddressForPlugin(const String &name) {
 	const ScriptImport *import = _GP(simp_for_plugin).getByName(name);
 	if (import) {
-		return import->Value.Ptr;
+		return Plugins::PluginMethod((Plugins::ScriptContainer *)import->Value.Ptr, name);
 	} else {
 		// Also search the internal symbol table for non-function symbols
 		import = _GP(simp).getByName(name);
 		if (import) {
-			return import->Value.Ptr;
+			return Plugins::PluginMethod((Plugins::ScriptContainer *)import->Value.Ptr, name);
 		}
 	}
-	return nullptr;
+
+	return Plugins::PluginMethod();
 }
 
 // If a while loop does this many iterations without the
diff --git a/engines/ags/engine/script/script_runtime.h b/engines/ags/engine/script/script_runtime.h
index 84d8997742..1895b00e0b 100644
--- a/engines/ags/engine/script/script_runtime.h
+++ b/engines/ags/engine/script/script_runtime.h
@@ -72,7 +72,7 @@ extern void *ccGetSymbolAddress(const String &name);
 // registering functions, compatible with old unsafe call style;
 // this is to be used solely by plugins until plugin inteface is redone
 extern bool ccAddExternalFunctionForPlugin(const String &name, void *pfn);
-extern void *ccGetSymbolAddressForPlugin(const String &name);
+extern Plugins::PluginMethod ccGetSymbolAddressForPlugin(const String &name);
 
 // DEBUG HOOK
 typedef void (*new_line_hook_type)(ccInstance *, int);
diff --git a/engines/ags/plugins/ags_creditz/ags_creditz.cpp b/engines/ags/plugins/ags_creditz/ags_creditz.cpp
index 8e14667894..631480e90d 100644
--- a/engines/ags/plugins/ags_creditz/ags_creditz.cpp
+++ b/engines/ags/plugins/ags_creditz/ags_creditz.cpp
@@ -528,7 +528,7 @@ void AGSCreditz::drawStEffects(int sequence, int id, int style) {
 
 	if (style == 1) {
 		if (set2 >= 0 && _numChars < (int)teksti.size() && _timer2 == 0) {
-			(*_playSound)(set2);
+			_playSound(set2);
 		}
 
 		if (_timer2 <= set1) {
diff --git a/engines/ags/plugins/ags_creditz/ags_creditz.h b/engines/ags/plugins/ags_creditz/ags_creditz.h
index b5c08a82ed..cf9ed4281b 100644
--- a/engines/ags/plugins/ags_creditz/ags_creditz.h
+++ b/engines/ags/plugins/ags_creditz/ags_creditz.h
@@ -111,7 +111,7 @@ protected:
 	};
 
 	Version _version;
-	IntFunction _playSound;
+	PluginMethod _playSound;
 	CreditArray _credits[10];
 	StCreditArray _stCredits[10];
 	bool _creditsRunning = 0, _paused = 0, _staticCredits = 0;
diff --git a/engines/ags/plugins/ags_creditz/ags_creditz2.cpp b/engines/ags/plugins/ags_creditz/ags_creditz2.cpp
index ae3f0136a5..c3caa021a9 100644
--- a/engines/ags/plugins/ags_creditz/ags_creditz2.cpp
+++ b/engines/ags/plugins/ags_creditz/ags_creditz2.cpp
@@ -36,7 +36,7 @@ const char *AGSCreditz2::AGS_GetPluginName() {
 
 void AGSCreditz2::AGS_EngineStartup(IAGSEngine *engine) {
 	PluginBase::AGS_EngineStartup(engine);
-	_playSound = (IntFunction)_engine->GetScriptFunctionAddress("PlaySound");
+	_playSound = _engine->GetScriptFunctionAddress("PlaySound");
 	engine->RequestEventHook(AGSE_POSTSCREENDRAW);
 
 	SCRIPT_METHOD(RunCreditSequence, AGSCreditz2::RunCreditSequence);
diff --git a/engines/ags/plugins/ags_pal_render/ags_pal_render.cpp b/engines/ags/plugins/ags_pal_render/ags_pal_render.cpp
index 58814a979b..a795cafcdc 100644
--- a/engines/ags/plugins/ags_pal_render/ags_pal_render.cpp
+++ b/engines/ags/plugins/ags_pal_render/ags_pal_render.cpp
@@ -1309,8 +1309,7 @@ int DrawReflections(int id, int charobj = 0) {
 	int *obst;
 	int flipped = 0;
 	if (charobj == 0) {
-		int (*sfGetGameParameter)(int, int, int, int);
-		sfGetGameParameter = ((int(*)(int, int, int, int)) engine->GetScriptFunctionAddress("GetGameParameter"));
+		PluginMethod sfGetGameParameter = engine->GetScriptFunctionAddress("GetGameParameter");
 		flipped = sfGetGameParameter(13, currchar->view + 1, currchar->loop, currchar->frame);
 	} else flipped = 0;
 	obst = new int [w];
diff --git a/engines/ags/plugins/ags_pal_render/raycast.cpp b/engines/ags/plugins/ags_pal_render/raycast.cpp
index f319654d7e..023da8a2fc 100644
--- a/engines/ags/plugins/ags_pal_render/raycast.cpp
+++ b/engines/ags/plugins/ags_pal_render/raycast.cpp
@@ -1275,8 +1275,7 @@ void AGSPalRender::Raycast_Render(ScriptMethodParams &params) {
 			if (vf == nullptr) engine->AbortGame("Raycast_Render: Unable to load viewframe of sprite.");
 			else {
 				sprite[spriteOrder[i]].texture = vf->pic;
-				int (*sfGetGameParameter)(int, int, int, int);
-				sfGetGameParameter = ((int(*)(int, int, int, int)) engine->GetScriptFunctionAddress("GetGameParameter"));
+				PluginMethod sfGetGameParameter = engine->GetScriptFunctionAddress("GetGameParameter");
 				flipped = sfGetGameParameter(13, sprite[spriteOrder[i]].view, loop, sprite[spriteOrder[i]].frame);
 			}
 		}
diff --git a/engines/ags/plugins/ags_plugin.cpp b/engines/ags/plugins/ags_plugin.cpp
index c24ae9758e..247460f44a 100644
--- a/engines/ags/plugins/ags_plugin.cpp
+++ b/engines/ags/plugins/ags_plugin.cpp
@@ -443,7 +443,7 @@ int IAGSEngine::GetWalkbehindBaseline(int32 wa) {
 		quit("!IAGSEngine::GetWalkBehindBase: invalid walk-behind area specified");
 	return _G(croom)->walkbehind_base[wa];
 }
-void *IAGSEngine::GetScriptFunctionAddress(const char *funcName) {
+Plugins::PluginMethod IAGSEngine::GetScriptFunctionAddress(const char *funcName) {
 	return ccGetSymbolAddressForPlugin(funcName);
 }
 int IAGSEngine::GetBitmapTransparentColor(BITMAP *bmp) {
diff --git a/engines/ags/plugins/ags_plugin.h b/engines/ags/plugins/ags_plugin.h
index 887db41159..8285731fd9 100644
--- a/engines/ags/plugins/ags_plugin.h
+++ b/engines/ags/plugins/ags_plugin.h
@@ -427,7 +427,7 @@ public:
 	// get the walk-behind baseline of a specific WB area
 	AGSIFUNC(int)    GetWalkbehindBaseline(int32 walkbehind);
 	// get the address of a script function
-	AGSIFUNC(void *) GetScriptFunctionAddress(const char *funcName);
+	AGSIFUNC(Plugins::PluginMethod) GetScriptFunctionAddress(const char *funcName);
 	// get the transparent colour of a bitmap
 	AGSIFUNC(int)    GetBitmapTransparentColor(BITMAP *);
 	// get the character scaling level at a particular point
diff --git a/engines/ags/plugins/ags_waves/ags_waves.cpp b/engines/ags/plugins/ags_waves/ags_waves.cpp
index ccec1fef41..1c879ec951 100644
--- a/engines/ags/plugins/ags_waves/ags_waves.cpp
+++ b/engines/ags/plugins/ags_waves/ags_waves.cpp
@@ -43,9 +43,9 @@ void AGSWaves::AGS_EngineStartup(IAGSEngine *engine) {
 
 	StartingValues();
 
-	Character_GetX = (SCAPI_CHARACTER_GETX)engine->GetScriptFunctionAddress("Character::get_X");
-	Character_GetY = (SCAPI_CHARACTER_GETY)engine->GetScriptFunctionAddress("Character::get_Y");
-	Character_ID = (SCAPI_CHARACTER_ID)engine->GetScriptFunctionAddress("Character::ID");
+	Character_GetX = engine->GetScriptFunctionAddress("Character::get_X");
+	Character_GetY = engine->GetScriptFunctionAddress("Character::get_Y");
+	Character_ID = engine->GetScriptFunctionAddress("Character::ID");
 
 	SCRIPT_METHOD(DrawScreenEffect, AGSWaves::DrawScreenEffect);
 	SCRIPT_METHOD(SFX_Play, AGSWaves::SFX_Play);
diff --git a/engines/ags/plugins/ags_waves/vars.h b/engines/ags/plugins/ags_waves/vars.h
index 458b95774a..45f4726649 100644
--- a/engines/ags/plugins/ags_waves/vars.h
+++ b/engines/ags/plugins/ags_waves/vars.h
@@ -123,9 +123,9 @@ struct Vars {
 	int screen_color_depth = 32;
 	AGSCharacter *playerCharacter = nullptr;
 
-	SCAPI_CHARACTER_GETX Character_GetX = nullptr;
-	SCAPI_CHARACTER_GETY Character_GetY = nullptr;
-	SCAPI_CHARACTER_ID   Character_ID = nullptr;
+	PluginMethod Character_GetX;
+	PluginMethod Character_GetY;
+	PluginMethod Character_ID;
 
 	getMus MusicLoads[80];
 	Soundeffect SFX[500];
diff --git a/engines/ags/plugins/plugin_base.cpp b/engines/ags/plugins/plugin_base.cpp
index c5364b77e0..58701db148 100644
--- a/engines/ags/plugins/plugin_base.cpp
+++ b/engines/ags/plugins/plugin_base.cpp
@@ -147,6 +147,32 @@ const char *pluginError() {
 
 /*------------------------------------------------------------------*/
 
+ScriptMethodParams::ScriptMethodParams() {
+
+}
+
+ScriptMethodParams::ScriptMethodParams(int val1) {
+	push_back(val1);
+}
+
+ScriptMethodParams::ScriptMethodParams(int val1, int val2) {
+	push_back(val1);
+	push_back(val2);
+}
+
+ScriptMethodParams::ScriptMethodParams(int val1, int val2, int val3) {
+	push_back(val1);
+	push_back(val2);
+	push_back(val3);
+}
+
+ScriptMethodParams::ScriptMethodParams(int val1, int val2, int val3, int val4) {
+	push_back(val1);
+	push_back(val2);
+	push_back(val3);
+	push_back(val4);
+}
+
 #define GET_CHAR c = format[0]; format.deleteChar(0)
 
 Common::String ScriptMethodParams::format(int formatIndex) {
diff --git a/engines/ags/plugins/plugin_base.h b/engines/ags/plugins/plugin_base.h
index 1f78b6ebf1..86cd90d746 100644
--- a/engines/ags/plugins/plugin_base.h
+++ b/engines/ags/plugins/plugin_base.h
@@ -132,6 +132,12 @@ class ScriptMethodParams : public Common::Array<intptr_t> {
 public:
 	NumberPtr _result;
 
+	ScriptMethodParams();
+	ScriptMethodParams(int val1);
+	ScriptMethodParams(int val1, int val2);
+	ScriptMethodParams(int val1, int val2, int val3);
+	ScriptMethodParams(int val1, int val2, int val3, int val4);
+
 	/**
 	 * Form of Common::String::format for the parameters array.
 	 * @param formatIndex	Param index of the format specifier string
@@ -176,6 +182,47 @@ public:
 	virtual void   AGS_EngineInitGfx(const char *driverID, void *data) {}
 };
 
+class PluginMethod {
+private:
+	ScriptContainer *_sc;
+	Common::String _name;
+public:
+	PluginMethod() : _sc(nullptr) {}
+	PluginMethod(ScriptContainer *sc, const Common::String &name) :
+		_sc(sc), _name(name) {
+	}
+
+	bool isValid() const {
+		return _sc != nullptr;
+	}
+
+	bool operator()(ScriptMethodParams &params) {
+		_sc->execMethod(_name, params);
+		return params._result;
+	}
+
+	NumberPtr operator()(intptr_t val1) {
+		ScriptMethodParams params(val1);
+		_sc->execMethod(_name, params);
+		return params._result;
+	}
+	NumberPtr operator()(intptr_t val1, intptr_t val2) {
+		ScriptMethodParams params(val1, val2);
+		_sc->execMethod(_name, params);
+		return params._result;
+	}
+	NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3) {
+		ScriptMethodParams params(val1, val2, val3);
+		_sc->execMethod(_name, params);
+		return params._result;
+	}
+	NumberPtr operator()(intptr_t val1, intptr_t val2, intptr_t val3, intptr_t val4) {
+		ScriptMethodParams params(val1, val2, val3, val4);
+		_sc->execMethod(_name, params);
+		return params._result;
+	}
+};
+
 extern PluginBase *pluginOpen(const char *filename);
 
 extern int pluginClose(Plugins::PluginBase *lib);




More information about the Scummvm-git-logs mailing list