[Scummvm-git-logs] scummvm master -> 930028522e35a03d869740ad5f3daa7b4434d548

ccawley2011 noreply at scummvm.org
Mon Dec 19 00:36:55 UTC 2022


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

Summary:
fb9416eacb ANDROID: Map gamepad inputs to joystick events
c33a65e32b ANDROID: Map Joystick inputs to Joystick events
930028522e ANDROID: Simplify Joystick axis scaling


Commit: fb9416eacbfbd60c0c9446ef971d2a01958d2bcf
    https://github.com/scummvm/scummvm/commit/fb9416eacbfbd60c0c9446ef971d2a01958d2bcf
Author: Rudis Muiznieks (rudis at sitosis.com)
Date: 2022-12-19T00:36:51Z

Commit Message:
ANDROID: Map gamepad inputs to joystick events

Previously most buttons were being ignored and A and B were mapped to
mouse clicks. This maps A and B and several more buttons to Joypad
button presses instead.

Changed paths:
    backends/platform/android/events.cpp


diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 8f228e51846..5ab311977f8 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1106,10 +1106,10 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 	case JE_GAMEPAD:
 		switch (arg1) {
 		case AKEY_EVENT_ACTION_DOWN:
-			e.type = Common::EVENT_KEYDOWN;
+			e.type = Common::EVENT_JOYBUTTON_DOWN;
 			break;
 		case AKEY_EVENT_ACTION_UP:
-			e.type = Common::EVENT_KEYUP;
+			e.type = Common::EVENT_JOYBUTTON_UP;
 			break;
 		default:
 			LOGE("unhandled jaction on gamepad key: %d", arg1);
@@ -1117,32 +1117,48 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 		}
 
 		switch (arg2) {
-		case AKEYCODE_BUTTON_A:
-		case AKEYCODE_BUTTON_B:
-			switch (arg1) {
-			case AKEY_EVENT_ACTION_DOWN:
-				e.type = (arg2 == AKEYCODE_BUTTON_A?
-					  Common::EVENT_LBUTTONDOWN :
-					  Common::EVENT_RBUTTONDOWN);
-				break;
-			case AKEY_EVENT_ACTION_UP:
-				e.type = (arg2 == AKEYCODE_BUTTON_A?
-					  Common::EVENT_LBUTTONUP :
-					  Common::EVENT_RBUTTONUP);
-				break;
-			}
+		case AKEYCODE_BUTTON_START:
+			e.joystick.button = Common::JOYSTICK_BUTTON_START;
+			break;
 
-			e.mouse = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+		case AKEYCODE_BUTTON_SELECT:
+			e.joystick.button = Common::JOYSTICK_BUTTON_BACK;
+			break;
+
+		case AKEYCODE_BUTTON_MODE:
+			e.joystick.button = Common::JOYSTICK_BUTTON_GUIDE;
+			break;
 
+		case AKEYCODE_BUTTON_A:
+			e.joystick.button = Common::JOYSTICK_BUTTON_A;
+			break;
+
+		case AKEYCODE_BUTTON_B:
+			e.joystick.button = Common::JOYSTICK_BUTTON_B;
 			break;
 
 		case AKEYCODE_BUTTON_X:
-			e.kbd.keycode = Common::KEYCODE_ESCAPE;
-			e.kbd.ascii = Common::ASCII_ESCAPE;
+			e.joystick.button = Common::JOYSTICK_BUTTON_X;
 			break;
 
 		case AKEYCODE_BUTTON_Y:
-			e.type = Common::EVENT_MAINMENU;
+			e.joystick.button = Common::JOYSTICK_BUTTON_Y;
+			break;
+
+		case AKEYCODE_BUTTON_L1:
+			e.joystick.button = Common::JOYSTICK_BUTTON_LEFT_SHOULDER;
+			break;
+
+		case AKEYCODE_BUTTON_R1:
+			e.joystick.button = Common::JOYSTICK_BUTTON_RIGHT_SHOULDER;
+			break;
+
+		case AKEYCODE_BUTTON_THUMBL:
+			e.joystick.button = Common::JOYSTICK_BUTTON_LEFT_STICK;
+			break;
+
+		case AKEYCODE_BUTTON_THUMBR:
+			e.joystick.button = Common::JOYSTICK_BUTTON_RIGHT_STICK;
 			break;
 
 		default:


Commit: c33a65e32b5a56da5f1edb7f7dca8ac52882e6da
    https://github.com/scummvm/scummvm/commit/c33a65e32b5a56da5f1edb7f7dca8ac52882e6da
Author: Rudis Muiznieks (rudis at sitosis.com)
Date: 2022-12-19T00:36:51Z

Commit Message:
ANDROID: Map Joystick inputs to Joystick events

Previously joystick motion inputs were being translated to direct mouse
movement events. This changes those into Joystick AXIS events instead.
Also updates joystick button inputs into joystick button events instead
of mouse clicks and key presses.

Changed paths:
    backends/platform/android/android.h
    backends/platform/android/events.cpp
    backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java


diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 432caa3e61d..abfc236e529 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -160,6 +160,8 @@ private:
 	int _trackball_scale;
 	int _dpad_scale;
 	int _joystick_scale;
+	int _axisPosX;
+	int _axisPosY;
 //	int _fingersDown;
 	int _firstPointerId;
 	int _secondPointerId;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 5ab311977f8..5070a8de169 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1175,19 +1175,26 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 		switch (arg1) {
 		// AMOTION_EVENT_ACTION_MOVE is 2 in NDK (https://developer.android.com/ndk/reference/group/input)
 		case AMOTION_EVENT_ACTION_MOVE:
-			e.mouse = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
-			e.type = Common::EVENT_MOUSEMOVE;
-
 			// already multiplied by 100
-			e.mouse.x += arg2 * _joystick_scale / _eventScaleX;
-			e.mouse.y += arg3 * _joystick_scale / _eventScaleY;
+			_axisPosX = (int32)arg2 * Common::JOYAXIS_MAX / _eventScaleX;
+			_axisPosY = (int32)arg3 * Common::JOYAXIS_MAX / _eventScaleY;
+
+			e.type = Common::EVENT_JOYAXIS_MOTION;
+
+			e.joystick.axis = Common::JOYSTICK_AXIS_LEFT_STICK_X;
+			e.joystick.position = CLIP<int32>(_axisPosX, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
+			pushEvent(e);
+
+			e.joystick.axis = Common::JOYSTICK_AXIS_LEFT_STICK_Y;
+			e.joystick.position = CLIP<int32>(_axisPosY, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
+			pushEvent(e);
 
 			break;
 		case AKEY_EVENT_ACTION_DOWN:
-			e.type = Common::EVENT_KEYDOWN;
+			e.type = Common::EVENT_JOYBUTTON_DOWN;
 			break;
 		case AKEY_EVENT_ACTION_UP:
-			e.type = Common::EVENT_KEYUP;
+			e.type = Common::EVENT_JOYBUTTON_UP;
 			break;
 		default:
 			LOGE("unhandled jaction on joystick: %d", arg1);
@@ -1197,40 +1204,28 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 		if (arg1 != AMOTION_EVENT_ACTION_MOVE) {
 			switch (arg2) {
 			case AKEYCODE_BUTTON_1:
-			case AKEYCODE_BUTTON_2:
-				switch (arg1) {
-				case AKEY_EVENT_ACTION_DOWN:
-					e.type = (arg2 == AKEYCODE_BUTTON_1?
-						  Common::EVENT_LBUTTONDOWN :
-						  Common::EVENT_RBUTTONDOWN);
-					break;
-				case AKEY_EVENT_ACTION_UP:
-					e.type = (arg2 == AKEYCODE_BUTTON_1?
-						  Common::EVENT_LBUTTONUP :
-						  Common::EVENT_RBUTTONUP);
-					break;
-				}
-
-				e.mouse = dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->getMousePosition();
+				e.joystick.button = Common::JOYSTICK_BUTTON_A;
+				break;
 
+			case AKEYCODE_BUTTON_2:
+				e.joystick.button = Common::JOYSTICK_BUTTON_B;
 				break;
 
 			case AKEYCODE_BUTTON_3:
-				e.kbd.keycode = Common::KEYCODE_ESCAPE;
-				e.kbd.ascii = Common::ASCII_ESCAPE;
+				e.joystick.button = Common::JOYSTICK_BUTTON_X;
 				break;
 
 			case AKEYCODE_BUTTON_4:
-				e.type = Common::EVENT_MAINMENU;
+				e.joystick.button = Common::JOYSTICK_BUTTON_Y;
 				break;
 
 			default:
 				LOGW("unmapped gamepad key: %d", arg2);
 				return;
 			}
-		}
 
-		pushEvent(e);
+			pushEvent(e);
+		}
 
 		return;
 
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
index 5ea0e42c9de..3ab743d3256 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
@@ -112,6 +112,8 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 	}
 
 	private void processJoystickInput(MotionEvent event, int historyPos) {
+		// TODO: make left stick, right stick, and d-pad distinguishable
+		// from each other. Also, handle analog triggers.
 
 		InputDevice inputDevice = event.getDevice();
 
@@ -121,7 +123,9 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		float x = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_X, historyPos);
 		//Log.d(ScummVM.LOG_TAG, "JOYSTICK - LEFT: x= " +x);
 		if (x == 0) {
-			x = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_X, historyPos);
+			// reducing to 1/3 since hat axis is non-analog, and 100% of axis max
+			// is way too fast when used for cursor movement
+			x = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_X, historyPos) * 0.33f;
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - HAT: x= " +x);
 		}
 		if (x == 0) {
@@ -135,7 +139,7 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		float y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_Y, historyPos);
 		//Log.d(ScummVM.LOG_TAG, "JOYSTICK - LEFT: y= " +y);
 		if (y == 0) {
-			y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_Y, historyPos);
+			y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_Y, historyPos) * 0.33f;
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - HAT: y= " +y);
 		}
 		if (y == 0) {
@@ -149,10 +153,11 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		if (Math.abs(x * 100) < 20.0f && Math.abs(y * 100) < 20.0f) {
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - pushEvent(): STOPPED: " + (int)(x * 100) + " y= " + (int)(y * 100));
 			removeMessages();
-			// do the move anyway, just don't repeat
+			// do the move, then signal the joystick has returned to center pos
 			repeatMove();
 			repeatingX = 0.0f;
 			repeatingY = 0.0f;
+			repeatMove();
 		} else {
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - pushEvent(): x= " + (int)(x * 100) + " y= " + (int)(y * 100));
 			if (repeatingX != 0.0f || repeatingY != 0.0f) {


Commit: 930028522e35a03d869740ad5f3daa7b4434d548
    https://github.com/scummvm/scummvm/commit/930028522e35a03d869740ad5f3daa7b4434d548
Author: Rudis Muiznieks (rudis at sitosis.com)
Date: 2022-12-19T00:36:51Z

Commit Message:
ANDROID: Simplify Joystick axis scaling

The scaling of Joystick axis values has been moved to the Java event
handler.

Changed paths:
    backends/platform/android/android.h
    backends/platform/android/events.cpp
    backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
    backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java


diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index abfc236e529..432caa3e61d 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -160,8 +160,6 @@ private:
 	int _trackball_scale;
 	int _dpad_scale;
 	int _joystick_scale;
-	int _axisPosX;
-	int _axisPosY;
 //	int _fingersDown;
 	int _firstPointerId;
 	int _secondPointerId;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 5070a8de169..31695253817 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1175,18 +1175,14 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
 		switch (arg1) {
 		// AMOTION_EVENT_ACTION_MOVE is 2 in NDK (https://developer.android.com/ndk/reference/group/input)
 		case AMOTION_EVENT_ACTION_MOVE:
-			// already multiplied by 100
-			_axisPosX = (int32)arg2 * Common::JOYAXIS_MAX / _eventScaleX;
-			_axisPosY = (int32)arg3 * Common::JOYAXIS_MAX / _eventScaleY;
-
 			e.type = Common::EVENT_JOYAXIS_MOTION;
 
 			e.joystick.axis = Common::JOYSTICK_AXIS_LEFT_STICK_X;
-			e.joystick.position = CLIP<int32>(_axisPosX, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
+			e.joystick.position = CLIP<int32>(arg2, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
 			pushEvent(e);
 
 			e.joystick.axis = Common::JOYSTICK_AXIS_LEFT_STICK_Y;
-			e.joystick.position = CLIP<int32>(_axisPosY, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
+			e.joystick.position = CLIP<int32>(arg3, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX);
 			pushEvent(e);
 
 			break;
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
index ffbe79496a1..668fd3ddc44 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsBase.java
@@ -60,6 +60,9 @@ public class ScummVMEventsBase implements
 	public static final int TOUCH_MODE_GAMEPAD = 2;
 	public static final int TOUCH_MODE_MAX = 3;
 
+	public static final int JOYSTICK_AXIS_MAX = 32767;
+	public static final float JOYSTICK_AXIS_HAT_SCALE = 0.33f;
+
 	final protected Context _context;
 	final protected ScummVM _scummvm;
 	final protected GestureDetector _gd;
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
index 3ab743d3256..ed57fe50934 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEventsModern.java
@@ -105,8 +105,8 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 
 	private boolean repeatMove() {
 		_scummvm.pushEvent(JE_JOYSTICK, MotionEvent.ACTION_MOVE,
-			(int) (repeatingX * 100),
-			(int) (repeatingY * 100),
+			(int) (repeatingX * JOYSTICK_AXIS_MAX),
+			(int) (repeatingY * JOYSTICK_AXIS_MAX),
 			0, 0, 0);
 		return true;
 	}
@@ -125,7 +125,7 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		if (x == 0) {
 			// reducing to 1/3 since hat axis is non-analog, and 100% of axis max
 			// is way too fast when used for cursor movement
-			x = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_X, historyPos) * 0.33f;
+			x = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_X, historyPos) * JOYSTICK_AXIS_HAT_SCALE;
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - HAT: x= " +x);
 		}
 		if (x == 0) {
@@ -139,7 +139,7 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		float y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_Y, historyPos);
 		//Log.d(ScummVM.LOG_TAG, "JOYSTICK - LEFT: y= " +y);
 		if (y == 0) {
-			y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_Y, historyPos) * 0.33f;
+			y = getCenteredAxis(event, inputDevice, MotionEvent.AXIS_HAT_Y, historyPos) * JOYSTICK_AXIS_HAT_SCALE;
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - HAT: y= " +y);
 		}
 		if (y == 0) {
@@ -150,7 +150,7 @@ public class ScummVMEventsModern extends ScummVMEventsBase {
 		// extra filter to stop repetition in order to avoid cases when android does not send onGenericMotionEvent()
 		// for small x or y (while abs is still larger than range.getflat())
 		// In such case we would end up with a slow moving "mouse" cursor - so we need this extra filter
-		if (Math.abs(x * 100) < 20.0f && Math.abs(y * 100) < 20.0f) {
+		if (Math.abs(x) < 0.2f && Math.abs(y) < 0.2f) {
 			//Log.d(ScummVM.LOG_TAG, "JOYSTICK - pushEvent(): STOPPED: " + (int)(x * 100) + " y= " + (int)(y * 100));
 			removeMessages();
 			// do the move, then signal the joystick has returned to center pos




More information about the Scummvm-git-logs mailing list