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

sev- noreply at scummvm.org
Mon Oct 16 15:34:48 UTC 2023


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:
cb2cb19256 AGS: Add ags_controller_arcnor plugin (used in Perfect Tides)


Commit: cb2cb192569f4e9cdeeb910b8b39bbd3148aa1fc
    https://github.com/scummvm/scummvm/commit/cb2cb192569f4e9cdeeb910b8b39bbd3148aa1fc
Author: Walter Agazzi (walter.agazzi at protonmail.com)
Date: 2023-10-16T17:34:44+02:00

Commit Message:
AGS: Add ags_controller_arcnor plugin (used in Perfect Tides)

+ minor rework standard AGSController plugin

Changed paths:
  A engines/ags/plugins/ags_controller/ags_controller_arcnor.cpp
  A engines/ags/plugins/ags_controller/ags_controller_arcnor.h
    engines/ags/module.mk
    engines/ags/plugins/ags_controller/ags_controller.cpp
    engines/ags/plugins/ags_controller/ags_controller.h
    engines/ags/plugins/plugin_base.cpp


diff --git a/engines/ags/module.mk b/engines/ags/module.mk
index 1ce1c53937c..683c897f8b5 100644
--- a/engines/ags/module.mk
+++ b/engines/ags/module.mk
@@ -324,6 +324,7 @@ MODULE_OBJS = \
 	plugins/ags_collision_detector/ags_collision_detector.o \
 	plugins/ags_consoles/ags_consoles.o \
 	plugins/ags_controller/ags_controller.o \
+	plugins/ags_controller/ags_controller_arcnor.o \
 	plugins/ags_creditz/ags_creditz.o \
 	plugins/ags_creditz/ags_creditz1.o \
 	plugins/ags_creditz/ags_creditz2.o \
diff --git a/engines/ags/plugins/ags_controller/ags_controller.cpp b/engines/ags/plugins/ags_controller/ags_controller.cpp
index 35b74b2937b..9e03f17327c 100644
--- a/engines/ags/plugins/ags_controller/ags_controller.cpp
+++ b/engines/ags/plugins/ags_controller/ags_controller.cpp
@@ -28,6 +28,25 @@ namespace AGS3 {
 namespace Plugins {
 namespace AGSController {
 
+struct Controller : public IAGSScriptManagedObject {
+public:
+
+	int Dispose(const char *address, bool force) override {
+		return true;
+	}
+
+	const char *GetType() override {
+		return "Controller";
+	};
+
+	int Serialize(const char *address, char *buffer, int bufsize) override {
+		return 0;
+	}
+};
+
+Controller ctrlInterface;
+ConReader ctrlReader;
+
 const char *AGSController::AGS_GetPluginName() {
 	return "AGSController";
 }
@@ -50,6 +69,7 @@ void AGSController::AGS_EngineStartup(IAGSEngine *engine) {
 	SCRIPT_METHOD(ClickMouse, AGSController::ClickMouse);
 
 	_engine->RequestEventHook(AGSE_PREGUIDRAW);
+	_engine->AddManagedObjectReader("Controller", &ctrlReader);
 }
 
 int64 AGSController::AGS_EngineOnEvent(int event, NumberPtr data) {
@@ -61,7 +81,11 @@ int64 AGSController::AGS_EngineOnEvent(int event, NumberPtr data) {
 }
 
 void AGSController::Controller_Update() {
-//	::AGS::g_events->pollEvents();
+	//	::AGS::g_events->pollEvents();
+}
+
+void ConReader::Unserialize(int key, const char *serializedData, int dataSize) {
+	//	no implementation
 }
 
 void AGSController::ControllerCount(ScriptMethodParams &params) {
@@ -79,11 +103,13 @@ void AGSController::ControllerCount(ScriptMethodParams &params) {
 }
 
 void AGSController::Controller_Open(ScriptMethodParams &params) {
-	// No implemented needed
+	Controller *newCtrl = new Controller();
+	_engine->RegisterManagedObject(newCtrl, &ctrlInterface);
+	params._result = newCtrl;
 }
 
 void AGSController::Controller_Close(ScriptMethodParams &params) {
-	// No implemented needed
+	// No implementation needed
 }
 
 void AGSController::Controller_Plugged(ScriptMethodParams &params) {
@@ -93,31 +119,43 @@ void AGSController::Controller_Plugged(ScriptMethodParams &params) {
 
 void AGSController::Controller_GetAxis(ScriptMethodParams &params) {
 	PARAMS1(int, axis);
-	params._result = ::AGS::g_events->getJoystickAxis(axis);
+	if (axis < 0 || axis > 31)
+		params._result = false;
+	else
+		params._result = ::AGS::g_events->getJoystickAxis(axis);
 }
 
 void AGSController::Controller_GetPOV(ScriptMethodParams &params) {
 	// Not supported
+	debug(0, "AGSController: POV is not implemented");
 	params._result = 0;
 }
 
 void AGSController::Controller_IsButtonDown(ScriptMethodParams &params) {
 	PARAMS1(int, button);
-	params._result = ::AGS::g_events->getJoystickButton(button);
+	if (button < 0 || button > 31)
+		params._result = false;
+	else
+		params._result = ::AGS::g_events->getJoystickButton(button);
 }
 
 void AGSController::Controller_GetName(ScriptMethodParams &params) {
 	int joystickNum = ConfMan.getInt("joystick_num");
-	params._result = (joystickNum != -1) ? "Joystick" : "";
+	params._result = (joystickNum != -1) ? _engine->CreateScriptString("Joystick")
+										 : _engine->CreateScriptString("");
 }
 
 void AGSController::Controller_Rumble(ScriptMethodParams &params) {
 	// Not supported
+	debug(0, "AGSController: Rumble is not supported");
 }
 
 void AGSController::Controller_IsButtonDownOnce(ScriptMethodParams &params) {
 	PARAMS1(int, button);
-	params._result = ::AGS::g_events->getJoystickButtonOnce(button);
+	if (button < 0 || button > 31)
+		params._result = false;
+	else
+		params._result = ::AGS::g_events->getJoystickButtonOnce(button);
 }
 
 void AGSController::Controller_PressAnyKey(ScriptMethodParams &params) {
@@ -133,6 +171,7 @@ void AGSController::Controller_PressAnyKey(ScriptMethodParams &params) {
 
 void AGSController::Controller_BatteryStatus(ScriptMethodParams &params) {
 	// Not supported, so return -1 for "UNKNOWN"
+	debug(0, "AGSController: Battery status is not supported");
 	params._result = -1;
 }
 
diff --git a/engines/ags/plugins/ags_controller/ags_controller.h b/engines/ags/plugins/ags_controller/ags_controller.h
index 0386ccfbdb3..689ff8c8889 100644
--- a/engines/ags/plugins/ags_controller/ags_controller.h
+++ b/engines/ags/plugins/ags_controller/ags_controller.h
@@ -28,9 +28,14 @@ namespace AGS3 {
 namespace Plugins {
 namespace AGSController {
 
+class ConReader : public IAGSManagedObjectReader {
+public:
+	virtual void Unserialize(int key, const char *serializedData, int dataSize);
+};
+
 class AGSController : public PluginBase {
 	SCRIPT_HASH(AGSController)
-private:
+protected:
 	void Controller_Update();
 
 	void ControllerCount(ScriptMethodParams &params);
diff --git a/engines/ags/plugins/ags_controller/ags_controller_arcnor.cpp b/engines/ags/plugins/ags_controller/ags_controller_arcnor.cpp
new file mode 100644
index 00000000000..c3d829e2f54
--- /dev/null
+++ b/engines/ags/plugins/ags_controller/ags_controller_arcnor.cpp
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * of the License, or(at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "ags/plugins/ags_controller/ags_controller.h"
+#include "ags/plugins/ags_controller/ags_controller_arcnor.h"
+
+#include "ags/events.h"
+
+namespace AGS3 {
+namespace Plugins {
+namespace AGSController {
+
+
+void AGSControllerArcnor::AGS_EngineStartup(IAGSEngine *engine) {
+	AGSController::AGS_EngineStartup(engine);
+
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_Open^1, AGSControllerArcnor::Controller_Open);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_GetAxis^1, AGSControllerArcnor::Controller_GetAxis);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_IsButtonDown^1, AGSControllerArcnor::Controller_IsButtonDown);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_Rumble^3, AGSControllerArcnor::Controller_Rumble);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_IsButtonDownOnce^1, AGSControllerArcnor::Controller_IsButtonDownOnce);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_IsButtonUpOnce^1, AGSControllerArcnor::Controller_IsButtonUpOnce);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_PressAnyButton, AGSControllerArcnor::Controller_PressAnyKey);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_GetPlayerIndex^0, AGSControllerArcnor::Controller_GetPlayerIndex);
+	SCRIPT_METHOD(AGSControllerArcnor::Controller_SetPlayerIndex^1, AGSControllerArcnor::Controller_SetPlayerIndex);
+	SCRIPT_METHOD(RunVirtualKeyboard, AGSControllerArcnor::RunVirtualKeyboard);
+}
+
+void AGSControllerArcnor::Controller_IsButtonUpOnce(ScriptMethodParams &params) {
+	PARAMS1(int, button);
+	if (button < 0 || button > 31)
+		params._result = false;
+	else
+		params._result = !(::AGS::g_events->getJoystickButtonOnce(button));
+}
+
+void AGSControllerArcnor::Controller_GetPlayerIndex(ScriptMethodParams &params) {
+	//  return -1 as "not available"
+	debug(0, "AGSController: GetPlayerIndex not implemented");
+	params._result = -1;
+}
+
+void AGSControllerArcnor::Controller_SetPlayerIndex(ScriptMethodParams &params) {
+	//	PARAMS1(int, id);
+	//	not implemented
+	debug(0, "AGSController: SetPlayerIndex not implemented");
+}
+
+void AGSControllerArcnor::RunVirtualKeyboard(ScriptMethodParams &params) {
+	//	PARAMS6(int, keyboard_mode, const char *, initialtext, const char *, headertext, const char *, guidetext, const char *, oktext, int, maxchars);
+	debug(0, "AGSController: Virtual Keyboard not implemented");
+	params._result = _engine->CreateScriptString("");
+}
+
+} // namespace AGSController
+} // namespace Plugins
+} // namespace AGS3
diff --git a/engines/ags/plugins/ags_controller/ags_controller_arcnor.h b/engines/ags/plugins/ags_controller/ags_controller_arcnor.h
new file mode 100644
index 00000000000..db8c4c663bc
--- /dev/null
+++ b/engines/ags/plugins/ags_controller/ags_controller_arcnor.h
@@ -0,0 +1,51 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * of the License, or(at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef AGS_PLUGINS_AGSCONTROLLER_AGSCONTROLLER_ARCNOR_H
+#define AGS_PLUGINS_AGSCONTROLLER_AGSCONTROLLER_ARCNOR_H
+
+#include "ags/plugins/ags_controller/ags_controller.h"
+
+namespace AGS3 {
+namespace Plugins {
+namespace AGSController {
+
+class AGSControllerArcnor : public AGSController {
+	SCRIPT_HASH_SUB(AGSControllerArcnor, AGSController)
+private:
+	void Controller_IsButtonUpOnce(ScriptMethodParams &params);
+	void Controller_PressAnyButton(ScriptMethodParams &params);
+	void Controller_GetPlayerIndex(ScriptMethodParams &params);
+	void Controller_SetPlayerIndex(ScriptMethodParams &params);
+	void RunVirtualKeyboard(ScriptMethodParams &params);
+
+public:
+	AGSControllerArcnor() : AGSController() {}
+	virtual ~AGSControllerArcnor() {}
+
+	void AGS_EngineStartup(IAGSEngine *engine) override;
+};
+
+} // namespace AGSController
+} // namespace Plugins
+} // namespace AGS3
+
+#endif
diff --git a/engines/ags/plugins/plugin_base.cpp b/engines/ags/plugins/plugin_base.cpp
index bb76a36aaf0..b147aa1c743 100644
--- a/engines/ags/plugins/plugin_base.cpp
+++ b/engines/ags/plugins/plugin_base.cpp
@@ -28,6 +28,7 @@
 #include "ags/plugins/ags_collision_detector/ags_collision_detector.h"
 #include "ags/plugins/ags_consoles/ags_consoles.h"
 #include "ags/plugins/ags_controller/ags_controller.h"
+#include "ags/plugins/ags_controller/ags_controller_arcnor.h"
 #include "ags/plugins/ags_creditz/ags_creditz1.h"
 #include "ags/plugins/ags_creditz/ags_creditz2.h"
 #include "ags/plugins/ags_fire/ags_fire.h"
@@ -90,6 +91,9 @@ Plugins::PluginBase *pluginOpen(const char *filename) {
 	if (fname.equalsIgnoreCase("AGSController"))
 		return new AGSController::AGSController();
 
+	if (fname.equalsIgnoreCase("agscontrollerplugin"))
+		return new AGSController::AGSControllerArcnor();
+
 	if (fname.equalsIgnoreCase("AGS_Collision_Detector"))
 		return new AGSCollisionDetector::AGSCollisionDetector();
 




More information about the Scummvm-git-logs mailing list