From 051fb92e83fa25c44eb1c67c2d1f39d26df181fb Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 23 Jul 2019 18:27:16 +0200 Subject: [PATCH] (Dinput joypad) Cleanup magic numbers mess surrounding hat code --- input/drivers_joypad/dinput_joypad.c | 50 ++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 01d6362b2f..ab197427b8 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -443,20 +443,44 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) pov = pad->joy_state.rgdwPOV[hat]; - /* Magic numbers I'm not sure where originate from. */ - if (pov < 36000) + switch (hat_dir) { - switch (hat_dir) - { - case HAT_UP_MASK: - return (pov >= 31500) || (pov <= 4500); - case HAT_RIGHT_MASK: - return (pov >= 4500) && (pov <= 13500); - case HAT_DOWN_MASK: - return (pov >= 13500) && (pov <= 22500); - case HAT_LEFT_MASK: - return (pov >= 22500) && (pov <= 31500); - } + case HAT_UP_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); + return + (pov == JOY_POVFORWARD) || + (pov == check1) || + (pov == check2); + } + case HAT_RIGHT_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVRIGHT+JOY_POVRIGHT/2); + return + (pov == JOY_POVRIGHT) || + (pov == check1) || + (pov == check2); + } + case HAT_DOWN_MASK: + { + static const unsigned check1 = (JOY_POVRIGHT+JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); + return + (pov == JOY_POVBACKWARD) || + (pov == check1) || + (pov == check2); + } + case HAT_LEFT_MASK: + { + static const unsigned check1 = (JOY_POVBACKWARD+JOY_POVRIGHT/2); + static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2); + return + (pov == JOY_POVLEFT) || + (pov == check1) || + (pov == check2); + } } return false;