Simplify button_is_pressed

This commit is contained in:
twinaphex 2021-04-10 18:44:10 +02:00
parent 372f939cc9
commit 760fc6b3f7

View File

@ -24999,16 +24999,23 @@ int16_t button_is_pressed(
unsigned port, unsigned id)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
const uint64_t bind_joykey = binds[id].joykey;
const uint64_t bind_joyaxis = binds[id].joyaxis;
const uint64_t autobind_joykey = joypad_info->auto_binds[id].joykey;
const uint64_t autobind_joyaxis= joypad_info->auto_binds[id].joyaxis;
uint16_t joy_idx = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if ((uint16_t)joykey != NO_BTN && joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
joy_idx, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis))
/ 0x8000) > joypad_info->axis_threshold)
((float)abs(joypad->axis(joy_idx, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
return 0;
}