Mercurial > repos > blastem
comparison bindings.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 |
---|---|
855 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION); | 855 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION); |
856 } | 856 } |
857 return mousebuttons; | 857 return mousebuttons; |
858 } | 858 } |
859 | 859 |
860 tern_node *get_binding_node_for_pad(int padnum) | |
861 { | |
862 if (padnum > MAX_JOYSTICKS) { | |
863 return NULL; | |
864 } | |
865 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; | |
866 if (!pads) { | |
867 return NULL; | |
868 } | |
869 char numstr[11]; | |
870 sprintf(numstr, "%d", padnum); | |
871 tern_node * pad = tern_find_node(pads, numstr); | |
872 if (!pad) { | |
873 char *type_id = render_joystick_type_id(padnum); | |
874 pad = tern_find_node(pads, type_id); | |
875 free(type_id); | |
876 } | |
877 if (!pad) { | |
878 controller_info info = get_controller_info(padnum); | |
879 char *key = make_controller_type_key(&info); | |
880 pad = tern_find_node(pads, key); | |
881 free(key); | |
882 } | |
883 if (!pad) { | |
884 pad = tern_find_node(pads, "default"); | |
885 } | |
886 return pad; | |
887 } | |
888 | |
860 void handle_joy_added(int joystick) | 889 void handle_joy_added(int joystick) |
861 { | 890 { |
862 if (joystick > MAX_JOYSTICKS) { | 891 tern_node *pad = get_binding_node_for_pad(joystick); |
863 return; | 892 if (!pad) { |
864 } | 893 return; |
865 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; | 894 } |
866 if (pads) { | 895 tern_node * dpad_node = tern_find_node(pad, "dpads"); |
867 char numstr[11]; | 896 if (dpad_node) { |
868 sprintf(numstr, "%d", joystick); | 897 for (int dpad = 0; dpad < 10; dpad++) |
869 tern_node * pad = tern_find_node(pads, numstr); | 898 { |
870 if (!pad) { | 899 char numstr[2] = {dpad + '0', 0}; |
871 char *type_id = render_joystick_type_id(joystick); | 900 tern_node * pad_dpad = tern_find_node(dpad_node, numstr); |
872 pad = tern_find_node(pads, type_id); | 901 char * dirs[] = {"up", "down", "left", "right"}; |
873 free(type_id); | 902 //TODO: Support controllers that have d-pads implemented as analog axes or buttons |
874 } | 903 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; |
875 if (!pad) { | 904 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { |
876 controller_info info = get_controller_info(joystick); | 905 char * target = tern_find_ptr(pad_dpad, dirs[dir]); |
877 char *key = make_controller_type_key(&info); | 906 if (target) { |
878 pad = tern_find_node(pads, key); | 907 uint8_t subtype_a = 0, subtype_b = 0; |
879 free(key); | 908 int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b); |
880 } | 909 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b); |
881 if (!pad) { | |
882 pad = tern_find_node(pads, "default"); | |
883 } | |
884 if (pad) { | |
885 tern_node * dpad_node = tern_find_node(pad, "dpads"); | |
886 if (dpad_node) { | |
887 for (int dpad = 0; dpad < 10; dpad++) | |
888 { | |
889 numstr[0] = dpad + '0'; | |
890 numstr[1] = 0; | |
891 tern_node * pad_dpad = tern_find_node(dpad_node, numstr); | |
892 char * dirs[] = {"up", "down", "left", "right"}; | |
893 //TODO: Support controllers that have d-pads implemented as analog axes or buttons | |
894 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; | |
895 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { | |
896 char * target = tern_find_ptr(pad_dpad, dirs[dir]); | |
897 if (target) { | |
898 uint8_t subtype_a = 0, subtype_b = 0; | |
899 int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b); | |
900 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b); | |
901 } | |
902 } | |
903 } | 910 } |
904 } | 911 } |
905 tern_node *button_node = tern_find_node(pad, "buttons"); | 912 } |
906 if (button_node) { | 913 } |
907 pad_button_state state = { | 914 tern_node *button_node = tern_find_node(pad, "buttons"); |
908 .padnum = joystick, | 915 if (button_node) { |
909 .padbuttons = get_pad_buttons(), | 916 pad_button_state state = { |
910 .mousebuttons = get_mouse_buttons() | 917 .padnum = joystick, |
911 }; | 918 .padbuttons = get_pad_buttons(), |
912 tern_foreach(button_node, process_pad_button, &state); | 919 .mousebuttons = get_mouse_buttons() |
913 } | 920 }; |
914 tern_node *axes_node = tern_find_node(pad, "axes"); | 921 tern_foreach(button_node, process_pad_button, &state); |
915 if (axes_node) { | 922 } |
916 pad_button_state state = { | 923 tern_node *axes_node = tern_find_node(pad, "axes"); |
917 .padnum = joystick, | 924 if (axes_node) { |
918 .padbuttons = get_pad_buttons(), | 925 pad_button_state state = { |
919 .mousebuttons = get_mouse_buttons() | 926 .padnum = joystick, |
920 }; | 927 .padbuttons = get_pad_buttons(), |
921 tern_foreach(axes_node, process_pad_axis, &state); | 928 .mousebuttons = get_mouse_buttons() |
922 } | 929 }; |
923 } | 930 tern_foreach(axes_node, process_pad_axis, &state); |
924 } | 931 } |
925 | |
926 } | 932 } |
927 | 933 |
928 //only handles keyboards and mice as gamepads are handled on hotplug events | 934 //only handles keyboards and mice as gamepads are handled on hotplug events |
929 void set_bindings(void) | 935 void set_bindings(void) |
930 { | 936 { |