mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
If an input (axis or key) is mapped to multiple targets, trigger them
all, not just the first one.
This commit is contained in:
parent
af158bf6cc
commit
bf7f582c3c
@ -671,27 +671,23 @@ KeyDef AxisDef(int deviceId, int axisId, int direction) {
|
||||
return KeyDef(deviceId, TranslateKeyCodeFromAxis(axisId, direction));
|
||||
}
|
||||
|
||||
static bool FindKeyMapping(int deviceId, int key, int *psp_button) {
|
||||
static bool FindKeyMapping(int deviceId, int key, std::vector<int> *psp_button) {
|
||||
// Brute force, let's optimize later
|
||||
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
|
||||
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
|
||||
if (*iter2 == KeyDef(deviceId, key)) {
|
||||
*psp_button = iter->first;
|
||||
return true;
|
||||
psp_button->push_back(iter->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return psp_button->size() > 0;
|
||||
}
|
||||
|
||||
int KeyToPspButton(int deviceId, int key) {
|
||||
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys) {
|
||||
int search_start_layer = 0;
|
||||
int psp_button;
|
||||
|
||||
if (FindKeyMapping(deviceId, key, &psp_button))
|
||||
return psp_button;
|
||||
|
||||
return KEYMAP_ERROR_UNKNOWN_KEY;
|
||||
return FindKeyMapping(deviceId, key, pspKeys);
|
||||
}
|
||||
|
||||
// TODO: vector output
|
||||
@ -708,9 +704,9 @@ bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int AxisToPspButton(int deviceId, int axisId, int direction) {
|
||||
bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys) {
|
||||
int key = TranslateKeyCodeFromAxis(axisId, direction);
|
||||
return KeyToPspButton(deviceId, key);
|
||||
return KeyToPspButton(deviceId, key, pspKeys);
|
||||
}
|
||||
|
||||
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction) {
|
||||
|
@ -124,10 +124,7 @@ namespace KeyMap {
|
||||
// Use if to translate KeyMap Keys to PSP
|
||||
// buttons. You should have already translated
|
||||
// your platform's keys to KeyMap keys.
|
||||
//
|
||||
// Returns KEYMAP_ERROR_UNKNOWN_KEY
|
||||
// for any unmapped key
|
||||
int KeyToPspButton(int deviceId, int key);
|
||||
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
|
||||
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys);
|
||||
|
||||
int TranslateKeyCodeToAxis(int keyCode, int &direction);
|
||||
@ -141,7 +138,7 @@ namespace KeyMap {
|
||||
// Direction is negative or positive.
|
||||
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
|
||||
|
||||
int AxisToPspButton(int deviceId, int axisId, int direction);
|
||||
bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys);
|
||||
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
|
||||
std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction);
|
||||
|
||||
|
@ -312,11 +312,11 @@ void EmuScreen::key(const KeyInput &key) {
|
||||
pauseTrigger_ = true;
|
||||
}
|
||||
|
||||
int result = KeyMap::KeyToPspButton(key.deviceId, key.keyCode);
|
||||
if (result == KEYMAP_ERROR_UNKNOWN_KEY)
|
||||
return;
|
||||
|
||||
pspKey(result, key.flags);
|
||||
std::vector<int> pspKeys;
|
||||
KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys);
|
||||
for (size_t i = 0; i < pspKeys.size(); i++) {
|
||||
pspKey(pspKeys[i], key.flags);
|
||||
}
|
||||
}
|
||||
|
||||
void EmuScreen::pspKey(int pspKeyCode, int flags) {
|
||||
@ -352,51 +352,58 @@ void EmuScreen::axis(const AxisInput &axis) {
|
||||
}
|
||||
|
||||
void EmuScreen::processAxis(const AxisInput &axis, int direction) {
|
||||
int result = KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, direction);
|
||||
int resultOpposite = KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -direction);
|
||||
std::vector<int> results;
|
||||
KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, direction, &results);
|
||||
std::vector<int> resultsOpposite;
|
||||
KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -direction, &resultsOpposite);
|
||||
|
||||
if (result == KEYMAP_ERROR_UNKNOWN_KEY)
|
||||
return;
|
||||
for (size_t i = 0; i < results.size(); i++) {
|
||||
int result = results[i];
|
||||
switch (result) {
|
||||
case VIRTKEY_AXIS_X_MIN:
|
||||
__CtrlSetAnalogX(-fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_X_MAX:
|
||||
__CtrlSetAnalogX(fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_Y_MIN:
|
||||
__CtrlSetAnalogY(-fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_Y_MAX:
|
||||
__CtrlSetAnalogY(fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
|
||||
switch (result) {
|
||||
case VIRTKEY_AXIS_X_MIN:
|
||||
__CtrlSetAnalogX(-fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_X_MAX:
|
||||
__CtrlSetAnalogX(fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_Y_MIN:
|
||||
__CtrlSetAnalogY(-fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_Y_MAX:
|
||||
__CtrlSetAnalogY(fabs(axis.value), CTRL_STICK_LEFT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_X_MIN:
|
||||
__CtrlSetAnalogX(-fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_X_MAX:
|
||||
__CtrlSetAnalogX(fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_Y_MIN:
|
||||
__CtrlSetAnalogY(-fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_Y_MAX:
|
||||
__CtrlSetAnalogY(fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
|
||||
case VIRTKEY_AXIS_RIGHT_X_MIN:
|
||||
__CtrlSetAnalogX(-fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_X_MAX:
|
||||
__CtrlSetAnalogX(fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_Y_MIN:
|
||||
__CtrlSetAnalogY(-fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
case VIRTKEY_AXIS_RIGHT_Y_MAX:
|
||||
__CtrlSetAnalogY(fabs(axis.value), CTRL_STICK_RIGHT);
|
||||
break;
|
||||
default:
|
||||
if (axis.value >= AXIS_BIND_THRESHOLD || axis.value <= -AXIS_BIND_THRESHOLD) {
|
||||
pspKey(result, KEY_DOWN);
|
||||
|
||||
default:
|
||||
if (axis.value >= AXIS_BIND_THRESHOLD || axis.value <= -AXIS_BIND_THRESHOLD) {
|
||||
pspKey(result, KEY_DOWN);
|
||||
|
||||
// Also unpress the other direction.
|
||||
result = KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, axis.value >= 0 ? -1 : 1);
|
||||
if (result != KEYMAP_ERROR_UNKNOWN_KEY)
|
||||
// Also unpress the other direction.
|
||||
std::vector<int> opposite;
|
||||
KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, axis.value >= 0 ? -1 : 1, &opposite);
|
||||
for (size_t i = 0; i < opposite.size(); i++) {
|
||||
pspKey(opposite[i], KEY_UP);
|
||||
}
|
||||
// Hm, why do we use a different way below?
|
||||
} else {
|
||||
// Release both directions, trying to deal with some erratic controllers that can cause it to stick.
|
||||
pspKey(result, KEY_UP);
|
||||
} else {
|
||||
// Release both directions, trying to deal with some erratic controllers that can cause it to stick.
|
||||
pspKey(result, KEY_UP);
|
||||
pspKey(resultOpposite, KEY_UP);
|
||||
for (size_t i = 0; i < resultsOpposite.size(); i++) {
|
||||
pspKey(resultsOpposite[i], KEY_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user