Let's let Moga start actually handling Moga events, Fix Rjoy
This commit is contained in:
parent
326fcec485
commit
fa2b229c95
|
@ -272,11 +272,7 @@ public class GL2JNIActivity extends Activity {
|
||||||
if (playerNum == null || playerNum == -1)
|
if (playerNum == null || playerNum == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (pad.isActiveMoga[playerNum]) {
|
if (!pad.compat[playerNum] && !pad.isActiveMoga[playerNum]) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pad.compat[playerNum]) {
|
|
||||||
// TODO: Moga should handle this locally
|
// TODO: Moga should handle this locally
|
||||||
|
|
||||||
// Joystick
|
// Joystick
|
||||||
|
@ -303,14 +299,15 @@ public class GL2JNIActivity extends Activity {
|
||||||
|
|
||||||
if (prefs.getBoolean("right_buttons", true)) {
|
if (prefs.getBoolean("right_buttons", true)) {
|
||||||
if (RS_Y > 0.5) {
|
if (RS_Y > 0.5) {
|
||||||
handle_key(playerNum, pad.map[playerNum][0], true);
|
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
|
||||||
handle_key(playerNum, pad.map[playerNum][1], false);
|
pad.wasKeyStick[playerNum] = true;
|
||||||
} else if (RS_Y < 0.5) {
|
} else if (RS_Y < 0.5) {
|
||||||
handle_key(playerNum, pad.map[playerNum][0], false);
|
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
|
||||||
handle_key(playerNum, pad.map[playerNum][1], true);
|
pad.wasKeyStick[playerNum] = true;
|
||||||
} else {
|
} else if (pad.wasKeyStick[playerNum]){
|
||||||
handle_key(playerNum, pad.map[playerNum][0], false);
|
handle_key(playerNum, pad.map[playerNum][0], false);
|
||||||
handle_key(playerNum, pad.map[playerNum][1], false);
|
handle_key(playerNum, pad.map[playerNum][1], false);
|
||||||
|
pad.wasKeyStick[playerNum] = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (RS_Y > 0.5) {
|
if (RS_Y > 0.5) {
|
||||||
|
@ -320,9 +317,8 @@ public class GL2JNIActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mView.pushInput();
|
||||||
}
|
}
|
||||||
mView.pushInput();
|
|
||||||
if ((pad.globalLS_X[playerNum] == pad.previousLS_X[playerNum] && pad.globalLS_Y[playerNum] == pad.previousLS_Y[playerNum])
|
if ((pad.globalLS_X[playerNum] == pad.previousLS_X[playerNum] && pad.globalLS_Y[playerNum] == pad.previousLS_Y[playerNum])
|
||||||
|| (pad.previousLS_X[playerNum] == 0.0f && pad.previousLS_Y[playerNum] == 0.0f))
|
|| (pad.previousLS_X[playerNum] == 0.0f && pad.previousLS_Y[playerNum] == 0.0f))
|
||||||
// Only handle Left Stick on an Xbox 360 controller if there was
|
// Only handle Left Stick on an Xbox 360 controller if there was
|
||||||
|
@ -379,7 +375,7 @@ public class GL2JNIActivity extends Activity {
|
||||||
* };
|
* };
|
||||||
*/
|
*/
|
||||||
|
|
||||||
boolean handle_key(Integer playerNum, int kc, boolean down) {
|
public boolean handle_key(Integer playerNum, int kc, boolean down) {
|
||||||
if (playerNum == null || playerNum == -1)
|
if (playerNum == null || playerNum == -1)
|
||||||
return false;
|
return false;
|
||||||
if (pad.isActiveMoga[playerNum]) {
|
if (pad.isActiveMoga[playerNum]) {
|
||||||
|
@ -461,6 +457,10 @@ public class GL2JNIActivity extends Activity {
|
||||||
LayoutParams.WRAP_CONTENT);
|
LayoutParams.WRAP_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GL2JNIView getGameView() {
|
||||||
|
return mView;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getDeviceId());
|
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getDeviceId());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
|
||||||
|
@ -470,7 +470,7 @@ public class GL2JNIActivity extends Activity {
|
||||||
playerNum = -1;
|
playerNum = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerNum != null && playerNum != -1) {
|
if (playerNum != null && playerNum != -1 && !pad.isActiveMoga[playerNum]) {
|
||||||
if (pad.compat[playerNum] || pad.custom[playerNum]) {
|
if (pad.compat[playerNum] || pad.custom[playerNum]) {
|
||||||
String id = pad.portId[playerNum];
|
String id = pad.portId[playerNum];
|
||||||
if (keyCode == prefs.getInt("l_button" + id,
|
if (keyCode == prefs.getInt("l_button" + id,
|
||||||
|
@ -482,8 +482,15 @@ public class GL2JNIActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle_key(playerNum, keyCode, false)
|
if (!pad.isActiveMoga[playerNum]) {
|
||||||
|| super.onKeyUp(keyCode, event);
|
return handle_key(playerNum, keyCode, false)
|
||||||
|
|| super.onKeyUp(keyCode, event);
|
||||||
|
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
@ -495,7 +502,7 @@ public class GL2JNIActivity extends Activity {
|
||||||
playerNum = -1;
|
playerNum = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerNum != null && playerNum != -1) {
|
if (playerNum != null && playerNum != -1 && !pad.isActiveMoga[playerNum]) {
|
||||||
if (pad.compat[playerNum] || pad.custom[playerNum]) {
|
if (pad.compat[playerNum] || pad.custom[playerNum]) {
|
||||||
String id = pad.portId[playerNum];
|
String id = pad.portId[playerNum];
|
||||||
if (keyCode == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
|
if (keyCode == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
|
||||||
|
@ -507,10 +514,12 @@ public class GL2JNIActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle_key(playerNum, keyCode, true)) {
|
if (!pad.isActiveMoga[playerNum]) {
|
||||||
if (playerNum == 0)
|
if (handle_key(playerNum, keyCode, true)) {
|
||||||
JNIdc.hide_osd();
|
if (playerNum == 0)
|
||||||
return true;
|
JNIdc.hide_osd();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_BUTTON_SELECT) {
|
if (keyCode == KeyEvent.KEYCODE_BUTTON_SELECT) {
|
||||||
|
@ -530,7 +539,14 @@ public class GL2JNIActivity extends Activity {
|
||||||
return showMenu();
|
return showMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
if (!pad.isActiveMoga[playerNum]) {
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
|
||||||
|
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean showMenu() {
|
private boolean showMenu() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class Gamepad {
|
||||||
public int[] name = { -1, -1, -1, -1 };
|
public int[] name = { -1, -1, -1, -1 };
|
||||||
public float[] globalLS_X = new float[4], globalLS_Y = new float[4],
|
public float[] globalLS_X = new float[4], globalLS_Y = new float[4],
|
||||||
previousLS_X = new float[4], previousLS_Y = new float[4];
|
previousLS_X = new float[4], previousLS_Y = new float[4];
|
||||||
|
public boolean[] wasKeyStick = { false, false, false, false };
|
||||||
public int map[][] = new int[4][];
|
public int map[][] = new int[4][];
|
||||||
|
|
||||||
public SparseArray<String> deviceId_deviceDescriptor = new SparseArray<String>();
|
public SparseArray<String> deviceId_deviceDescriptor = new SparseArray<String>();
|
||||||
|
|
|
@ -3,13 +3,14 @@ package com.reicast.emulator.periph;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import tv.ouya.console.api.OuyaController;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.SparseArray;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.bda.controller.Controller;
|
import com.bda.controller.Controller;
|
||||||
|
@ -17,6 +18,7 @@ import com.bda.controller.ControllerListener;
|
||||||
import com.bda.controller.KeyEvent;
|
import com.bda.controller.KeyEvent;
|
||||||
import com.bda.controller.MotionEvent;
|
import com.bda.controller.MotionEvent;
|
||||||
import com.bda.controller.StateEvent;
|
import com.bda.controller.StateEvent;
|
||||||
|
import com.reicast.emulator.GL2JNIActivity;
|
||||||
import com.reicast.emulator.R;
|
import com.reicast.emulator.R;
|
||||||
import com.reicast.emulator.emu.GL2JNIView;
|
import com.reicast.emulator.emu.GL2JNIView;
|
||||||
import com.reicast.emulator.emu.JNIdc;
|
import com.reicast.emulator.emu.JNIdc;
|
||||||
|
@ -133,83 +135,100 @@ public class MOGAInput
|
||||||
{
|
{
|
||||||
public void onKeyEvent(KeyEvent event)
|
public void onKeyEvent(KeyEvent event)
|
||||||
{
|
{
|
||||||
Integer playerNum = pad.deviceDescriptor_PlayerNum.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
|
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getControllerId());
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
|
||||||
if (playerNum == null)
|
playerNum = pad.deviceDescriptor_PlayerNum
|
||||||
|
.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
|
||||||
|
} else {
|
||||||
|
playerNum = -1;
|
||||||
|
}
|
||||||
|
if (playerNum == null || playerNum == -1)
|
||||||
return;
|
return;
|
||||||
|
if (playerNum != null && playerNum != -1) {
|
||||||
String id = pad.portId[playerNum];
|
String id = pad.portId[playerNum];
|
||||||
if (pad.custom[playerNum]) {
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
if (event.getKeyCode() == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
|
if (event.getKeyCode() == prefs.getInt("l_button" + id, KeyEvent.KEYCODE_BUTTON_L1)) {
|
||||||
simulatedTouchEvent(playerNum, 1.0f, 0.0f);
|
simulatedTouchEvent(playerNum, 1.0f, 0.0f);
|
||||||
simulatedTouchEvent(playerNum, 0.0f, 0.0f);
|
} else if (event.getKeyCode() == prefs.getInt("r_button" + id, KeyEvent.KEYCODE_BUTTON_R1)) {
|
||||||
}
|
|
||||||
if (event.getKeyCode() == prefs.getInt("r_button" + id, KeyEvent.KEYCODE_BUTTON_R1)) {
|
|
||||||
simulatedTouchEvent(playerNum, 0.0f, 1.0f);
|
simulatedTouchEvent(playerNum, 0.0f, 1.0f);
|
||||||
simulatedTouchEvent(playerNum, 0.0f, 0.0f);
|
} else if (((GL2JNIActivity) act).handle_key(playerNum, event.getKeyCode(), true)) {
|
||||||
|
if (playerNum == 0)
|
||||||
|
JNIdc.hide_osd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
if (event.getKeyCode() == prefs.getInt("l_button" + id,
|
||||||
|
KeyEvent.KEYCODE_BUTTON_L1)
|
||||||
|
|| event.getKeyCode() == prefs.getInt("r_button" + id,
|
||||||
|
KeyEvent.KEYCODE_BUTTON_R1)) {
|
||||||
|
simulatedTouchEvent(playerNum, 0.0f, 0.0f);
|
||||||
|
} else {
|
||||||
|
((GL2JNIActivity) act).handle_key(playerNum, event.getKeyCode(), false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(playerNum == 0)
|
|
||||||
JNIdc.hide_osd();
|
|
||||||
|
|
||||||
for (int i = 0; i < pad.map.length; i += 2) {
|
|
||||||
if (pad.map[playerNum][i + 0] == event.getKeyCode()) {
|
|
||||||
if (event.getAction() == 0) //FIXME to const
|
|
||||||
GL2JNIView.kcode_raw[playerNum] &= ~pad.map[playerNum][i + 1];
|
|
||||||
else
|
|
||||||
GL2JNIView.kcode_raw[playerNum] |= pad.map[playerNum][i + 1];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void simulatedTouchEvent(int playerNum, float L2, float R2) {
|
|
||||||
if(playerNum == 0)
|
|
||||||
JNIdc.hide_osd();
|
|
||||||
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
|
|
||||||
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
|
|
||||||
pad.globalLS_X[playerNum] = 0;
|
|
||||||
pad.globalLS_Y[playerNum] = 0;
|
|
||||||
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
|
||||||
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
|
||||||
GL2JNIView.jx[playerNum] = (int) (0 * 126);
|
|
||||||
GL2JNIView.jy[playerNum] = (int) (0 * 126);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onMotionEvent(MotionEvent event)
|
public void onMotionEvent(MotionEvent event)
|
||||||
{
|
{
|
||||||
Integer playerNum = pad.deviceDescriptor_PlayerNum.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
|
Integer playerNum = Arrays.asList(pad.name).indexOf(event.getControllerId());
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && playerNum == -1) {
|
||||||
if (playerNum == null)
|
playerNum = pad.deviceDescriptor_PlayerNum
|
||||||
|
.get(pad.deviceId_deviceDescriptor.get(event.getControllerId()));
|
||||||
|
} else {
|
||||||
|
playerNum = -1;
|
||||||
|
}
|
||||||
|
if (playerNum == null || playerNum == -1)
|
||||||
return;
|
return;
|
||||||
|
if (!pad.compat[playerNum]) {
|
||||||
|
// Joystick
|
||||||
|
// do other things with joystick
|
||||||
|
float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
|
||||||
|
float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||||
|
float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
|
||||||
|
float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||||
|
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
|
||||||
|
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
|
||||||
|
|
||||||
if(playerNum == 0)
|
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
|
||||||
JNIdc.hide_osd();
|
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
|
||||||
|
pad.globalLS_X[playerNum] = LS_X;
|
||||||
|
pad.globalLS_Y[playerNum] = LS_Y;
|
||||||
|
|
||||||
float S_X = event.getAxisValue(MotionEvent.AXIS_X);
|
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
||||||
float S_Y = event.getAxisValue(MotionEvent.AXIS_Y);
|
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
||||||
float L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
|
||||||
float R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
|
||||||
|
|
||||||
pad.previousLS_X[playerNum] = pad.globalLS_X[playerNum];
|
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
|
||||||
pad.previousLS_Y[playerNum] = pad.globalLS_Y[playerNum];
|
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
|
||||||
pad.globalLS_X[playerNum] = S_X;
|
|
||||||
pad.globalLS_Y[playerNum] = S_Y;
|
|
||||||
|
|
||||||
|
if (prefs.getBoolean("right_buttons", true)) {
|
||||||
|
if (RS_Y > 0.5) {
|
||||||
|
((GL2JNIActivity) act).handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
|
||||||
|
pad.wasKeyStick[playerNum] = true;
|
||||||
|
} else if (RS_Y < 0.5) {
|
||||||
|
((GL2JNIActivity) act).handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
|
||||||
|
pad.wasKeyStick[playerNum] = true;
|
||||||
|
} else if (pad.wasKeyStick[playerNum]){
|
||||||
|
((GL2JNIActivity) act).handle_key(playerNum, pad.map[playerNum][0], false);
|
||||||
|
((GL2JNIActivity) act).handle_key(playerNum, pad.map[playerNum][1], false);
|
||||||
|
pad.wasKeyStick[playerNum] = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (RS_Y > 0.5) {
|
||||||
|
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
|
||||||
|
} else if (RS_Y < 0.5) {
|
||||||
|
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
((GL2JNIActivity) act).getGameView().pushInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean simulatedTouchEvent(int playerNum, float L2, float R2) {
|
||||||
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
||||||
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
||||||
|
((GL2JNIActivity) act).getGameView().pushInput();
|
||||||
GL2JNIView.jx[playerNum] = (int) (S_X * 126);
|
return true;
|
||||||
GL2JNIView.jy[playerNum] = (int) (S_Y * 126);
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(final Entry<Integer, ExampleFloat> entry : mMotions.entrySet())
|
|
||||||
{
|
|
||||||
final int key = entry.getKey();
|
|
||||||
final ExampleFloat value = entry.getValue();
|
|
||||||
value.mValue = event.getAxisValue(key);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStateEvent(StateEvent event)
|
public void onStateEvent(StateEvent event)
|
||||||
|
|
Loading…
Reference in New Issue