Merge pull request #2692 from unknownbrackets/keymap-axis

Do axis keymap as well (should replace right stick bind)
This commit is contained in:
Henrik Rydgård 2013-07-08 01:14:02 -07:00
commit 476382d2cc
11 changed files with 386 additions and 408 deletions

View File

@ -22,6 +22,8 @@
namespace KeyMap {
KeyDef AxisDef(int deviceId, int axisId, int direction);
// TODO: Make use const_map.h from native
struct DefaultKeyMap {
static KeyMapping defaultKeyboardMap()
@ -72,24 +74,32 @@ struct DefaultKeyMap {
m[KeyDef(DEVICE_ID_X360_0, KEYCODE_BUTTON_R2)] = VIRTKEY_UNTHROTTLE;
m[KeyDef(DEVICE_ID_X360_0, KEYCODE_BUTTON_THUMBR)] = VIRTKEY_PAUSE;
m[KeyDef(DEVICE_ID_X360_0, KEYCODE_BUTTON_L2)] = VIRTKEY_SPEED_TOGGLE;
m[AxisDef(DEVICE_ID_X360_0, JOYSTICK_AXIS_X, -1)] = VIRTKEY_AXIS_X_MIN;
m[AxisDef(DEVICE_ID_X360_0, JOYSTICK_AXIS_X, +1)] = VIRTKEY_AXIS_X_MAX;
m[AxisDef(DEVICE_ID_X360_0, JOYSTICK_AXIS_Y, -1)] = VIRTKEY_AXIS_Y_MIN;
m[AxisDef(DEVICE_ID_X360_0, JOYSTICK_AXIS_Y, +1)] = VIRTKEY_AXIS_Y_MAX;
return m;
}
static KeyMapping defaultPadMap()
{
KeyMapping m;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_A)] = CTRL_CROSS;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_B)] = CTRL_CIRCLE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_X)] = CTRL_SQUARE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_Y)] = CTRL_TRIANGLE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_2)] = CTRL_CROSS;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_3)] = CTRL_CIRCLE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_4)] = CTRL_SQUARE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_1)] = CTRL_TRIANGLE;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_DPAD_UP)] = CTRL_UP;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_DPAD_RIGHT)] = CTRL_RIGHT;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_DPAD_DOWN)] = CTRL_DOWN;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_DPAD_LEFT)] = CTRL_LEFT;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_START)] = CTRL_START;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BACK)] = CTRL_SELECT;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_L1)] = CTRL_LTRIGGER;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_R1)] = CTRL_RTRIGGER;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_10)] = CTRL_START;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_9)] = CTRL_SELECT;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_7)] = CTRL_LTRIGGER;
m[KeyDef(DEVICE_ID_PAD_0, KEYCODE_BUTTON_8)] = CTRL_RTRIGGER;
m[AxisDef(DEVICE_ID_PAD_0, JOYSTICK_AXIS_X, -1)] = VIRTKEY_AXIS_X_MIN;
m[AxisDef(DEVICE_ID_PAD_0, JOYSTICK_AXIS_X, +1)] = VIRTKEY_AXIS_X_MAX;
m[AxisDef(DEVICE_ID_PAD_0, JOYSTICK_AXIS_Y, +1)] = VIRTKEY_AXIS_Y_MIN;
m[AxisDef(DEVICE_ID_PAD_0, JOYSTICK_AXIS_Y, -1)] = VIRTKEY_AXIS_Y_MAX;
return m;
}
@ -108,6 +118,10 @@ struct DefaultKeyMap {
m[KeyDef(DEVICE_ID_DEFAULT, KEYCODE_BACK)] = CTRL_SELECT;
m[KeyDef(DEVICE_ID_DEFAULT, KEYCODE_BUTTON_L1)] = CTRL_LTRIGGER;
m[KeyDef(DEVICE_ID_DEFAULT, KEYCODE_BUTTON_R1)] = CTRL_RTRIGGER;
m[AxisDef(DEVICE_ID_DEFAULT, JOYSTICK_AXIS_X, -1)] = VIRTKEY_AXIS_X_MIN;
m[AxisDef(DEVICE_ID_DEFAULT, JOYSTICK_AXIS_X, +1)] = VIRTKEY_AXIS_X_MAX;
m[AxisDef(DEVICE_ID_DEFAULT, JOYSTICK_AXIS_Y, -1)] = VIRTKEY_AXIS_Y_MIN;
m[AxisDef(DEVICE_ID_DEFAULT, JOYSTICK_AXIS_Y, +1)] = VIRTKEY_AXIS_Y_MAX;
return m;
}
@ -329,7 +343,35 @@ const KeyMap_IntStrPair key_names[] = {
{KEYCODE_NUMPAD_9, "Num9"},
};
static int key_names_count = sizeof(key_names) / sizeof(key_names[0]);
const KeyMap_IntStrPair axis_names[] = {
{JOYSTICK_AXIS_X, "X Axis"},
{JOYSTICK_AXIS_Y, "Y Axis"},
{JOYSTICK_AXIS_PRESSURE, "Pressure"},
{JOYSTICK_AXIS_SIZE, "Size"},
{JOYSTICK_AXIS_TOUCH_MAJOR, "Touch Major"},
{JOYSTICK_AXIS_TOUCH_MINOR, "Touch Minor"},
{JOYSTICK_AXIS_TOOL_MAJOR, "Tool Major"},
{JOYSTICK_AXIS_TOOL_MINOR, "Tool Minor"},
{JOYSTICK_AXIS_ORIENTATION, "Orient"},
{JOYSTICK_AXIS_VSCROLL, "Vert Scroll"},
{JOYSTICK_AXIS_HSCROLL, "Horiz Scroll"},
{JOYSTICK_AXIS_Z, "Z Axis"},
{JOYSTICK_AXIS_RX, "X Rotation"},
{JOYSTICK_AXIS_RY, "Y Rotation"},
{JOYSTICK_AXIS_RZ, "Z Rotation"},
{JOYSTICK_AXIS_HAT_X, "X HAT"},
{JOYSTICK_AXIS_HAT_Y, "Y HAT"},
{JOYSTICK_AXIS_LTRIGGER, "TriggerL"},
{JOYSTICK_AXIS_RTRIGGER, "TriggerR"},
{JOYSTICK_AXIS_THROTTLE, "Throttle"},
{JOYSTICK_AXIS_RUDDER, "Rudder"},
{JOYSTICK_AXIS_WHEEL, "Wheel"},
{JOYSTICK_AXIS_GAS, "Gas"},
{JOYSTICK_AXIS_BRAKE, "Brake"},
{JOYSTICK_AXIS_DISTANCE, "Distance"},
{JOYSTICK_AXIS_TILT, "Tilt"}
};
static std::string unknown_key_name = "??";
const KeyMap_IntStrPair psp_button_names[] = {
{CTRL_CIRCLE, "O"},
@ -350,17 +392,22 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_AXIS_Y_MIN, "An.Down"},
{VIRTKEY_AXIS_Y_MAX, "An.Up"},
{VIRTKEY_AXIS_RIGHT_X_MIN, "RightAn.Left"},
{VIRTKEY_AXIS_RIGHT_X_MAX, "RightAn.Right"},
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
{VIRTKEY_AXIS_RIGHT_Y_MAX, "RightAn.Up"},
{VIRTKEY_RAPID_FIRE, "RapidFire"},
{VIRTKEY_UNTHROTTLE, "Unthrottle"},
{VIRTKEY_SPEED_TOGGLE, "SpeedToggle"},
{VIRTKEY_PAUSE, "Pause"},
};
static int psp_button_names_count = sizeof(psp_button_names) / sizeof(psp_button_names[0]);
const int AXIS_BIND_KEYCODE_START = 4000;
static std::string FindName(int key, const KeyMap_IntStrPair list[], int size)
static std::string FindName(int key, const KeyMap_IntStrPair list[], size_t size)
{
for (int i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
if (list[i].key == key)
return list[i].name;
@ -369,14 +416,36 @@ static std::string FindName(int key, const KeyMap_IntStrPair list[], int size)
std::string GetKeyName(int keyCode)
{
return FindName(keyCode, key_names, key_names_count);
return FindName(keyCode, key_names, ARRAY_SIZE(key_names));
}
std::string GetPspButtonName(int btn)
{
return FindName(btn, psp_button_names, psp_button_names_count);
return FindName(btn, psp_button_names, ARRAY_SIZE(psp_button_names));
}
int TranslateKeyCodeToAxis(int keyCode, int &direction)
{
if (keyCode < AXIS_BIND_KEYCODE_START)
return 0;
int v = keyCode - AXIS_BIND_KEYCODE_START;
// Even/odd for direction.
direction = v & 1 ? -1 : 1;
return v / 2;
}
int TranslateKeyCodeFromAxis(int axisId, int direction)
{
direction = direction < 0 ? 1 : 0;
return AXIS_BIND_KEYCODE_START + axisId * 2 + direction;
}
KeyDef AxisDef(int deviceId, int axisId, int direction) {
return KeyDef(deviceId, TranslateKeyCodeFromAxis(axisId, direction));
}
static bool FindKeyMapping(int deviceId, int key, int *psp_button)
{
for (size_t i = 0; i < controllerMaps.size(); i++) {
@ -417,9 +486,34 @@ bool KeyFromPspButton(int controllerMap, int btn, int *deviceId, int *keyCode)
return false;
}
int AxisToPspButton(int deviceId, int axisId, int direction)
{
int key = TranslateKeyCodeFromAxis(axisId, direction);
return KeyToPspButton(deviceId, key);
}
bool AxisFromPspButton(int controllerMap, int btn, int *deviceId, int *axisId, int *direction)
{
int search_start_layer = 0;
for (auto iter = controllerMaps[controllerMap].keys.begin(); iter != controllerMaps[controllerMap].keys.end(); ++iter) {
if (iter->second == btn && iter->first.keyCode >= AXIS_BIND_KEYCODE_START) {
*deviceId = iter->first.deviceId;
*axisId = TranslateKeyCodeToAxis(iter->first.keyCode, *direction);
return true;
}
}
return false;
}
std::string NameKeyFromPspButton(int controllerMap, int btn) {
int deviceId;
int axisId;
int direction;
int keyCode;
if (AxisFromPspButton(controllerMap, btn, &deviceId, &axisId, &direction)) {
return GetAxisName(axisId) + (direction < 0 ? "-" : "+");
}
if (KeyFromPspButton(controllerMap, btn, &deviceId, &keyCode)) {
return GetKeyName(keyCode);
}
@ -428,7 +522,12 @@ std::string NameKeyFromPspButton(int controllerMap, int btn) {
std::string NameDeviceFromPspButton(int controllerMap, int btn) {
int deviceId;
int axisId;
int direction;
int keyCode;
if (AxisFromPspButton(controllerMap, btn, &deviceId, &axisId, &direction)) {
return GetDeviceName(deviceId);
}
if (KeyFromPspButton(controllerMap, btn, &deviceId, &keyCode)) {
return GetDeviceName(deviceId);
}
@ -446,7 +545,7 @@ std::string NamePspButtonFromKey(int deviceId, int key)
}
void RemoveButtonMapping(int map, int btn) {
for (auto iter = controllerMaps[map].keys.begin(); iter != controllerMaps[map].keys.end(); ++iter) {
for (auto iter = controllerMaps[map].keys.begin(); iter != controllerMaps[map].keys.end(); ++iter) {
if (iter->second == btn) {
controllerMaps[map].keys.erase(iter);
return;
@ -460,6 +559,29 @@ void SetKeyMapping(int map, int deviceId, int key, int btn)
controllerMaps[map].keys[KeyDef(deviceId, key)] = btn;
}
std::string GetAxisName(int axisId)
{
return FindName(axisId, axis_names, ARRAY_SIZE(axis_names));
}
bool IsMappedAxis(int deviceId, int axisId, int direction)
{
int key = TranslateKeyCodeFromAxis(axisId, direction);
return KeyToPspButton(deviceId, key) != KEYMAP_ERROR_UNKNOWN_KEY;
}
std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction)
{
int key = TranslateKeyCodeFromAxis(axisId, direction);
return GetPspButtonName(KeyToPspButton(deviceId, key));
}
void SetAxisMapping(int map, int deviceId, int axisId, int direction, int btn)
{
int key = TranslateKeyCodeFromAxis(axisId, direction);
SetKeyMapping(map, deviceId, key, btn);
}
void RestoreDefault() {
controllerMaps = DefaultKeyMap::KeyMap;
}

View File

@ -36,10 +36,16 @@ enum {
VIRTKEY_UNTHROTTLE = 0x10005,
VIRTKEY_PAUSE = 0x10006,
VIRTKEY_SPEED_TOGGLE = 0x10007,
VIRTKEY_AXIS_RIGHT_X_MIN = 0x10008,
VIRTKEY_AXIS_RIGHT_Y_MIN = 0x10009,
VIRTKEY_AXIS_RIGHT_X_MAX = 0x1000a,
VIRTKEY_AXIS_RIGHT_Y_MAX = 0x1000b,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};
const float AXIS_BIND_THRESHOLD = 0.75f;
class KeyDef {
public:
KeyDef(int devId, int k) : deviceId(devId), keyCode(k) {}
@ -115,6 +121,16 @@ namespace KeyMap {
// Any configuration will be saved to the Core config.
void SetKeyMapping(int map, int deviceId, int keyCode, int psp_key);
std::string GetAxisName(int axisId);
int AxisToPspButton(int deviceId, int axisId, int direction);
bool AxisFromPspButton(int controllerMap, int btn, int *deviceId, int *axisId, int *direction);
bool IsMappedAxis(int deviceId, int axisId, int direction);
std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction);
// Configure an axis mapping, saves the configuration.
// Direction is negative or positive.
void SetAxisMapping(int map, int deviceId, int axisId, int direction, int btn);
void LoadFromIni(IniFile &iniFile);
void SaveToIni(IniFile &iniFile);
void RestoreDefault();

View File

@ -145,8 +145,6 @@ void Config::Load(const char *iniFileName)
control->Get("LargeControls", &bLargeControls, false);
// control->Get("KeyMapping",iMappingMap);
control->Get("AccelerometerToAnalogHoriz", &bAccelerometerToAnalogHoriz, false);
control->Get("RightStickBind", &iRightStickBind, 0);
control->Get("SwapDInputRightAxes", &iSwapRightAxes, 0);
control->Get("TouchButtonOpacity", &iTouchButtonOpacity, 65);
control->Get("ButtonScale", &fButtonScale, 1.15);
@ -259,8 +257,6 @@ void Config::Save()
control->Set("LargeControls", bLargeControls);
// control->Set("KeyMapping",iMappingMap);
control->Set("AccelerometerToAnalogHoriz", bAccelerometerToAnalogHoriz);
control->Set("RightStickBind", iRightStickBind);
control->Set("SwapDInputRightAxes", iSwapRightAxes);
control->Set("TouchButtonOpacity", iTouchButtonOpacity);
control->Set("ButtonScale", fButtonScale);

View File

@ -108,14 +108,6 @@ public:
bool bShowDebugStats;
bool bLargeControls;
bool bAccelerometerToAnalogHoriz;
// Temporary until control mapping rewrite
// 0 = none
// 1 = arrow buttons
// 2 = face buttons
// 3 = L/R
// 4 = L/R + triangle/cross
int iRightStickBind;
int iSwapRightAxes;
// Control
int iTouchButtonOpacity;

View File

@ -107,7 +107,6 @@ EmuScreen::EmuScreen(const std::string &filename) : invalid_(true) {
osm.Show(s->T("PressESC", "Press ESC to open the pause menu"), 3.0f);
}
#endif
memset(analog_, 0, sizeof(analog_));
memset(&fakeInputState, 0, sizeof(fakeInputState));
memset(virtKeys, 0, sizeof(virtKeys));
}
@ -203,11 +202,54 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) {
case VIRTKEY_PAUSE:
screenManager()->push(new PauseScreen());
break;
case VIRTKEY_AXIS_X_MIN:
__CtrlSetAnalogX(-1.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_X_MAX:
__CtrlSetAnalogX(1.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_Y_MIN:
__CtrlSetAnalogY(-1.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_Y_MAX:
__CtrlSetAnalogY(1.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_RIGHT_X_MIN:
__CtrlSetAnalogX(-1.0f, CTRL_STICK_RIGHT);
break;
case VIRTKEY_AXIS_RIGHT_X_MAX:
__CtrlSetAnalogX(1.0f, CTRL_STICK_RIGHT);
break;
case VIRTKEY_AXIS_RIGHT_Y_MIN:
__CtrlSetAnalogY(-1.0f, CTRL_STICK_RIGHT);
break;
case VIRTKEY_AXIS_RIGHT_Y_MAX:
__CtrlSetAnalogY(1.0f, CTRL_STICK_RIGHT);
break;
}
}
void EmuScreen::onVKeyUp(int virtualKeyCode) {
switch (virtualKeyCode) {
case VIRTKEY_AXIS_X_MIN:
case VIRTKEY_AXIS_X_MAX:
__CtrlSetAnalogX(0.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_Y_MIN:
case VIRTKEY_AXIS_Y_MAX:
__CtrlSetAnalogY(0.0f, CTRL_STICK_LEFT);
break;
case VIRTKEY_AXIS_RIGHT_X_MIN:
case VIRTKEY_AXIS_RIGHT_X_MAX:
__CtrlSetAnalogX(0.0f, CTRL_STICK_RIGHT);
break;
case VIRTKEY_AXIS_RIGHT_Y_MIN:
case VIRTKEY_AXIS_RIGHT_Y_MAX:
__CtrlSetAnalogY(0.0f, CTRL_STICK_RIGHT);
break;
default:
break;
}
@ -218,31 +260,71 @@ void EmuScreen::key(const KeyInput &key) {
if (result == KEYMAP_ERROR_UNKNOWN_KEY)
return;
if (result >= VIRTKEY_FIRST) {
int vk = result - VIRTKEY_FIRST;
if (key.flags & KEY_DOWN) {
pspKey(result, key.flags);
}
void EmuScreen::pspKey(int pspKeyCode, int flags) {
if (pspKeyCode >= VIRTKEY_FIRST) {
int vk = pspKeyCode - VIRTKEY_FIRST;
if (flags & KEY_DOWN) {
virtKeys[vk] = true;
onVKeyDown(result);
onVKeyDown(pspKeyCode);
}
if (key.flags & KEY_UP) {
if (flags & KEY_UP) {
virtKeys[vk] = false;
onVKeyUp(result);
onVKeyUp(pspKeyCode);
}
} else {
if (key.flags & KEY_DOWN)
__CtrlButtonDown(result);
if (key.flags & KEY_UP)
__CtrlButtonUp(result);
if (flags & KEY_DOWN)
__CtrlButtonDown(pspKeyCode);
if (flags & KEY_UP)
__CtrlButtonUp(pspKeyCode);
}
}
void EmuScreen::axis(const AxisInput &axis) {
// TODO: Apply some form of axis mapping
switch (axis.axisId) {
case JOYSTICK_AXIS_X: analog_[0].x = axis.value; break;
case JOYSTICK_AXIS_Y: analog_[0].y = axis.value; break;
case JOYSTICK_AXIS_Z: analog_[1].x = axis.value; break;
case JOYSTICK_AXIS_RZ: analog_[1].y = axis.value; break;
int result = KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, axis.value >= 0 ? 1 : -1);
if (result == KEYMAP_ERROR_UNKNOWN_KEY)
return;
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;
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)
pspKey(result, KEY_UP);
} else {
pspKey(result, KEY_UP);
}
}
}
@ -276,20 +358,12 @@ void EmuScreen::update(InputState &input) {
if (invalid_)
return;
float leftstick_x = analog_[0].x;
float leftstick_y = analog_[0].y;
float rightstick_x = analog_[1].x;
float rightstick_y = analog_[1].y;
float leftstick_x = 0.0f;
float leftstick_y = 0.0f;
float rightstick_x = 0.0f;
float rightstick_y = 0.0f;
// Virtual keys.
if (virtKeys[VIRTKEY_AXIS_X_MIN - VIRTKEY_FIRST])
leftstick_x -= 1.0f;
if (virtKeys[VIRTKEY_AXIS_X_MAX - VIRTKEY_FIRST])
leftstick_x += 1.0f;
if (virtKeys[VIRTKEY_AXIS_Y_MIN - VIRTKEY_FIRST])
leftstick_y -= 1.0f;
if (virtKeys[VIRTKEY_AXIS_Y_MAX - VIRTKEY_FIRST])
leftstick_y += 1.0f;
__CtrlSetRapidFire(virtKeys[VIRTKEY_RAPID_FIRE - VIRTKEY_FIRST]);
// First translate touches into native pad input.
@ -327,6 +401,13 @@ void EmuScreen::update(InputState &input) {
rightstick_x += fakeInputState.pad_rstick_x;
rightstick_y += fakeInputState.pad_rstick_y;
if (g_Config.bShowAnalogStick) {
__CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT);
__CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT);
}
__CtrlSetAnalogX(clamp1(rightstick_x), CTRL_STICK_RIGHT);
__CtrlSetAnalogY(clamp1(rightstick_y), CTRL_STICK_RIGHT);
// Also send the special buttons to input, since that's where they're handled.
input.pad_buttons_down |= fakeInputState.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB | PAD_BUTTON_LEFT_THUMB);
input.pad_buttons_up |= fakeInputState.pad_buttons_up & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB | PAD_BUTTON_LEFT_THUMB);
@ -343,14 +424,9 @@ void EmuScreen::update(InputState &input) {
if (g_Config.bAccelerometerToAnalogHoriz) {
// TODO: Deadzone, etc.
leftstick_x += clamp1(curve1(input.acc.y) * 2.0f);
leftstick_x = clamp1(leftstick_x);
__CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT);
}
__CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT);
__CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT);
__CtrlSetAnalogX(clamp1(rightstick_x), CTRL_STICK_RIGHT);
__CtrlSetAnalogY(clamp1(rightstick_y), CTRL_STICK_RIGHT);
// Make sure fpsLimit starts at 0
if (PSP_CoreParameter().fpsLimit != 0 && PSP_CoreParameter().fpsLimit != 1 && PSP_CoreParameter().fpsLimit != 2) {
PSP_CoreParameter().fpsLimit = 0;

View File

@ -40,6 +40,7 @@ public:
virtual void axis(const AxisInput &axis);
private:
void pspKey(int pspKeyCode, int flags);
void onVKeyDown(int virtualKeyCode);
void onVKeyUp(int virtualKeyCode);
@ -50,9 +51,6 @@ private:
// For the virtual touch buttons, that currently can't send key events.
InputState fakeInputState;
// Analog is still buffered.
struct {float x, y;} analog_[2];
// To track mappable virtual keys. We can have as many as we want.
bool virtKeys[VIRTKEY_COUNT];
};

View File

@ -690,6 +690,22 @@ void KeyMappingNewKeyDialog::key(const KeyInput &key) {
if (key.flags & KEY_DOWN) {
last_kb_deviceid = key.deviceId;
last_kb_key = key.keyCode;
last_axis_id = -1;
}
}
void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (axis.value > AXIS_BIND_THRESHOLD) {
last_axis_deviceid = axis.deviceId;
last_axis_id = axis.axisId;
last_axis_direction = 1;
last_kb_key = 0;
}
if (axis.value < -AXIS_BIND_THRESHOLD) {
last_axis_deviceid = axis.deviceId;
last_axis_id = axis.axisId;
last_axis_direction = -1;
last_kb_key = 0;
}
}
@ -1474,34 +1490,6 @@ void ControlsScreen::render() {
UICheckBox(GEN_ID, x, y += stride, c->T("Tilt", "Tilt to Analog (horizontal)"), ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz);
if (g_Config.bShowTouchControls) {
UICheckBox(GEN_ID, x, y += stride, c->T("Show Left Analog Stick"), ALIGN_TOPLEFT, &g_Config.bShowAnalogStick);
bool rightstick = g_Config.iRightStickBind > 0;
UICheckBox(GEN_ID, x, y += stride, c->T("Bind Right Analog Stick"), ALIGN_TOPLEFT, &rightstick);
if (rightstick) {
if (g_Config.iRightStickBind <= 0 )
g_Config.iRightStickBind = 1;
char showType[256];
std::string type;
switch (g_Config.iRightStickBind) {
case 1: type = "Arrow Buttons";break;
case 2: type = "Face Buttons";break;
case 3: type = "L/R";break;
case 4: type = "L/R + Triangle/Cross";break;
}
sprintf(showType, "%s %s", c->T("Target :"), type.c_str());
ui_draw2d.DrawText(UBUNTU24, showType, x + 60, (y += stride) , 0xFFFFFFFF, ALIGN_LEFT);
HLinear hlinear1(x + 60 , y+= stride + 5, 10);
if (UIButton(GEN_ID, hlinear1, 200, 0, c->T("Arrow Buttons"), ALIGN_LEFT))
g_Config.iRightStickBind = 1;
if (UIButton(GEN_ID, hlinear1, 200, 0, c->T("Face Buttons"), ALIGN_LEFT))
g_Config.iRightStickBind = 2;
if (UIButton(GEN_ID, hlinear1, 60, 0, c->T("L/R"), ALIGN_LEFT))
g_Config.iRightStickBind = 3;
if (UIButton(GEN_ID, hlinear1, 280, 0, c->T("L/R + Triangle/Cross"), ALIGN_LEFT))
g_Config.iRightStickBind = 4;
y += 20;
} else
g_Config.iRightStickBind = 0;
UICheckBox(GEN_ID, x, y += stride, c->T("Buttons Scaling"), ALIGN_TOPLEFT, &g_Config.bLargeControls);
if (g_Config.bLargeControls) {
@ -1681,16 +1669,29 @@ void KeyMappingNewKeyDialog::render() {
KeyScale(1.4f);
KeyText(right, top, keyI18N->T("New Key"));
KeyScale(2.0f);
if (last_kb_key != 0) {
if (last_axis_id != -1) {
const std::string axis_direction_name = KeyMap::GetAxisName(last_axis_id) + (last_axis_direction < 0 ? "-" : "+");
KeyText(right, top += stride, axis_direction_name.c_str());
KeyScale(1.4f);
KeyText(right, top + stride, GetDeviceName(last_axis_deviceid));
bool key_used = KeyMap::IsMappedAxis(last_axis_deviceid, last_axis_id, last_axis_direction);
if (key_used) {
KeyScale(1.0f);
KeyText(left + stride, top + 2*stride,
keyI18N->T("Warning: Key is already used by"));
KeyText(left + stride, top + 3*stride,
(KeyMap::NamePspButtonFromAxis(last_axis_deviceid, last_axis_id, last_axis_direction)).c_str());
}
} else if (last_kb_key != 0) {
KeyText(right, top += stride, KeyMap::GetKeyName(last_kb_key).c_str());
KeyScale(1.4f);
KeyText(right, top + stride, GetDeviceName(last_kb_deviceid));
bool key_used = KeyMap::IsMappedKey(last_kb_deviceid, last_kb_key);
if (key_used) {
KeyScale(1.0f);
KeyText(left + stride, top + 2*stride,
keyI18N->T("Warning: Key is already used by"));
KeyText(left + stride, top + 3*stride,
KeyText(left + stride, top + 2*stride,
keyI18N->T("Warning: Key is already used by"));
KeyText(left + stride, top + 3*stride,
(KeyMap::NamePspButtonFromKey(last_kb_deviceid, last_kb_key)).c_str());
}
}
@ -1701,7 +1702,10 @@ void KeyMappingNewKeyDialog::render() {
// Save & cancel buttons
if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) {
KeyMap::SetKeyMapping(currentMap_, last_kb_deviceid, last_kb_key, pspBtn);
if (last_axis_id != -1)
KeyMap::SetAxisMapping(currentMap_, last_axis_deviceid, last_axis_id, last_axis_direction, pspBtn);
else
KeyMap::SetKeyMapping(currentMap_, last_kb_deviceid, last_kb_key, pspBtn);
g_Config.Save();
screenManager()->finishDialog(this, DR_OK);
}

View File

@ -150,16 +150,22 @@ public:
pspBtn = btn;
last_kb_deviceid = 0;
last_kb_key = 0;
last_axis_deviceid = 0;
last_axis_id = -1;
currentMap_ = currentMap;
}
void update(InputState &input);
void render();
void key(const KeyInput &key);
void axis(const AxisInput &axis);
private:
int pspBtn;
int last_kb_deviceid;
int last_kb_key;
int last_axis_deviceid;
int last_axis_id;
int last_axis_direction;
int currentMap_;
};

View File

@ -36,27 +36,25 @@
// In order from 0. There can be 128, but most controllers do not have that many.
static const int dinput_buttons[] = {
KEYCODE_BUTTON_Y,
KEYCODE_BUTTON_A,
KEYCODE_BUTTON_B,
KEYCODE_BUTTON_X,
KEYCODE_BUTTON_L2,
KEYCODE_BUTTON_R2,
KEYCODE_BUTTON_L1,
KEYCODE_BUTTON_R1,
KEYCODE_BUTTON_SELECT,
KEYCODE_BUTTON_START,
KEYCODE_BUTTON_THUMBL,
KEYCODE_BUTTON_THUMBR,
KEYCODE_BUTTON_Z,
KEYCODE_BUTTON_1,
KEYCODE_BUTTON_2,
KEYCODE_BUTTON_3,
KEYCODE_BUTTON_4,
KEYCODE_BUTTON_5,
KEYCODE_BUTTON_6,
KEYCODE_BUTTON_7,
KEYCODE_BUTTON_8,
KEYCODE_BUTTON_9,
KEYCODE_BUTTON_10,
KEYCODE_BUTTON_11,
KEYCODE_BUTTON_12,
KEYCODE_BUTTON_13,
KEYCODE_BUTTON_14,
KEYCODE_BUTTON_15,
KEYCODE_BUTTON_16,
};
struct Stick {
float x;
float y;
};
static Stick NormalizedDeadzoneFilter(short x, short y);
static float NormalizedDeadzoneFilter(short value);
#define DIFF (JOY_POVRIGHT - JOY_POVFORWARD) / 2
#define JOY_POVFORWARD_RIGHT JOY_POVFORWARD + DIFF
@ -87,6 +85,12 @@ DinputDevice::DinputDevice() {
pDI = NULL;
memset(lastButtons_, 0, sizeof(lastButtons_));
memset(lastPOV_, 0, sizeof(lastPOV_));
last_lX_ = 0;
last_lY_ = 0;
last_lZ_ = 0;
last_lRx_ = 0;
last_lRy_ = 0;
last_lRz_ = 0;
if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL)))
return;
@ -148,6 +152,19 @@ DinputDevice::~DinputDevice() {
}
}
void SendNativeAxis(int deviceId, short value, short &lastValue, int axisId) {
if (value == lastValue)
return;
AxisInput axis;
axis.deviceId = deviceId;
axis.axisId = axisId;
axis.value = NormalizedDeadzoneFilter(value);
NativeAxis(axis);
lastValue = value;
}
int DinputDevice::UpdateState(InputState &input_state) {
if (!pJoystick) return -1;
@ -164,47 +181,27 @@ int DinputDevice::UpdateState(InputState &input_state) {
ApplyButtons(js, input_state);
if (analog) {
Stick left = NormalizedDeadzoneFilter(js.lX, js.lY);
Stick right = NormalizedDeadzoneFilter(js.lZ, js.lRz);
input_state.pad_lstick_x += left.x;
input_state.pad_lstick_y += left.y;
input_state.pad_rstick_x += right.x;
input_state.pad_rstick_y += right.y;
AxisInput axis;
axis.deviceId = DEVICE_ID_PAD_0;
axis.axisId = JOYSTICK_AXIS_X;
axis.value = left.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Y;
axis.value = left.y;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Z;
axis.value = right.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_RZ;
axis.value = right.y;
NativeAxis(axis);
SendNativeAxis(DEVICE_ID_PAD_0, js.lX, last_lX_, JOYSTICK_AXIS_X);
SendNativeAxis(DEVICE_ID_PAD_0, js.lY, last_lY_, JOYSTICK_AXIS_Y);
SendNativeAxis(DEVICE_ID_PAD_0, js.lZ, last_lZ_, JOYSTICK_AXIS_Z);
SendNativeAxis(DEVICE_ID_PAD_0, js.lRx, last_lRx_, JOYSTICK_AXIS_RX);
SendNativeAxis(DEVICE_ID_PAD_0, js.lRy, last_lRy_, JOYSTICK_AXIS_RY);
SendNativeAxis(DEVICE_ID_PAD_0, js.lRz, last_lRz_, JOYSTICK_AXIS_RZ);
}
return UPDATESTATE_SKIP_PAD;
}
static Stick NormalizedDeadzoneFilter(short x, short y) {
Stick s;
s.x = (float)x / 10000.f;
s.y = -((float)y / 10000.f);
static float NormalizedDeadzoneFilter(short value) {
float result = (float)value / 10000.0f;
// Expand and clamp. Hack to let us reach the corners on most pads.
s.x = std::min(1.0f, std::max(-1.0f, s.x * 1.2f));
s.y = std::min(1.0f, std::max(-1.0f, s.y * 1.2f));
// Expand and clamp. Hack to let us reach the corners on most pads.
result = std::min(1.0f, std::max(result * 1.2f, -1.0f));
return s;
return result;
}
void DinputDevice::ApplyButtons(DIJOYSTATE2 &state, InputState &input_state) {
@ -261,206 +258,5 @@ void DinputDevice::ApplyButtons(DIJOYSTATE2 &state, InputState &input_state) {
lastPOV_[0] = LOWORD(state.rgdwPOV[0]);
}
// TODO: Remove this once proper analog stick
// binding is implemented.
const LONG rthreshold = 8000;
KeyInput RAS;
RAS.deviceId = DEVICE_ID_PAD_0;
switch (g_Config.iRightStickBind) {
case 0:
break;
case 1:
if(!g_Config.iSwapRightAxes) {
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_RIGHT;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_LEFT;
NativeKey(RAS);
}
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_DOWN;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_UP;
NativeKey(RAS);
}
}
else {
if (state.lX > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_RIGHT;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_LEFT;
NativeKey(RAS);
}
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_UP;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_DOWN;
NativeKey(RAS);
}
}
break;
case 2:
if(!g_Config.iSwapRightAxes) {
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_B;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_X;
NativeKey(RAS);
}
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_Y;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_A;
NativeKey(RAS);
}
}
else {
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_B;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_X;
NativeKey(RAS);
}
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_Y;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = RAS.keyCode = KEYCODE_BUTTON_A;
NativeKey(RAS);
}
}
break;
case 3:
if(!g_Config.iSwapRightAxes) {
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_R1;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_L1;
NativeKey(RAS);
}
}
else {
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_R1;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_L1;
NativeKey(RAS);
}
}
break;
case 4:
if(!g_Config.iSwapRightAxes) {
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_R1;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_L1;
NativeKey(RAS);
}
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_Y;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_A;
NativeKey(RAS);
}
}
else {
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_R1;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_L1;
NativeKey(RAS);
}
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_BUTTON_Y;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = RAS.keyCode = KEYCODE_BUTTON_A;
NativeKey(RAS);
}
}
break;
case 5:
if(!g_Config.iSwapRightAxes) {
if (state.lRz > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_RIGHT;
NativeKey(RAS);
}
else if (state.lRz < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_LEFT;
NativeKey(RAS);
}
}
else {
if (state.lZ > rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_LEFT;
NativeKey(RAS);
}
else if (state.lZ < -rthreshold) {
RAS.flags = KEY_DOWN;
RAS.keyCode = KEYCODE_DPAD_RIGHT;
NativeKey(RAS);
}
}
break;
}
}

View File

@ -37,4 +37,10 @@ private:
bool analog;
BYTE lastButtons_[128];
WORD lastPOV_[4];
short last_lX_;
short last_lY_;
short last_lZ_;
short last_lRx_;
short last_lRy_;
short last_lRz_;
};

View File

@ -66,35 +66,36 @@ int XinputDevice::UpdateState(InputState &input_state) {
if ( dwResult == ERROR_SUCCESS ) {
ApplyButtons(state, input_state);
Stick left = NormalizedDeadzoneFilter(state.Gamepad.sThumbLX, state.Gamepad.sThumbLY);
Stick right = NormalizedDeadzoneFilter(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY);
input_state.pad_lstick_x += left.x;
input_state.pad_lstick_y += left.y;
input_state.pad_rstick_x += right.x;
input_state.pad_rstick_y += right.y;
// Also convert the analog triggers.
input_state.pad_ltrigger = state.Gamepad.bLeftTrigger / 255.0f;
input_state.pad_rtrigger = state.Gamepad.bRightTrigger / 255.0f;
if (prevState.Gamepad.sThumbLX != state.Gamepad.sThumbLX || prevState.Gamepad.sThumbLY != state.Gamepad.sThumbLY) {
Stick left = NormalizedDeadzoneFilter(state.Gamepad.sThumbLX, state.Gamepad.sThumbLY);
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0;
axis.axisId = JOYSTICK_AXIS_X;
axis.value = left.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Y;
axis.value = left.y;
NativeAxis(axis);
}
if (prevState.Gamepad.sThumbRX != state.Gamepad.sThumbRX || prevState.Gamepad.sThumbRY != state.Gamepad.sThumbRY) {
Stick right = NormalizedDeadzoneFilter(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY);
AxisInput axis;
axis.deviceId = DEVICE_ID_X360_0;
axis.axisId = JOYSTICK_AXIS_Z;
axis.value = right.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_RZ;
axis.value = right.y;
NativeAxis(axis);
}
this->prevState = state;
this->check_delay = 0;
AxisInput axis;
axis.deviceId = DEVICE_ID_KEYBOARD;
axis.axisId = JOYSTICK_AXIS_X;
axis.value = left.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Y;
axis.value = left.y;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Z;
axis.value = right.x;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_RZ;
axis.value = right.y;
NativeAxis(axis);
// If there's an XInput pad, skip following pads. This prevents DInput and XInput
// from colliding.
return UPDATESTATE_SKIP_PAD;
@ -112,7 +113,6 @@ inline float Clampf(float val, float min, float max) {
return val;
}
// We only filter the left stick since PSP has no analog triggers or right stick
static Stick NormalizedDeadzoneFilter(short x, short y) {
static const float DEADZONE = (float)XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32767.0f;
Stick s;
@ -139,46 +139,12 @@ static Stick NormalizedDeadzoneFilter(short x, short y) {
void XinputDevice::ApplyButtons(XINPUT_STATE &state, InputState &input_state) {
u32 buttons = state.Gamepad.wButtons;
// Simulate some extra buttons from axes. This should be done elsewhere really.
if (state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
buttons |= XBOX_CODE_LEFTTRIGGER;
if (state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
buttons |= XBOX_CODE_RIGHTTRIGGER;
const SHORT rthreshold = 22000;
switch (g_Config.iRightStickBind) {
case 0:
break;
case 1:
if (state.Gamepad.sThumbRX > rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_RIGHT;
else if (state.Gamepad.sThumbRX < -rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_LEFT;
if (state.Gamepad.sThumbRY > rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_UP;
else if (state.Gamepad.sThumbRY < -rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_DOWN;
break;
case 2:
if (state.Gamepad.sThumbRX > rthreshold) buttons |= XINPUT_GAMEPAD_B;
else if (state.Gamepad.sThumbRX < -rthreshold) buttons |= XINPUT_GAMEPAD_X;
if (state.Gamepad.sThumbRY > rthreshold) buttons |= XINPUT_GAMEPAD_Y;
else if (state.Gamepad.sThumbRY < -rthreshold) buttons |= XINPUT_GAMEPAD_A;
break;
case 3:
if (state.Gamepad.sThumbRX > rthreshold) buttons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
else if (state.Gamepad.sThumbRX < -rthreshold) buttons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
break;
case 4:
if (state.Gamepad.sThumbRX > rthreshold) buttons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
else if (state.Gamepad.sThumbRX < -rthreshold) buttons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
if (state.Gamepad.sThumbRY > rthreshold) buttons |= XINPUT_GAMEPAD_Y;
else if (state.Gamepad.sThumbRY < -rthreshold) buttons |= XINPUT_GAMEPAD_A;
break;
case 5:
if (state.Gamepad.sThumbRX > rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_RIGHT;
else if (state.Gamepad.sThumbRX < -rthreshold) buttons |= XINPUT_GAMEPAD_DPAD_LEFT;
break;
}
u32 downMask = buttons & (~prevButtons);
u32 upMask = (~buttons) & prevButtons;
prevButtons = buttons;