[Scummvm-git-logs] scummvm master -> 9dd5f7fea850b5fbfe30cb8765d62e81d09da13c
dreammaster
dreammaster at scummvm.org
Sun Apr 18 04:25:14 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:
9dd5f7fea8 AGS: Implementing AGSController plugin
Commit: 9dd5f7fea850b5fbfe30cb8765d62e81d09da13c
https://github.com/scummvm/scummvm/commit/9dd5f7fea850b5fbfe30cb8765d62e81d09da13c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-04-17T21:25:06-07:00
Commit Message:
AGS: Implementing AGSController plugin
Changed paths:
A engines/ags/plugins/ags_controller/ags_controller.cpp
A engines/ags/plugins/ags_controller/ags_controller.h
engines/ags/events.cpp
engines/ags/events.h
engines/ags/module.mk
engines/ags/plugins/plugin_base.cpp
diff --git a/engines/ags/events.cpp b/engines/ags/events.cpp
index 521ffef864..73427362db 100644
--- a/engines/ags/events.cpp
+++ b/engines/ags/events.cpp
@@ -32,6 +32,8 @@ EventsManager *g_events;
EventsManager::EventsManager() {
g_events = this;
_keys.resize(AGS3::__allegro_KEY_MAX);
+ Common::fill(&_joystickAxis[0], &_joystickAxis[32], 0);
+ Common::fill(&_joystickButton[0], &_joystickButton[32], 0);
}
EventsManager::~EventsManager() {
@@ -42,22 +44,43 @@ void EventsManager::pollEvents() {
Common::Event e;
while (g_system->getEventManager()->pollEvent(e)) {
- if (e.type == Common::EVENT_QUIT || e.type == Common::EVENT_RETURN_TO_LAUNCHER) {
+ switch (e.type) {
+ case Common::EVENT_QUIT:
+ case Common::EVENT_RETURN_TO_LAUNCHER:
_G(want_exit) = true;
_G(abort_engine) = true;
_G(check_dynamic_sprites_at_exit) = false;
+ break;
- } else if (e.type == Common::EVENT_KEYDOWN) {
+ case Common::EVENT_JOYAXIS_MOTION:
+ assert(e.joystick.axis < 32);
+ _joystickAxis[e.joystick.axis] = e.joystick.position;
+ break;
+
+ case Common::EVENT_JOYBUTTON_DOWN:
+ assert(e.joystick.button < 32);
+ _joystickButton[e.joystick.button] = true;
+ break;
+
+ case Common::EVENT_JOYBUTTON_UP:
+ assert(e.joystick.button < 32);
+ _joystickButton[e.joystick.button] = false;
+ break;
+
+ case Common::EVENT_KEYDOWN:
updateKeys(e.kbd, true);
if (!isModifierKey(e.kbd.keycode)) {
// Add keypresses to the pending key list
_pendingKeys.push(e.kbd);
}
- } else if (e.type == Common::EVENT_KEYUP) {
+ break;
+
+ case Common::EVENT_KEYUP:
updateKeys(e.kbd, false);
+ break;
- } else {
+ default:
// Add other event types to the pending events queue. If the event is a
// mouse move and the prior one was also, then discard the prior one.
// This'll help prevent too many mouse move events accumulating
@@ -66,6 +89,7 @@ void EventsManager::pollEvents() {
_pendingEvents.back() = e;
else
_pendingEvents.push(e);
+ break;
}
}
}
diff --git a/engines/ags/events.h b/engines/ags/events.h
index def00a1a1c..b0813af80e 100644
--- a/engines/ags/events.h
+++ b/engines/ags/events.h
@@ -35,6 +35,8 @@ private:
Common::Queue<Common::Event> _pendingEvents;
Common::Queue<Common::KeyState> _pendingKeys;
Common::Array<bool> _keys;
+ int16 _joystickAxis[32];
+ bool _joystickButton[32];
bool isModifierKey(const Common::KeyCode &keycode) const;
bool isExtendedKey(const Common::KeyCode &keycode) const;
@@ -79,6 +81,32 @@ public:
* Returns the bitset of currently pressed modifier keys
*/
uint getModifierFlags() const;
+
+ /**
+ * Gets a joystick axis position
+ */
+ int16 getJoystickAxis(byte axis) const {
+ assert(axis < 32);
+ return _joystickAxis[axis];
+ }
+
+ /**
+ * Gets whether a given joystick button is down
+ */
+ bool getJoystickButton(byte button) const {
+ assert(button < 32);
+ return _joystickButton[button];
+ }
+
+ /**
+ * Gets whether a given joystick button is down once
+ */
+ bool getJoystickButtonOnce(byte button) {
+ assert(button < 32);
+ bool result = _joystickButton[button];
+ _joystickButton[button] = false;
+ return result;
+ }
};
extern EventsManager *g_events;
diff --git a/engines/ags/module.mk b/engines/ags/module.mk
index 4ef8260e08..981b1f47b8 100644
--- a/engines/ags/module.mk
+++ b/engines/ags/module.mk
@@ -287,6 +287,7 @@ MODULE_OBJS = \
plugins/agsplugin.o \
plugins/plugin_base.o \
plugins/ags_blend/ags_blend.o \
+ plugins/ags_controller/ags_controller.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
new file mode 100644
index 0000000000..4770191277
--- /dev/null
+++ b/engines/ags/plugins/ags_controller/ags_controller.cpp
@@ -0,0 +1,150 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "ags/plugins/ags_controller/ags_controller.h"
+#include "ags/events.h"
+#include "common/config-manager.h"
+#include "common/system.h"
+
+namespace AGS3 {
+namespace Plugins {
+namespace AGSController {
+
+IAGSEngine *AGSController::_engine;
+
+AGSController::AGSController() : PluginBase() {
+ _engine = nullptr;
+ DLL_METHOD(AGS_GetPluginName);
+ DLL_METHOD(AGS_EngineStartup);
+ DLL_METHOD(AGS_EngineShutdown);
+ DLL_METHOD(AGS_EngineOnEvent);
+}
+
+const char *AGSController::AGS_GetPluginName() {
+ return "AGSController";
+}
+
+void AGSController::AGS_EngineStartup(IAGSEngine *engine) {
+ _engine = engine;
+
+ SCRIPT_METHOD_EXT(ControllerCount, ControllerCount);
+ SCRIPT_METHOD_EXT(Controller::Open, Controller_Open);
+ SCRIPT_METHOD_EXT(Controller::Close, Controller_Close);
+ SCRIPT_METHOD_EXT(Controller::Plugged, Controller_Plugged);
+ SCRIPT_METHOD_EXT(Controller::GetAxis, Controller_GetAxis);
+ SCRIPT_METHOD_EXT(Controller::GetPOV, Controller_GetPOV);
+ SCRIPT_METHOD_EXT(Controller::IsButtonDown, Controller_IsButtonDown);
+ SCRIPT_METHOD_EXT(Controller::GetName^0, Controller_GetName);
+ SCRIPT_METHOD_EXT(Controller::Rumble, Controller_Rumble);
+ SCRIPT_METHOD_EXT(Controller::IsButtonDownOnce, Controller_IsButtonDownOnce);
+ SCRIPT_METHOD_EXT(Controller::PressAnyKey, Controller_PressAnyKey);
+ SCRIPT_METHOD_EXT(Controller::BatteryStatus, Controller_BatteryStatus);
+ SCRIPT_METHOD_EXT(ClickMouse, ClickMouse);
+
+ _engine->RequestEventHook(AGSE_PREGUIDRAW);
+}
+
+void AGSController::AGS_EngineShutdown() {
+}
+
+int64 AGSController::AGS_EngineOnEvent(int event, NumberPtr data) {
+ if (event == AGSE_PREGUIDRAW) {
+ Controller_Update();
+ }
+
+ return 0;
+}
+
+void AGSController::Controller_Update() {
+ ::AGS::g_events->pollEvents();
+}
+
+void AGSController::ControllerCount(ScriptMethodParams ¶ms) {
+ int joystickNum = ConfMan.getInt("joystick_num");
+ params._result = (joystickNum == -1) ? 0 : 1;
+}
+
+void AGSController::Controller_Open(ScriptMethodParams ¶ms) {
+ // No implemented needed
+}
+
+void AGSController::Controller_Close(ScriptMethodParams ¶ms) {
+ // No implemented needed
+}
+
+void AGSController::Controller_Plugged(ScriptMethodParams ¶ms) {
+ int joystickNum = ConfMan.getInt("joystick_num");
+ params._result = joystickNum != -1;
+}
+
+void AGSController::Controller_GetAxis(ScriptMethodParams ¶ms) {
+ PARAMS1(int, axis);
+ params._result = ::AGS::g_events->getJoystickAxis(axis);
+}
+
+void AGSController::Controller_GetPOV(ScriptMethodParams ¶ms) {
+ // Not supported
+ params._result = 0;
+}
+
+void AGSController::Controller_IsButtonDown(ScriptMethodParams ¶ms) {
+ PARAMS1(int, button);
+ params._result = ::AGS::g_events->getJoystickButton(button);
+}
+
+void AGSController::Controller_GetName(ScriptMethodParams ¶ms) {
+ int joystickNum = ConfMan.getInt("joystick_num");
+ params._result = (joystickNum != -1) ? "Joystick" :"";
+}
+
+void AGSController::Controller_Rumble(ScriptMethodParams ¶ms) {
+ // Not supported
+}
+
+void AGSController::Controller_IsButtonDownOnce(ScriptMethodParams ¶ms) {
+ PARAMS1(int, button);
+ params._result = ::AGS::g_events->getJoystickButtonOnce(button);
+}
+
+void AGSController::Controller_PressAnyKey(ScriptMethodParams ¶ms) {
+ params._result = -1;
+
+ for (int index = 0; index < 32; ++index) {
+ if (::AGS::g_events->getJoystickButton(index)) {
+ params._result = index;
+ break;
+ }
+ }
+}
+
+void AGSController::Controller_BatteryStatus(ScriptMethodParams ¶ms) {
+ // Not supported, so return -1 for "UNKNOWN"
+ params._result = -1;
+}
+
+void AGSController::ClickMouse(ScriptMethodParams ¶ms) {
+ error("TODO: ClickMouse - find out what params it gets");
+}
+
+} // namespace AGSController
+} // namespace Plugins
+} // namespace AGS3
diff --git a/engines/ags/plugins/ags_controller/ags_controller.h b/engines/ags/plugins/ags_controller/ags_controller.h
new file mode 100644
index 0000000000..0577ff7e01
--- /dev/null
+++ b/engines/ags/plugins/ags_controller/ags_controller.h
@@ -0,0 +1,66 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef AGS_PLUGINS_AGSCONTROLLER_AGSCONTROLLER_H
+#define AGS_PLUGINS_AGSCONTROLLER_AGSCONTROLLER_H
+
+#include "ags/plugins/plugin_base.h"
+
+namespace AGS3 {
+namespace Plugins {
+namespace AGSController {
+
+class AGSController : public PluginBase {
+private:
+ static IAGSEngine *_engine;
+
+private:
+ static const char *AGS_GetPluginName();
+ static void AGS_EngineStartup(IAGSEngine *engine);
+ static void AGS_EngineShutdown();
+ static int64 AGS_EngineOnEvent(int event, NumberPtr data);
+
+private:
+ static void Controller_Update();
+
+ static void ControllerCount(ScriptMethodParams ¶ms);
+ static void Controller_Open(ScriptMethodParams ¶ms);
+ static void Controller_Plugged(ScriptMethodParams ¶ms);
+ static void Controller_GetAxis(ScriptMethodParams ¶ms);
+ static void Controller_GetPOV(ScriptMethodParams ¶ms);
+ static void Controller_IsButtonDown(ScriptMethodParams ¶ms);
+ static void Controller_Close(ScriptMethodParams ¶ms);
+ static void Controller_GetName(ScriptMethodParams ¶ms);
+ static void Controller_Rumble(ScriptMethodParams ¶ms);
+ static void Controller_IsButtonDownOnce(ScriptMethodParams ¶ms);
+ static void Controller_PressAnyKey(ScriptMethodParams ¶ms);
+ static void Controller_BatteryStatus(ScriptMethodParams ¶ms);
+ static void ClickMouse(ScriptMethodParams ¶ms);
+public:
+ AGSController();
+};
+
+} // namespace AGSController
+} // namespace Plugins
+} // namespace AGS3
+
+#endif
diff --git a/engines/ags/plugins/plugin_base.cpp b/engines/ags/plugins/plugin_base.cpp
index c8b248d4f5..670db1329b 100644
--- a/engines/ags/plugins/plugin_base.cpp
+++ b/engines/ags/plugins/plugin_base.cpp
@@ -23,6 +23,7 @@
#include "ags/lib/allegro.h"
#include "ags/plugins/plugin_base.h"
#include "ags/plugins/ags_blend/ags_blend.h"
+#include "ags/plugins/ags_controller/ags_controller.h"
#include "ags/plugins/ags_creditz/ags_creditz1.h"
#include "ags/plugins/ags_creditz/ags_creditz2.h"
#include "ags/plugins/ags_flashlight/ags_flashlight.h"
@@ -63,6 +64,9 @@ void *pluginOpen(const char *filename) {
if (fname.equalsIgnoreCase("AGSBlend"))
return new AGSBlend::AGSBlend();
+ if (fname.equalsIgnoreCase("AGSController"))
+ return new AGSController::AGSController();
+
if (fname.equalsIgnoreCase("agsCreditz"))
return new AGSCreditz::AGSCreditz1();
More information about the Scummvm-git-logs
mailing list