Added configuration GUI for physical controllers
Reverted changes in maple_cfg.cpp except a minor memory leak Fixed an issue with the Xbox 360 controller support, that the first press of the DPAD would not get handled Lots of improvments on multi-controller support
This commit is contained in:
parent
53a89c7ce2
commit
3cb8b2cc6e
|
@ -69,7 +69,6 @@ void mcfg_Create(MapleDeviceType type,u32 bus,u32 port)
|
|||
void mcfg_CreateDevices()
|
||||
{
|
||||
mcfg_Create(MDT_SegaController,0,5);
|
||||
mcfg_Create(MDT_SegaController,1,5);
|
||||
|
||||
#ifdef HAS_VMU
|
||||
mcfg_Create(MDT_SegaVMU,0,0);
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -32,6 +33,8 @@ extern "C"
|
|||
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);
|
||||
}
|
||||
|
@ -244,12 +258,6 @@ JNIEXPORT jint JNICALL Java_com_reicast_emulator_JNIdc_data(JNIEnv *env,jobject
|
|||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_JNIdc_rendframe(JNIEnv *env,jobject obj)
|
||||
{
|
||||
/*char kcode_str0[100];
|
||||
char kcode_str1[100];
|
||||
sprintf(kcode_str0,"%d", kcode[0]);
|
||||
sprintf(kcode_str1,"%d", kcode[1]);
|
||||
__android_log_write(ANDROID_LOG_INFO, "kcode 0", kcode_str0);
|
||||
__android_log_write(ANDROID_LOG_INFO, "kcode 1", kcode_str1);*/
|
||||
while(!rend_single_frame()) ;
|
||||
}
|
||||
|
||||
|
@ -303,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);
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -5,6 +5,11 @@ 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;
|
||||
|
@ -12,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;
|
||||
|
@ -36,7 +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, Integer> deviceId_PlayerNum = new HashMap<Integer, Integer>();
|
||||
HashMap<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
|
||||
HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
|
||||
|
||||
int map[][];
|
||||
|
||||
|
@ -117,10 +124,6 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
map = new int[4][];
|
||||
deviceId_PlayerNum.put(87, 0);
|
||||
deviceId_PlayerNum.put(86, 1);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
moga.onCreate(this);
|
||||
|
||||
|
@ -141,13 +144,54 @@ public class GL2JNIActivity extends Activity {
|
|||
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]));
|
||||
|
||||
Integer playerNum = deviceId_PlayerNum.get(joys[i]);
|
||||
if (playerNum != null) {
|
||||
|
||||
if (InputDevice.getDevice(joys[i]).getName()
|
||||
|
@ -188,7 +232,11 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
|
||||
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[playerNum] = new int[] {
|
||||
|
@ -247,8 +295,8 @@ public class GL2JNIActivity extends Activity {
|
|||
// Log.w("INPUT", event.toString() + " " + event.getSource());
|
||||
// Get all the axis for the KeyEvent
|
||||
|
||||
Integer playerNum = deviceId_PlayerNum.get(event.getDeviceId());
|
||||
Log.w("onGenericMotionEvent playerNum", String.valueOf(playerNum));
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
|
||||
if (playerNum == null)
|
||||
return false;
|
||||
|
||||
|
@ -285,7 +333,8 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
}
|
||||
|
||||
if ((xbox[playerNum] || nVidia[playerNum]) && globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum])
|
||||
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;
|
||||
|
@ -364,18 +413,17 @@ public class GL2JNIActivity extends Activity {
|
|||
}
|
||||
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
Integer playerNum = deviceId_PlayerNum.get(event.getDeviceId());
|
||||
Log.w("onKeyUp playerNum", String.valueOf(playerNum));
|
||||
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) {
|
||||
Integer playerNum = deviceId_PlayerNum.get(event.getDeviceId());
|
||||
Log.w("onKeyDown playerNum", String.valueOf(playerNum));
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
|
||||
if (handle_key(playerNum, keyCode, true)) {
|
||||
JNIdc.hide_osd();
|
||||
if(playerNum == 1)
|
||||
JNIdc.hide_osd();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ public class JNIdc
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
.getResourceId(3, -1)));
|
||||
// About
|
||||
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons
|
||||
.getResourceId(4, -1)));
|
||||
|
||||
// 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(
|
||||
|
|
Loading…
Reference in New Issue