Mercurial > repos > blastem
comparison render_sdl.c @ 1623:18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 24 Oct 2018 21:10:12 -0700 |
parents | 419a0a133b5c |
children | c4ba3177b72d |
comparison
equal
deleted
inserted
replaced
1622:4bb2c8b78b4a | 1623:18a946ec74c8 |
---|---|
1643 return; | 1643 return; |
1644 } | 1644 } |
1645 } | 1645 } |
1646 } | 1646 } |
1647 | 1647 |
1648 int render_lookup_button(char *name) | |
1649 { | |
1650 static tern_node *button_lookup; | |
1651 if (!button_lookup) { | |
1652 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) | |
1653 { | |
1654 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); | |
1655 } | |
1656 //alternative Playstation-style names | |
1657 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); | |
1658 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); | |
1659 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); | |
1660 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); | |
1661 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); | |
1662 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); | |
1663 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); | |
1664 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); | |
1665 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); | |
1666 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); | |
1667 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); | |
1668 } | |
1669 return (int)tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); | |
1670 } | |
1671 | |
1672 int render_lookup_axis(char *name) | |
1673 { | |
1674 static tern_node *axis_lookup; | |
1675 if (!axis_lookup) { | |
1676 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) | |
1677 { | |
1678 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); | |
1679 } | |
1680 //alternative Playstation-style names | |
1681 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); | |
1682 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); | |
1683 } | |
1684 return (int)tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); | |
1685 } | |
1686 | |
1648 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) | 1687 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) |
1649 { | 1688 { |
1650 static tern_node *button_lookup, *axis_lookup; | 1689 tern_node *button_lookup, *axis_lookup; |
1651 if (controller > MAX_JOYSTICKS || !joysticks[controller]) { | 1690 if (controller > MAX_JOYSTICKS || !joysticks[controller]) { |
1652 return RENDER_NOT_PLUGGED_IN; | 1691 return RENDER_NOT_PLUGGED_IN; |
1653 } | 1692 } |
1654 | 1693 |
1655 if (!SDL_IsGameController(joystick_sdl_index[controller])) { | 1694 if (!SDL_IsGameController(joystick_sdl_index[controller])) { |
1661 return RENDER_NOT_PLUGGED_IN; | 1700 return RENDER_NOT_PLUGGED_IN; |
1662 } | 1701 } |
1663 | 1702 |
1664 SDL_GameControllerButtonBind cbind; | 1703 SDL_GameControllerButtonBind cbind; |
1665 if (is_axis) { | 1704 if (is_axis) { |
1666 if (!axis_lookup) { | 1705 |
1667 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) | 1706 int sdl_axis = render_lookup_axis(name); |
1668 { | |
1669 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); | |
1670 } | |
1671 //alternative Playstation-style names | |
1672 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); | |
1673 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); | |
1674 } | |
1675 intptr_t sdl_axis = tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); | |
1676 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { | 1707 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { |
1677 SDL_GameControllerClose(control); | 1708 SDL_GameControllerClose(control); |
1678 return RENDER_INVALID_NAME; | 1709 return RENDER_INVALID_NAME; |
1679 } | 1710 } |
1680 cbind = SDL_GameControllerGetBindForAxis(control, sdl_axis); | 1711 cbind = SDL_GameControllerGetBindForAxis(control, sdl_axis); |
1681 } else { | 1712 } else { |
1682 if (!button_lookup) { | 1713 int sdl_button = render_lookup_button(name); |
1683 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) | |
1684 { | |
1685 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); | |
1686 } | |
1687 //alternative Playstation-style names | |
1688 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); | |
1689 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); | |
1690 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); | |
1691 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); | |
1692 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); | |
1693 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); | |
1694 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); | |
1695 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); | |
1696 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); | |
1697 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); | |
1698 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); | |
1699 } | |
1700 intptr_t sdl_button = tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); | |
1701 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { | 1714 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { |
1702 SDL_GameControllerClose(control); | 1715 SDL_GameControllerClose(control); |
1703 return RENDER_INVALID_NAME; | 1716 return RENDER_INVALID_NAME; |
1704 } | 1717 } |
1705 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); | 1718 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); |