Merge pull request #77 from NoblesseOblige/master

bwRavencl's Multi controller (Clean merge)
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2014-01-05 18:25:25 -08:00
commit 8c61d40afd
11 changed files with 655 additions and 73 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.DS_Store
*.class
*.orig
bin/
gen/

View File

@ -78,7 +78,7 @@ void mcfg_CreateDevices()
void mcfg_DestroyDevices()
{
for (int i=0;i<3;i++)
for (int j=0;j<5;j++)
for (int i=0;i<=3;i++)
for (int j=0;j<=5;j++)
delete MapleDevices[i][j];
}
}

View File

@ -13,6 +13,7 @@
#include "profiler/profiler.h"
#include "cfg/cfg.h"
#include "rend/TexCache.h"
#include "hw/maple/maple_devs.h"
#include "util.h"
@ -29,9 +30,11 @@ extern "C"
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_rendinit(JNIEnv *env,jobject obj,jint w,jint h) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_rendframe(JNIEnv *env,jobject obj) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_kcode(JNIEnv * env, jobject obj,u32 k_code, u32 l_t, u32 r_t, u32 jx, u32 jy) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy) __attribute__((visibility("default")));
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_vjoy(JNIEnv * env, jobject obj,u32 id,float x, float y, float w, float h) __attribute__((visibility("default")));
//JNIEXPORT jint JNICALL Java_com_reicast_emulator_JNIdc_play(JNIEnv *env,jobject obj,jshortArray result,jint size);
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers) __attribute__((visibility("default")));
};
void egl_stealcntx();
@ -39,6 +42,7 @@ void SetApplicationPath(wchar *path);
int dc_init(int argc,wchar* argv[]);
void dc_run();
void dc_term();
void mcfg_Create(MapleDeviceType type,u32 bus,u32 port);
bool VramLockedWrite(u8* address);
@ -51,6 +55,9 @@ extern int screen_width,screen_height;
static u64 tvs_base;
static char CurFileName[256];
// Additonal controllers 2, 3 and 4 connected ?
static bool add_controllers[3] = { false, true, false };
u16 kcode[4];
u32 vks[4];
s8 joyx[4],joyy[4];
@ -84,6 +91,13 @@ static void *ThreadHandler(void *UserData)
strcat(Args[2],P);
}
// Add additonal controllers
for (int i = 0; i < 3; i++)
{
if (add_controllers[i])
mcfg_Create(MDT_SegaController,i+1,5);
}
// Run nullDC emulator
dc_init(Args[2]? 3:1,Args);
}
@ -247,14 +261,28 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_rendframe(JNIEnv *env,job
while(!rend_single_frame()) ;
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_kcode(JNIEnv * env, jobject obj,u32 k_code, u32 l_t, u32 r_t, u32 jx, u32 jy)
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy)
{
lt[0] = l_t;
rt[0] = r_t;
kcode[0] = k_code;
kcode[3] = kcode[2] = kcode[1] = 0xFFFF;
joyx[0]=jx;
joyy[0]=jy;
jint *k_code_body = env->GetIntArrayElements(k_code, 0);
jint *l_t_body = env->GetIntArrayElements(l_t, 0);
jint *r_t_body = env->GetIntArrayElements(r_t, 0);
jint *jx_body = env->GetIntArrayElements(jx, 0);
jint *jy_body = env->GetIntArrayElements(jy, 0);
for(int i = 0; i < 4; i++)
{
kcode[i] = k_code_body[i];
lt[i] = l_t_body[i];
rt[i] = r_t_body[i];
joyx[i] = jx_body[i];
joyy[i] = jy_body[i];
}
env->ReleaseIntArrayElements(k_code, k_code_body, 0);
env->ReleaseIntArrayElements(l_t, l_t_body, 0);
env->ReleaseIntArrayElements(r_t, r_t_body, 0);
env->ReleaseIntArrayElements(jx, jx_body, 0);
env->ReleaseIntArrayElements(jy, jy_body, 0);
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_rendinit(JNIEnv * env, jobject obj, jint w,jint h)
@ -283,6 +311,13 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_vjoy(JNIEnv * env, jobjec
}
}
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_initControllers(JNIEnv *env, jobject obj, jbooleanArray controllers)
{
jboolean *controllers_body = env->GetBooleanArrayElements(controllers, 0);
memcpy(add_controllers, controllers_body, 3);
env->ReleaseBooleanArrayElements(controllers, controllers_body, 0);
}
u32 os_Push(void* frame, u32 amt, bool wait)
{
verify(amt==SAMPLE_COUNT);
@ -294,4 +329,4 @@ u32 os_Push(void* frame, u32 amt, bool wait)
bool os_IsAudioBuffered()
{
return jenv->CallIntMethod(track,writemid,jsamples,-1)==0;
}
}

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_1" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_2" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_3" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_4" />
<TextView
android:layout_weight="1"
android:id="@+id/textViewDeviceDescriptorPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/controller_none" />
<Button
android:layout_weight="1"
android:id="@+id/buttonSelectControllerPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_controller" />
<Button
android:layout_weight="1"
android:id="@+id/buttonRemoveControllerPlayer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/remove_controller" />
</LinearLayout>
</LinearLayout>

View File

@ -19,6 +19,17 @@
<string name="select_render">PVR Rendering (does nothing for now)</string>
<string name="games_listing">Available Dreamcast Games</string>
<string name="controller_1">Controller 1</string>
<string name="controller_2">Controller 2</string>
<string name="controller_3">Controller 3</string>
<string name="controller_4">Controller 4</string>
<string name="controller_none">None</string>
<string name="select_controller">Select Controller</string>
<string name="remove_controller">Remove Controller</string>
<string name="select_controller_title">Select Controller</string>
<string name="select_controller_message">Press any button on the controller to assign to port</string>
<string name="controller_already_in_use">This controller is already in use!</string>
<string-array name="images">
<item>cdi</item>
@ -41,6 +52,7 @@
<item>Browser</item>
<item>Settings</item>
<item>Paths</item>
<item>Controllers</item>
<item>About</item>
</string-array>
@ -50,10 +62,11 @@
<item>@drawable/disk_unknown</item>
<item>@drawable/config</item>
<item>@drawable/open_folder</item>
<item>@drawable/config</item>
<item>@drawable/question</item>
</array>
<!-- Content Description -->
<string name="desc_list_item_icon">Item Icon</string>
</resources>
</resources>

View File

@ -0,0 +1,268 @@
package com.reicast.emulator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class ControllersFragment extends Fragment {
private Activity parentActivity;
private int listenForButton = 0;
private AlertDialog alertDialogSelectController;
private SharedPreferences mPrefs;
// Container Activity must implement this interface
public interface OnClickListener {
public void onMainBrowseSelected(String path_entry, boolean games);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.controllers_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
Button buttonSelectControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonSelectControllerPlayer1);
buttonSelectControllerPlayer1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
selectController(1);
}
});
Button buttonSelectControllerPlayer2 = (Button) getView()
.findViewById(R.id.buttonSelectControllerPlayer2);
buttonSelectControllerPlayer2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
selectController(2);
}
});
Button buttonSelectControllerPlayer3 = (Button) getView()
.findViewById(R.id.buttonSelectControllerPlayer3);
buttonSelectControllerPlayer3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
selectController(3);
}
});
Button buttonSelectControllerPlayer4 = (Button) getView()
.findViewById(R.id.buttonSelectControllerPlayer4);
buttonSelectControllerPlayer4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
selectController(4);
}
});
Button buttonRemoveControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer1);
buttonRemoveControllerPlayer1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeController(1);
}
});
Button buttonRemoveControllerPlayer2 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer2);
buttonRemoveControllerPlayer2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeController(2);
}
});
Button buttonRemoveControllerPlayer3 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer3);
buttonRemoveControllerPlayer3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeController(3);
}
});
Button buttonRemoveControllerPlayer4 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer4);
buttonRemoveControllerPlayer4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeController(4);
}
});
updateControllers();
}
private void updateControllers() {
String deviceDescriptorPlayer1 = mPrefs.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = mPrefs.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = mPrefs.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = mPrefs.getString("device_descriptor_player_4", null);
String labelPlayer1 = null, labelPlayer2 = null, labelPlayer3 = null, labelPlayer4 = null;
for (int devideId : InputDevice.getDeviceIds()) {
InputDevice dev = InputDevice.getDevice(devideId);
String descriptor = dev.getDescriptor();
if (descriptor != null) {
if (descriptor.equals(deviceDescriptorPlayer1))
labelPlayer1 = dev.getName() + " (" + descriptor + ")";
else if (descriptor.equals(deviceDescriptorPlayer2))
labelPlayer2 = dev.getName() + " (" + descriptor + ")";
else if (descriptor.equals(deviceDescriptorPlayer3))
labelPlayer3 = dev.getName() + " (" + descriptor + ")";
else if (descriptor.equals(deviceDescriptorPlayer4))
labelPlayer4 = dev.getName() + " (" + descriptor + ")";
}
}
TextView textViewDeviceDescriptorPlayer1 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer1);
Button buttonRemoveControllerPlayer1 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer1);
if (deviceDescriptorPlayer1 != null) {
textViewDeviceDescriptorPlayer1.setText(labelPlayer1);
buttonRemoveControllerPlayer1.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer1.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer1.setEnabled(false);
}
TextView textViewDeviceDescriptorPlayer2 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer2);
Button buttonRemoveControllerPlayer2 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer2);
if (deviceDescriptorPlayer2 != null) {
textViewDeviceDescriptorPlayer2.setText(labelPlayer2);
buttonRemoveControllerPlayer2.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer2.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer2.setEnabled(false);
}
TextView textViewDeviceDescriptorPlayer3 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer3);
Button buttonRemoveControllerPlayer3 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer3);
if (deviceDescriptorPlayer3 != null) {
textViewDeviceDescriptorPlayer3.setText(labelPlayer3);
buttonRemoveControllerPlayer3.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer3.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer3.setEnabled(false);
}
TextView textViewDeviceDescriptorPlayer4 = (TextView) getView()
.findViewById(R.id.textViewDeviceDescriptorPlayer4);
Button buttonRemoveControllerPlayer4 = (Button) getView()
.findViewById(R.id.buttonRemoveControllerPlayer4);
if (deviceDescriptorPlayer4 != null) {
textViewDeviceDescriptorPlayer4.setText(labelPlayer4);
buttonRemoveControllerPlayer4.setEnabled(true);
} else {
textViewDeviceDescriptorPlayer4.setText(getString(R.string.controller_none));
buttonRemoveControllerPlayer4.setEnabled(false);
}
}
private void selectController(int playerNum) {
listenForButton = playerNum;
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(getString(R.string.select_controller_title));
builder.setMessage(getString(R.string.select_controller_message) + " " + String.valueOf(listenForButton) + ".");
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
listenForButton = 0;
dialog.dismiss();
}
});
builder.setOnKeyListener(new Dialog.OnKeyListener() {
//@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
mapDevice(event);
return true;
}
});
alertDialogSelectController = builder.create();
alertDialogSelectController.show();
}
private void mapDevice(KeyEvent event) {
String descriptor = InputDevice.getDevice(event.getDeviceId()).getDescriptor();
if (descriptor == null)
return;
String deviceDescriptorPlayer1 = mPrefs.getString("device_descriptor_player_1", null);
String deviceDescriptorPlayer2 = mPrefs.getString("device_descriptor_player_2", null);
String deviceDescriptorPlayer3 = mPrefs.getString("device_descriptor_player_3", null);
String deviceDescriptorPlayer4 = mPrefs.getString("device_descriptor_player_4", null);
if (descriptor.equals(deviceDescriptorPlayer1) || descriptor.equals(deviceDescriptorPlayer2) ||
descriptor.equals(deviceDescriptorPlayer3) || descriptor.equals(deviceDescriptorPlayer4)) {
Toast.makeText(parentActivity, getString(R.string.controller_already_in_use), Toast.LENGTH_SHORT).show();
return;
}
switch(listenForButton) {
case 0:
return;
case 1:
mPrefs.edit().putString("device_descriptor_player_1", descriptor).commit();
break;
case 2:
mPrefs.edit().putString("device_descriptor_player_2", descriptor).commit();
break;
case 3:
mPrefs.edit().putString("device_descriptor_player_3", descriptor).commit();
break;
case 4:
mPrefs.edit().putString("device_descriptor_player_4", descriptor).commit();
break;
}
Log.d("New controller for port " + String.valueOf(listenForButton) + ":", descriptor);
listenForButton = 0;
alertDialogSelectController.cancel();
updateControllers();
}
private void removeController(int playerNum) {
switch(playerNum) {
case 1:
mPrefs.edit().putString("device_descriptor_player_1", null).commit();
break;
case 2:
mPrefs.edit().putString("device_descriptor_player_2", null).commit();
break;
case 3:
mPrefs.edit().putString("device_descriptor_player_3", null).commit();
break;
case 4:
mPrefs.edit().putString("device_descriptor_player_4", null).commit();
break;
}
updateControllers();
}
}

View File

@ -1,6 +1,15 @@
package com.reicast.emulator;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import tv.ouya.console.api.OuyaController;
import com.reicast.emulator.GL2JNIView.EmuThread;
import android.content.SharedPreferences;
import android.view.InputDevice;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
@ -8,6 +17,7 @@ import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Gravity;
import android.view.InputDevice;
@ -29,10 +39,13 @@ public class GL2JNIActivity extends Activity {
PopupWindow popUp;
LayoutParams params;
MOGAInput moga = new MOGAInput();
static boolean xbox = false, nVidia = false;
float globalLS_X, globalLS_Y, previousLS_X, previousLS_Y;
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];
int map[];
public static HashMap<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
public static HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
int map[][];
View addbut(int x, OnClickListener ocl) {
ImageButton but = new ImageButton(this);
@ -129,24 +142,73 @@ public class GL2JNIActivity extends Activity {
// Call parent onCreate()
super.onCreate(icicle);
OuyaController.init(this);
map = new int[4][];
// Populate device descriptor-to-player-map from preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_1", null), 0);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_2", null), 1);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_3", null), 2);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_4", null), 3);
boolean controllerTwoConnected = false;
boolean controllerThreeConnected = false;
boolean controllerFourConnected = false;
for (HashMap.Entry<String, Integer> e : deviceDescriptor_PlayerNum.entrySet()) {
String descriptor = e.getKey();
Integer playerNum = e.getValue();
switch (playerNum) {
case 1:
if (descriptor != null)
controllerTwoConnected = true;
break;
case 2:
if (descriptor != null)
controllerThreeConnected = true;
break;
case 3:
if (descriptor != null)
controllerFourConnected = true;
break;
}
}
JNIdc.initControllers(new boolean[] {controllerTwoConnected, controllerThreeConnected, controllerFourConnected});
int joys[] = InputDevice.getDeviceIds();
for (int i = 0; i < joys.length; i++) {
String descriptor = InputDevice.getDevice(joys[i]).getDescriptor();
Log.d("reidc", "InputDevice ID: " + joys[i]);
Log.d("reidc", "InputDevice Name: "
+ InputDevice.getDevice(joys[i]).getName());
Log.d("reidc", "InputDevice Descriptor: " + descriptor);
deviceId_deviceDescriptor.put(joys[i], descriptor);
}
for (int i = 0; i < joys.length; i++) {
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(joys[i]));
if (playerNum != null) {
if (InputDevice.getDevice(joys[i]).getName()
.equals("Sony PLAYSTATION(R)3 Controller")) {
map = 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,
map[playerNum] = new int[] {
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, key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN,
key_CONT_DPAD_DOWN,
OuyaController.BUTTON_DPAD_LEFT,
key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT,
key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START
@ -154,7 +216,7 @@ public class GL2JNIActivity extends Activity {
};
} else if (InputDevice.getDevice(joys[i]).getName()
.equals("Microsoft X-Box 360 pad")) {
map = new int[] {
map[playerNum] = new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_Y, key_CONT_Y,
@ -170,10 +232,14 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START };
xbox = true;
xbox[playerNum] = true;
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
} else if (InputDevice.getDevice(joys[i]).getName()
.contains("NVIDIA Corporation NVIDIA Controller")) {
map = new int[] {
map[playerNum] = new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_Y, key_CONT_Y,
@ -189,9 +255,9 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START };
nVidia = true;
nVidia[playerNum] = true;
} else if (!moga.isActive) { // Ouya controller
map = new int[] {
map[playerNum] = new int[] {
OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_Y, key_CONT_Y,
@ -208,6 +274,7 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START };
}
}
}
// When viewing a resource, pass its URI to the native code for opening
@ -228,9 +295,10 @@ public class GL2JNIActivity extends Activity {
// Log.w("INPUT", event.toString() + " " + event.getSource());
// Get all the axis for the KeyEvent
if (nVidia) {
JNIdc.hide_osd();
}
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
if (playerNum == null)
return false;
if (!moga.isActive) {
@ -245,23 +313,24 @@ public class GL2JNIActivity extends Activity {
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
if (xbox || nVidia) {
previousLS_X = globalLS_X;
previousLS_Y = globalLS_Y;
globalLS_X = LS_X;
globalLS_Y = LS_Y;
if (xbox[playerNum] || nVidia[playerNum]) {
previousLS_X[playerNum] = globalLS_X[playerNum];
previousLS_Y[playerNum] = globalLS_Y[playerNum];
globalLS_X[playerNum] = LS_X;
globalLS_Y[playerNum] = LS_Y;
}
GL2JNIView.lt = (int) (L2 * 255);
GL2JNIView.rt = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.jx = (int) (LS_X * 126);
GL2JNIView.jy = (int) (LS_Y * 126);
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
}
}
if ((xbox || nVidia) && globalLS_X == previousLS_X && globalLS_Y == previousLS_Y)
if ((xbox[playerNum] || nVidia[playerNum]) && ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum])
|| (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f)))
// Only handle Left Stick on an Xbox 360 controller if there was some actual motion on the stick,
// so otherwise the event can be handled as a DPAD event
return false;
@ -313,16 +382,19 @@ public class GL2JNIActivity extends Activity {
* };
*/
boolean handle_key(int kc, boolean down) {
boolean handle_key(Integer playerNum, int kc, boolean down) {
if (playerNum == null)
return false;
if (!moga.isActive) {
boolean rav = false;
for (int i = 0; i < map.length; i += 2) {
if (map[i + 0] == kc) {
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw &= ~map[i + 1];
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
else
GL2JNIView.kcode_raw |= map[i + 1];
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
rav = true;
break;
@ -337,12 +409,17 @@ public class GL2JNIActivity extends Activity {
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
return handle_key(keyCode, false) || super.onKeyUp(keyCode, event);
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
return handle_key(playerNum, keyCode, false) || super.onKeyUp(keyCode, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (handle_key(keyCode, true)) {
JNIdc.hide_osd();
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
if (handle_key(playerNum, keyCode, true)) {
if(playerNum == 0)
JNIdc.hide_osd();
return true;
}

View File

@ -120,7 +120,9 @@ class GL2JNIView extends GLSurfaceView
JNIdc.data(1, GL2JNIActivity.syms);
JNIdc.hide_osd();
JNIdc.kcode(0xFFFF,0,0,128,128);
int[] kcode = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF };
int[] rt = { 0, 0, 0, 0 }, lt = { 0, 0, 0, 0 };
int[] jx = { 128, 128, 128, 128 }, jy = { 128, 128, 128, 128 };
JNIdc.init(fileName);
@ -264,8 +266,8 @@ class GL2JNIView extends GLSurfaceView
}
*/
static int kcode_raw = 0xFFFF;
static int lt, rt, jx, jy;
static int[] kcode_raw = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF };
static int[] lt = new int[4], rt = new int[4], jx = new int[4], jy = new int[4];
@Override public boolean onTouchEvent(final MotionEvent event)
{
@ -321,8 +323,8 @@ class GL2JNIView extends GLSurfaceView
anal_id=event.getPointerId(i);
}
else if (vjoy[j][4]==-4) ;
else if(vjoy[j][4]==-1) lt=pre;
else if(vjoy[j][4]==-2) rt=pre;
else if(vjoy[j][4]==-1) lt[0]=pre;
else if(vjoy[j][4]==-2) rt[0]=pre;
else
rv&=~(int)vjoy[j][4];
}
@ -365,8 +367,8 @@ class GL2JNIView extends GLSurfaceView
reset_analog();
anal_id=-1;
rv=0xFFFF;
rt=0;
lt=0;
rt[0]=0;
lt[0]=0;
for(int j=0;j<vjoy.length;j++)
vjoy[j][5]=0;
break;
@ -391,9 +393,9 @@ class GL2JNIView extends GLSurfaceView
if(GL2JNIActivity.keys[0]!=0) rv&=~key_CONT_B;
*/
kcode_raw = rv;
jx = get_anal(11, 0);
jy = get_anal(11, 1);
kcode_raw[0] = rv;
jx[0] = get_anal(11, 0);
jy[0] = get_anal(11, 1);
return(true);
}

View File

@ -16,11 +16,13 @@ public class JNIdc
public static native void rendinit(int w,int y);
public static native void rendframe();
public static native void kcode(int kcode,int lt, int rt, int jx, int jy);
public static native void kcode(int[] kcode, int[] lt, int[] rt, int[] jx, int[] jy);
public static native void vjoy(int id,float x, float y, float w, float h);
//public static native int play(short result[],int size);
public static native void initControllers(boolean[] controllers);
public static void show_osd() {
JNIdc.vjoy(13, 1,0,0,0);
}
@ -28,4 +30,4 @@ public class JNIdc
public static void hide_osd() {
JNIdc.vjoy(13, 0,0,0,0);
}
}
}

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 &= ~map[i + 1];
GL2JNIView.kcode_raw[playerNum] &= ~map[i + 1];
else
GL2JNIView.kcode_raw |= 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 = (int) (L2 * 255);
GL2JNIView.rt = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.jx = (int) (LS_X * 126);
GL2JNIView.jy = (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();

View File

@ -118,9 +118,12 @@ public class MainActivity extends FragmentActivity implements
// Paths
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons
.getResourceId(2, 0)));
// About
// Controllers
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons
.getResourceId(3, 0)));
// About
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons
.getResourceId(4, 0)));
// Recycle the typed array
navMenuIcons.recycle();
@ -435,6 +438,17 @@ public class MainActivity extends FragmentActivity implements
frag_tag = "OPTIONS_FRAG";
break;
case 3:
fragment = (ControllersFragment) getSupportFragmentManager()
.findFragmentByTag("CONTROLLERS_FRAG");
if (fragment != null) {
if (fragment.isVisible()) {
return;
}
}
fragment = new ControllersFragment();
frag_tag = "CONTROLLERS_FRAG";
break;
case 4:
fragment = null;
// vib.vibrate(50);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(