(Dinput joypad) Cleanup magic numbers mess surrounding

hat code
This commit is contained in:
twinaphex 2019-07-23 18:27:16 +02:00
parent 0893d6b7b1
commit 051fb92e83
1 changed files with 37 additions and 13 deletions

View File

@ -443,20 +443,44 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey)
pov = pad->joy_state.rgdwPOV[hat]; pov = pad->joy_state.rgdwPOV[hat];
/* Magic numbers I'm not sure where originate from. */ switch (hat_dir)
if (pov < 36000)
{ {
switch (hat_dir) case HAT_UP_MASK:
{ {
case HAT_UP_MASK: static const unsigned check1 = (JOY_POVRIGHT/2);
return (pov >= 31500) || (pov <= 4500); static const unsigned check2 = (JOY_POVLEFT+JOY_POVRIGHT/2);
case HAT_RIGHT_MASK: return
return (pov >= 4500) && (pov <= 13500); (pov == JOY_POVFORWARD) ||
case HAT_DOWN_MASK: (pov == check1) ||
return (pov >= 13500) && (pov <= 22500); (pov == check2);
case HAT_LEFT_MASK: }
return (pov >= 22500) && (pov <= 31500); 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; return false;