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?)
This commit is contained in:
Matteo Hausner 2014-01-05 15:06:31 +01:00 committed by LoungeKatt
parent 3cb8b2cc6e
commit b0ef1a4468
2 changed files with 35 additions and 20 deletions

View File

@ -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<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
public static HashMap<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
public static HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
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;
}

View File

@ -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<Integer, ExampleFloat> 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();