From b0ef1a4468ca7433f0c39ef91642c38bc200a21d Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Sun, 5 Jan 2014 15:06:31 +0100 Subject: [PATCH] Added multi-controller support into MOGA implementation (Untested! Somebody with MOGA hardware should verify that I didn't break anything!) Fixed OSD hiding for multiple controllers (OSD is now hidden only in case Player 1 is using a physical controller) Fixed PS3 controller mapping (regression?) --- .../com/reicast/emulator/GL2JNIActivity.java | 18 ++++----- .../src/com/reicast/emulator/MOGAInput.java | 37 ++++++++++++++----- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/GL2JNIActivity.java b/shell/android/src/com/reicast/emulator/GL2JNIActivity.java index 400611a30..b3364618c 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNIActivity.java +++ b/shell/android/src/com/reicast/emulator/GL2JNIActivity.java @@ -42,8 +42,8 @@ public class GL2JNIActivity extends Activity { static boolean[] xbox = { false, false, false, false }, nVidia = { false, false, false, false }; float[] globalLS_X = new float[4], globalLS_Y = new float[4], previousLS_X = new float[4], previousLS_Y = new float[4]; - HashMap deviceId_deviceDescriptor = new HashMap(); - HashMap deviceDescriptor_PlayerNum = new HashMap(); + public static HashMap deviceId_deviceDescriptor = new HashMap(); + public static HashMap deviceDescriptor_PlayerNum = new HashMap(); int map[][]; @@ -197,10 +197,10 @@ public class GL2JNIActivity extends Activity { if (InputDevice.getDevice(joys[i]).getName() .equals("Sony PLAYSTATION(R)3 Controller")) { map[playerNum] = new int[] { - OuyaController.BUTTON_Y, key_CONT_B, - OuyaController.BUTTON_U, key_CONT_A, - OuyaController.BUTTON_O, key_CONT_X, - OuyaController.BUTTON_A, key_CONT_Y, + OuyaController.BUTTON_Y, key_CONT_Y, + OuyaController.BUTTON_U, key_CONT_X, + OuyaController.BUTTON_O, key_CONT_A, + OuyaController.BUTTON_A, key_CONT_B, OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP, OuyaController.BUTTON_DPAD_DOWN, @@ -300,10 +300,6 @@ public class GL2JNIActivity extends Activity { if (playerNum == null) return false; - if (nVidia[playerNum]) { - JNIdc.hide_osd(); - } - if (!moga.isActive) { // Joystick @@ -422,7 +418,7 @@ public class GL2JNIActivity extends Activity { Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId())); if (handle_key(playerNum, keyCode, true)) { - if(playerNum == 1) + if(playerNum == 0) JNIdc.hide_osd(); return true; } diff --git a/shell/android/src/com/reicast/emulator/MOGAInput.java b/shell/android/src/com/reicast/emulator/MOGAInput.java index bf61a55e4..9cf5d0de3 100644 --- a/shell/android/src/com/reicast/emulator/MOGAInput.java +++ b/shell/android/src/com/reicast/emulator/MOGAInput.java @@ -141,13 +141,20 @@ public class MOGAInput { public void onKeyEvent(KeyEvent event) { - JNIdc.hide_osd(); + Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId())); + + if (playerNum == null) + return; + + if(playerNum == 0) + JNIdc.hide_osd(); + for (int i = 0; i < map.length; i += 2) { if (map[i + 0] == event.getKeyCode()) { if (event.getAction() == 0) //FIXME to const - GL2JNIView.kcode_raw[0] &= ~map[i + 1]; + GL2JNIView.kcode_raw[playerNum] &= ~map[i + 1]; else - GL2JNIView.kcode_raw[0] |= map[i + 1]; + GL2JNIView.kcode_raw[playerNum] |= map[i + 1]; break; } @@ -156,18 +163,24 @@ public class MOGAInput public void onMotionEvent(MotionEvent event) { - JNIdc.hide_osd(); + Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId())); + + if (playerNum == null) + return; + + if(playerNum == 0) + JNIdc.hide_osd(); float LS_X = event.getAxisValue(MotionEvent.AXIS_X); float LS_Y = event.getAxisValue(MotionEvent.AXIS_Y); float L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER); float R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER); - GL2JNIView.lt[0] = (int) (L2 * 255); - GL2JNIView.rt[0] = (int) (R2 * 255); + GL2JNIView.lt[playerNum] = (int) (L2 * 255); + GL2JNIView.rt[playerNum] = (int) (R2 * 255); - GL2JNIView.jx[0] = (int) (LS_X * 126); - GL2JNIView.jy[0] = (int) (LS_Y * 126); + GL2JNIView.jx[playerNum] = (int) (LS_X * 126); + GL2JNIView.jy[playerNum] = (int) (LS_Y * 126); /* for(final Entry entry : mMotions.entrySet()) @@ -180,7 +193,13 @@ public class MOGAInput public void onStateEvent(StateEvent event) { - JNIdc.hide_osd(); + Integer playerNum = GL2JNIActivity.deviceDescriptor_PlayerNum.get(GL2JNIActivity.deviceId_deviceDescriptor.get(event.getControllerId())); + + if (playerNum == null) + return; + + if(playerNum == 0) + JNIdc.hide_osd(); if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == ACTION_CONNECTED) { Toast.makeText(act.getApplicationContext(), "MOGA Connected!", Toast.LENGTH_SHORT).show();