[Android-overlay] Multiple physical gamepad support.
This commit is contained in:
parent
cb3dd6b94b
commit
7718c9959e
|
@ -28,7 +28,7 @@ namespace ButtonManager
|
||||||
std::map<std::pair<int, int>, Button*> m_buttons;
|
std::map<std::pair<int, int>, Button*> m_buttons;
|
||||||
std::map<std::pair<int, int>, Axis*> m_axises;
|
std::map<std::pair<int, int>, Axis*> m_axises;
|
||||||
std::unordered_map<std::string, InputDevice*> m_controllers;
|
std::unordered_map<std::string, InputDevice*> m_controllers;
|
||||||
const char *configStrings[] = { "InputA",
|
const char* configStrings[] = { "InputA",
|
||||||
"InputB",
|
"InputB",
|
||||||
"InputStart",
|
"InputStart",
|
||||||
"InputX",
|
"InputX",
|
||||||
|
@ -94,29 +94,34 @@ namespace ButtonManager
|
||||||
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini"));
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini"));
|
||||||
for (int a = 0; a < configStringNum; ++a)
|
for (int a = 0; a < configStringNum; ++a)
|
||||||
{
|
{
|
||||||
BindType type;
|
for (int padID = 0; padID < 4; ++padID)
|
||||||
int bindnum;
|
|
||||||
char dev[128];
|
|
||||||
bool hasbind = false;
|
|
||||||
char modifier = 0;
|
|
||||||
std::string value;
|
|
||||||
ini.Get("Android", configStrings[a], &value, "None");
|
|
||||||
if (value == "None")
|
|
||||||
continue;
|
|
||||||
if (std::string::npos != value.find("Axis"))
|
|
||||||
{
|
{
|
||||||
hasbind = true;
|
std::ostringstream config;
|
||||||
type = BIND_AXIS;
|
config << configStrings[a] << "_" << padID;
|
||||||
sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier);
|
BindType type;
|
||||||
|
int bindnum;
|
||||||
|
char dev[128];
|
||||||
|
bool hasbind = false;
|
||||||
|
char modifier = 0;
|
||||||
|
std::string value;
|
||||||
|
ini.Get("Android", config.str().c_str(), &value, "None");
|
||||||
|
if (value == "None")
|
||||||
|
continue;
|
||||||
|
if (std::string::npos != value.find("Axis"))
|
||||||
|
{
|
||||||
|
hasbind = true;
|
||||||
|
type = BIND_AXIS;
|
||||||
|
sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier);
|
||||||
|
}
|
||||||
|
else if (std::string::npos != value.find("Button"))
|
||||||
|
{
|
||||||
|
hasbind = true;
|
||||||
|
type = BIND_BUTTON;
|
||||||
|
sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum);
|
||||||
|
}
|
||||||
|
if (hasbind)
|
||||||
|
AddBind(std::string(dev), new sBind(padID, (ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f));
|
||||||
}
|
}
|
||||||
else if (std::string::npos != value.find("Button"))
|
|
||||||
{
|
|
||||||
hasbind = true;
|
|
||||||
type = BIND_BUTTON;
|
|
||||||
sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum);
|
|
||||||
}
|
|
||||||
if (hasbind)
|
|
||||||
AddBind(std::string(dev), new sBind((ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,7 +131,7 @@ namespace ButtonManager
|
||||||
pressed = m_buttons[std::make_pair(padID, button)]->Pressed();
|
pressed = m_buttons[std::make_pair(padID, button)]->Pressed();
|
||||||
|
|
||||||
for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it)
|
for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it)
|
||||||
pressed |= it->second->ButtonValue(button);
|
pressed |= it->second->ButtonValue(padID, button);
|
||||||
|
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +143,7 @@ namespace ButtonManager
|
||||||
auto it = m_controllers.begin();
|
auto it = m_controllers.begin();
|
||||||
if (it == m_controllers.end())
|
if (it == m_controllers.end())
|
||||||
return value;
|
return value;
|
||||||
return it->second->AxisValue(axis);
|
return it->second->AxisValue(padID, axis);
|
||||||
}
|
}
|
||||||
void TouchEvent(int padID, int button, int action)
|
void TouchEvent(int padID, int button, int action)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +153,7 @@ namespace ButtonManager
|
||||||
{
|
{
|
||||||
m_axises[std::make_pair(padID, axis)]->SetValue(value);
|
m_axises[std::make_pair(padID, axis)]->SetValue(value);
|
||||||
}
|
}
|
||||||
void GamepadEvent(std::string dev, int button, int action)
|
void GamepadEvent(std::string dev, ButtonType button, int action)
|
||||||
{
|
{
|
||||||
auto it = m_controllers.find(dev);
|
auto it = m_controllers.find(dev);
|
||||||
if (it != m_controllers.end())
|
if (it != m_controllers.end())
|
||||||
|
@ -159,7 +164,7 @@ namespace ButtonManager
|
||||||
m_controllers[dev] = new InputDevice(dev);
|
m_controllers[dev] = new InputDevice(dev);
|
||||||
m_controllers[dev]->PressEvent(button, action);
|
m_controllers[dev]->PressEvent(button, action);
|
||||||
}
|
}
|
||||||
void GamepadAxisEvent(std::string dev, int axis, float value)
|
void GamepadAxisEvent(std::string dev, ButtonType axis, float value)
|
||||||
{
|
{
|
||||||
auto it = m_controllers.find(dev);
|
auto it = m_controllers.find(dev);
|
||||||
if (it != m_controllers.end())
|
if (it != m_controllers.end())
|
||||||
|
@ -181,31 +186,35 @@ namespace ButtonManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputDevice
|
// InputDevice
|
||||||
void InputDevice::PressEvent(int button, int action)
|
void InputDevice::PressEvent(ButtonType button, int action)
|
||||||
{
|
{
|
||||||
m_buttons[button] = action == 0 ? true : false;
|
m_buttons[m_binds[button]->m_bind] = action == 0 ? true : false;
|
||||||
}
|
}
|
||||||
void InputDevice::AxisEvent(int axis, float value)
|
void InputDevice::AxisEvent(ButtonType axis, float value)
|
||||||
{
|
{
|
||||||
m_axises[axis] = value;
|
m_axises[m_binds[axis]->m_bind] = value;
|
||||||
}
|
}
|
||||||
bool InputDevice::ButtonValue(ButtonType button)
|
bool InputDevice::ButtonValue(int padID, ButtonType button)
|
||||||
{
|
{
|
||||||
auto it = m_binds.find(button);
|
auto it = m_binds.find(button);
|
||||||
if (it == m_binds.end())
|
if (it == m_binds.end())
|
||||||
return false;
|
return false;
|
||||||
|
if (it->second->m_padID != padID)
|
||||||
|
return false;
|
||||||
if (it->second->m_bindtype == BIND_BUTTON)
|
if (it->second->m_bindtype == BIND_BUTTON)
|
||||||
return m_buttons[it->second->m_bind];
|
return m_buttons[it->second->m_bind];
|
||||||
else
|
else
|
||||||
return AxisValue(button);
|
return AxisValue(padID, button);
|
||||||
}
|
}
|
||||||
float InputDevice::AxisValue(ButtonType axis)
|
float InputDevice::AxisValue(int padID, ButtonType axis)
|
||||||
{
|
{
|
||||||
auto it = m_binds.find(axis);
|
auto it = m_binds.find(axis);
|
||||||
if (it == m_binds.end())
|
if (it == m_binds.end())
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
if (it->second->m_padID != padID)
|
||||||
|
return 0.0f;
|
||||||
if (it->second->m_bindtype == BIND_BUTTON)
|
if (it->second->m_bindtype == BIND_BUTTON)
|
||||||
return ButtonValue(axis);
|
return ButtonValue(padID, axis);
|
||||||
else
|
else
|
||||||
return m_axises[it->second->m_bind] * it->second->m_neg;
|
return m_axises[it->second->m_bind] * it->second->m_neg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,12 +85,13 @@ namespace ButtonManager
|
||||||
|
|
||||||
struct sBind
|
struct sBind
|
||||||
{
|
{
|
||||||
|
const int m_padID;
|
||||||
const ButtonType m_buttontype;
|
const ButtonType m_buttontype;
|
||||||
const BindType m_bindtype;
|
const BindType m_bindtype;
|
||||||
const int m_bind;
|
const int m_bind;
|
||||||
const float m_neg;
|
const float m_neg;
|
||||||
sBind(ButtonType buttontype, BindType bindtype, int bind, float neg)
|
sBind(int padID, ButtonType buttontype, BindType bindtype, int bind, float neg)
|
||||||
: m_buttontype(buttontype), m_bindtype(bindtype), m_bind(bind), m_neg(neg)
|
: m_padID(padID), m_buttontype(buttontype), m_bindtype(bindtype), m_bind(bind), m_neg(neg)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,10 +114,10 @@ namespace ButtonManager
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
void AddBind(sBind *bind) { m_binds[bind->m_buttontype] = bind; }
|
void AddBind(sBind *bind) { m_binds[bind->m_buttontype] = bind; }
|
||||||
void PressEvent(int button, int action);
|
void PressEvent(ButtonType button, int action);
|
||||||
void AxisEvent(int axis, float value);
|
void AxisEvent(ButtonType axis, float value);
|
||||||
bool ButtonValue(ButtonType button);
|
bool ButtonValue(int padID, ButtonType button);
|
||||||
float AxisValue(ButtonType axis);
|
float AxisValue(int padID, ButtonType axis);
|
||||||
};
|
};
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
@ -124,7 +125,7 @@ namespace ButtonManager
|
||||||
float GetAxisValue(int padID, ButtonType axis);
|
float GetAxisValue(int padID, ButtonType axis);
|
||||||
void TouchEvent(int padID, int button, int action);
|
void TouchEvent(int padID, int button, int action);
|
||||||
void TouchAxisEvent(int padID, int axis, float value);
|
void TouchAxisEvent(int padID, int axis, float value);
|
||||||
void GamepadEvent(std::string dev, int button, int action);
|
void GamepadEvent(std::string dev, ButtonType button, int action);
|
||||||
void GamepadAxisEvent(std::string dev, int axis, float value);
|
void GamepadAxisEvent(std::string dev, ButtonType axis, float value);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,14 +249,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEve
|
||||||
{
|
{
|
||||||
const char *Device = env->GetStringUTFChars(jDevice, NULL);
|
const char *Device = env->GetStringUTFChars(jDevice, NULL);
|
||||||
std::string strDevice = std::string(Device);
|
std::string strDevice = std::string(Device);
|
||||||
ButtonManager::GamepadEvent(strDevice, Button, Action);
|
ButtonManager::GamepadEvent(strDevice, (ButtonManager::ButtonType)Button, Action);
|
||||||
env->ReleaseStringUTFChars(jDevice, Device);
|
env->ReleaseStringUTFChars(jDevice, Device);
|
||||||
}
|
}
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Axis, jfloat Value)
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Axis, jfloat Value)
|
||||||
{
|
{
|
||||||
const char *Device = env->GetStringUTFChars(jDevice, NULL);
|
const char *Device = env->GetStringUTFChars(jDevice, NULL);
|
||||||
std::string strDevice = std::string(Device);
|
std::string strDevice = std::string(Device);
|
||||||
ButtonManager::GamepadAxisEvent(strDevice, Axis, Value);
|
ButtonManager::GamepadAxisEvent(strDevice, (ButtonManager::ButtonType)Axis, Value);
|
||||||
env->ReleaseStringUTFChars(jDevice, Device);
|
env->ReleaseStringUTFChars(jDevice, Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue