Android input: Filter axis messages for duplicates. Assorted fixes and cleanup.
This commit is contained in:
parent
fc3f7da3af
commit
de96926d2e
3 changed files with 15 additions and 11 deletions
|
@ -1169,20 +1169,19 @@ PermissionStatus System_GetPermissionStatus(SystemPermission permission) {
|
||||||
|
|
||||||
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_touch
|
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_touch
|
||||||
(JNIEnv *, jclass, float x, float y, int code, int pointerId) {
|
(JNIEnv *, jclass, float x, float y, int code, int pointerId) {
|
||||||
|
if (!renderer_inited)
|
||||||
float scaledX = x * g_display.dpi_scale_x;
|
return;
|
||||||
float scaledY = y * g_display.dpi_scale_y;
|
|
||||||
|
|
||||||
TouchInput touch;
|
TouchInput touch;
|
||||||
touch.id = pointerId;
|
touch.id = pointerId;
|
||||||
touch.x = scaledX;
|
touch.x = x * g_display.dpi_scale_x;
|
||||||
touch.y = scaledY;
|
touch.y = y * g_display.dpi_scale_y;
|
||||||
touch.flags = code;
|
touch.flags = code;
|
||||||
|
|
||||||
NativeTouch(touch);
|
NativeTouch(touch);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyDown(JNIEnv *, jclass, jint deviceId, jint key, jboolean isRepeat) {
|
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyDown(JNIEnv *, jclass, jint deviceId, jint key, jboolean isRepeat) {
|
||||||
|
if (!renderer_inited)
|
||||||
|
return false;
|
||||||
KeyInput keyInput;
|
KeyInput keyInput;
|
||||||
keyInput.deviceId = (InputDeviceID)deviceId;
|
keyInput.deviceId = (InputDeviceID)deviceId;
|
||||||
keyInput.keyCode = (InputKeyCode)key;
|
keyInput.keyCode = (InputKeyCode)key;
|
||||||
|
@ -1194,6 +1193,8 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyDown(JNIEnv *, jclass, j
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyUp(JNIEnv *, jclass, jint deviceId, jint key) {
|
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyUp(JNIEnv *, jclass, jint deviceId, jint key) {
|
||||||
|
if (!renderer_inited)
|
||||||
|
return false;
|
||||||
KeyInput keyInput;
|
KeyInput keyInput;
|
||||||
keyInput.deviceId = (InputDeviceID)deviceId;
|
keyInput.deviceId = (InputDeviceID)deviceId;
|
||||||
keyInput.keyCode = (InputKeyCode)key;
|
keyInput.keyCode = (InputKeyCode)key;
|
||||||
|
@ -1210,7 +1211,6 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_joystickAxis(
|
||||||
axis.deviceId = (InputDeviceID)deviceId;
|
axis.deviceId = (InputDeviceID)deviceId;
|
||||||
axis.axisId = (InputAxis)axisId;
|
axis.axisId = (InputAxis)axisId;
|
||||||
axis.value = value;
|
axis.value = value;
|
||||||
|
|
||||||
NativeAxis(axis);
|
NativeAxis(axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1218,7 +1218,6 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent(
|
||||||
JNIEnv *env, jclass, jint stick, jfloat x, jfloat y) {
|
JNIEnv *env, jclass, jint stick, jfloat x, jfloat y) {
|
||||||
if (!renderer_inited)
|
if (!renderer_inited)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: Support mousewheel for android
|
// TODO: Support mousewheel for android
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public class InputDeviceState {
|
||||||
|
|
||||||
private InputDevice mDevice;
|
private InputDevice mDevice;
|
||||||
private int[] mAxes;
|
private int[] mAxes;
|
||||||
|
private float[] mAxisPrevValue;
|
||||||
|
|
||||||
private int sources;
|
private int sources;
|
||||||
|
|
||||||
|
@ -118,6 +119,7 @@ public class InputDeviceState {
|
||||||
}
|
}
|
||||||
|
|
||||||
mAxes = new int[numAxes];
|
mAxes = new int[numAxes];
|
||||||
|
mAxisPrevValue = new float[numAxes];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (MotionRange range : device.getMotionRanges()) {
|
for (MotionRange range : device.getMotionRanges()) {
|
||||||
|
@ -150,7 +152,10 @@ public class InputDeviceState {
|
||||||
for (int i = 0; i < mAxes.length; i++) {
|
for (int i = 0; i < mAxes.length; i++) {
|
||||||
int axisId = mAxes[i];
|
int axisId = mAxes[i];
|
||||||
float value = event.getAxisValue(axisId);
|
float value = event.getAxisValue(axisId);
|
||||||
|
if (value != mAxisPrevValue[i]) {
|
||||||
NativeApp.joystickAxis(deviceId, axisId, value);
|
NativeApp.joystickAxis(deviceId, axisId, value);
|
||||||
|
mAxisPrevValue[i] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1083,7 +1083,7 @@ public abstract class NativeActivity extends Activity {
|
||||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||||
// Joysticks are supported in Honeycomb MR1 and later via the onGenericMotionEvent method.
|
// Joysticks are supported in Honeycomb MR1 and later via the onGenericMotionEvent method.
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && event.getSource() == InputDevice.SOURCE_JOYSTICK) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && (event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
|
||||||
// Pass through / ignore
|
// Pass through / ignore
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue