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(_axisPosX, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX); + e.joystick.position = CLIP(arg2, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX); pushEvent(e); e.joystick.axis = Common::JOYSTICK_AXIS_LEFT_STICK_Y; - e.joystick.position = CLIP(_axisPosY, Common::JOYAXIS_MIN, Common::JOYAXIS_MAX); + e.joystick.position = CLIP(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