diff --git a/sc2/src/sc2code/libs/input/sdl/keynames.c b/sc2/src/sc2code/libs/input/sdl/keynames.c index d99d4bcd6..4acf56e67 100644 --- a/sc2/src/sc2code/libs/input/sdl/keynames.c +++ b/sc2/src/sc2code/libs/input/sdl/keynames.c @@ -16,7 +16,7 @@ * specially, and we cannot treat them as normal keys. Pain, * tragedy. */ -typedef struct _keyname { +typedef struct vcontrol_keyname { /* const */ char *name; int code; } keyname; diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.c b/sc2/src/sc2code/libs/input/sdl/vcontrol.c index b4c4e4aef..4169d441d 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.c +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.c @@ -10,29 +10,29 @@ /* How many binding slots are allocated at once. */ #define POOL_CHUNK_SIZE 64 -typedef struct _vcontrol_keybinding { +typedef struct vcontrol_keybinding { int *target; - struct _vcontrol_keypool *parent; - struct _vcontrol_keybinding *next; + struct vcontrol_keypool *parent; + struct vcontrol_keybinding *next; } keybinding; -typedef struct _vcontrol_keypool { +typedef struct vcontrol_keypool { keybinding pool[POOL_CHUNK_SIZE]; int remaining; - struct _vcontrol_keypool *next; + struct vcontrol_keypool *next; } keypool; -typedef struct _vcontrol_joystick_axis { +typedef struct vcontrol_joystick_axis { keybinding *neg, *pos; int polarity; } axis_type; -typedef struct _vcontrol_joystick_hat { +typedef struct vcontrol_joystick_hat { keybinding *left, *right, *up, *down; Uint8 last; } hat_type; -typedef struct _vcontrol_joystick { +typedef struct vcontrol_joystick { SDL_Joystick *stick; int numaxes, numbuttons, numhats; int threshold; @@ -52,8 +52,17 @@ static VControl_NameBinding *nametable; static int version, errors, validlines; +/* Iterator temp variables */ + +static int *iter_target; +static int iter_device, iter_index; + +/* Last interesting event */ +static int event_ready; +static SDL_Event last_interesting; + static keypool * -_allocate_key_chunk (void) +allocate_key_chunk (void) { keypool *x = vctrl_malloc (sizeof (keypool)); if (x) @@ -72,17 +81,17 @@ _allocate_key_chunk (void) } static void -_free_key_pool (keypool *x) +free_key_pool (keypool *x) { if (x) { - _free_key_pool (x->next); + free_key_pool (x->next); vctrl_free (x); } } static void -_create_joystick (int index) +create_joystick (int index) { SDL_Joystick *stick; int axes, buttons, hats; @@ -135,7 +144,7 @@ _create_joystick (int index) } static void -_destroy_joystick (int index) +destroy_joystick (int index) { SDL_Joystick *stick = joysticks[index].stick; if (stick) @@ -153,10 +162,10 @@ _destroy_joystick (int index) } static void -_key_init (void) +key_init (void) { int i; - pool = _allocate_key_chunk (); + pool = allocate_key_chunk (); for (i = 0; i < SDLK_LAST; i++) bindings[i] = NULL; /* Prepare for possible joystick controls. We don't actually @@ -181,26 +190,26 @@ _key_init (void) } static void -_key_uninit (void) +key_uninit (void) { int i; - _free_key_pool (pool); + free_key_pool (pool); for (i = 0; i < SDLK_LAST; i++) bindings[i] = NULL; pool = NULL; for (i = 0; i < joycount; i++) - _destroy_joystick (i); + destroy_joystick (i); vctrl_free (joysticks); } static void -_name_init (void) +name_init (void) { nametable = NULL; } static void -_name_uninit (void) +name_uninit (void) { nametable = NULL; } @@ -208,15 +217,15 @@ _name_uninit (void) void VControl_Init (void) { - _key_init (); - _name_init (); + key_init (); + name_init (); } void VControl_Uninit (void) { - _key_uninit (); - _name_uninit (); + key_uninit (); + name_uninit (); } int @@ -236,7 +245,7 @@ VControl_SetJoyThreshold (int port, int threshold) static void -_add_binding (keybinding **newptr, int *target) +add_binding (keybinding **newptr, int *target) { keybinding *newbinding; keypool *searchbase; @@ -264,7 +273,7 @@ _add_binding (keybinding **newptr, int *target) /* If we're completely full, allocate a new chunk */ if (searchbase->next == NULL) { - searchbase->next = _allocate_key_chunk (); + searchbase->next = allocate_key_chunk (); } searchbase = searchbase->next; } @@ -284,7 +293,7 @@ _add_binding (keybinding **newptr, int *target) /* Sanity check. */ if (!newbinding) { - fprintf (stderr, "_add_binding failed to find a free binding slot!\n"); + fprintf (stderr, "add_binding failed to find a free binding slot!\n"); return; } @@ -295,7 +304,7 @@ _add_binding (keybinding **newptr, int *target) } static void -_remove_binding (keybinding **ptr, int *target) +remove_binding (keybinding **ptr, int *target) { if (!(*ptr)) { @@ -328,7 +337,7 @@ _remove_binding (keybinding **ptr, int *target) } static void -_activate (keybinding *i) +activate (keybinding *i) { while (i != NULL) { @@ -338,7 +347,7 @@ _activate (keybinding *i) } static void -_deactivate (keybinding *i) +deactivate (keybinding *i) { while (i != NULL) { @@ -406,7 +415,7 @@ VControl_AddKeyBinding (SDLKey symbol, int *target) fprintf (stderr, "VControl: Illegal key index %d\n", symbol); return -1; } - _add_binding(&bindings[symbol], target); + add_binding(&bindings[symbol], target); return 0; } @@ -417,7 +426,7 @@ VControl_RemoveKeyBinding (SDLKey symbol, int *target) fprintf (stderr, "VControl: Illegal key index %d\n", symbol); return; } - _remove_binding (&bindings[symbol], target); + remove_binding (&bindings[symbol], target); } int @@ -427,16 +436,16 @@ VControl_AddJoyAxisBinding (int port, int axis, int polarity, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((axis >= 0) && (axis < j->numaxes)) { if (polarity < 0) { - _add_binding(&joysticks[port].axes[axis].neg, target); + add_binding(&joysticks[port].axes[axis].neg, target); } else if (polarity > 0) { - _add_binding(&joysticks[port].axes[axis].pos, target); + add_binding(&joysticks[port].axes[axis].pos, target); } else { @@ -465,16 +474,16 @@ VControl_RemoveJoyAxisBinding (int port, int axis, int polarity, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((axis >= 0) && (axis < j->numaxes)) { if (polarity < 0) { - _remove_binding(&joysticks[port].axes[axis].neg, target); + remove_binding(&joysticks[port].axes[axis].neg, target); } else if (polarity > 0) { - _remove_binding(&joysticks[port].axes[axis].pos, target); + remove_binding(&joysticks[port].axes[axis].pos, target); } else { @@ -499,10 +508,10 @@ VControl_AddJoyButtonBinding (int port, int button, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((button >= 0) && (button < j->numbuttons)) { - _add_binding(&joysticks[port].buttons[button], target); + add_binding(&joysticks[port].buttons[button], target); return 0; } else @@ -525,10 +534,10 @@ VControl_RemoveJoyButtonBinding (int port, int button, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((button >= 0) && (button < j->numbuttons)) { - _remove_binding (&joysticks[port].buttons[button], target); + remove_binding (&joysticks[port].buttons[button], target); } else { @@ -548,24 +557,24 @@ VControl_AddJoyHatBinding (int port, int which, Uint8 dir, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((which >= 0) && (which < j->numhats)) { if (dir == SDL_HAT_LEFT) { - _add_binding(&joysticks[port].hats[which].left, target); + add_binding(&joysticks[port].hats[which].left, target); } else if (dir == SDL_HAT_RIGHT) { - _add_binding(&joysticks[port].hats[which].right, target); + add_binding(&joysticks[port].hats[which].right, target); } else if (dir == SDL_HAT_UP) { - _add_binding(&joysticks[port].hats[which].up, target); + add_binding(&joysticks[port].hats[which].up, target); } else if (dir == SDL_HAT_DOWN) { - _add_binding(&joysticks[port].hats[which].down, target); + add_binding(&joysticks[port].hats[which].down, target); } else { @@ -594,24 +603,24 @@ VControl_RemoveJoyHatBinding (int port, int which, Uint8 dir, int *target) { joystick *j = &joysticks[port]; if (!(j->stick)) - _create_joystick (port); + create_joystick (port); if ((which >= 0) && (which < j->numhats)) { if (dir == SDL_HAT_LEFT) { - _remove_binding(&joysticks[port].hats[which].left, target); + remove_binding(&joysticks[port].hats[which].left, target); } else if (dir == SDL_HAT_RIGHT) { - _remove_binding(&joysticks[port].hats[which].right, target); + remove_binding(&joysticks[port].hats[which].right, target); } else if (dir == SDL_HAT_UP) { - _remove_binding(&joysticks[port].hats[which].up, target); + remove_binding(&joysticks[port].hats[which].up, target); } else if (dir == SDL_HAT_DOWN) { - _remove_binding(&joysticks[port].hats[which].down, target); + remove_binding(&joysticks[port].hats[which].down, target); } else { @@ -632,20 +641,20 @@ VControl_RemoveJoyHatBinding (int port, int which, Uint8 dir, int *target) void VControl_RemoveAllBindings () { - _key_uninit (); - _key_init (); + key_uninit (); + key_init (); } void VControl_ProcessKeyDown (SDLKey symbol) { - _activate (bindings[symbol]); + activate (bindings[symbol]); } void VControl_ProcessKeyUp (SDLKey symbol) { - _deactivate (bindings[symbol]); + deactivate (bindings[symbol]); } void @@ -653,7 +662,7 @@ VControl_ProcessJoyButtonDown (int port, int button) { if (!joysticks[port].stick) return; - _activate (joysticks[port].buttons[button]); + activate (joysticks[port].buttons[button]); } void @@ -661,7 +670,7 @@ VControl_ProcessJoyButtonUp (int port, int button) { if (!joysticks[port].stick) return; - _deactivate (joysticks[port].buttons[button]); + deactivate (joysticks[port].buttons[button]); } void @@ -677,10 +686,10 @@ VControl_ProcessJoyAxis (int port, int axis, int value) { if (joysticks[port].axes[axis].polarity == -1) { - _deactivate (joysticks[port].axes[axis].neg); + deactivate (joysticks[port].axes[axis].neg); } joysticks[port].axes[axis].polarity = 1; - _activate (joysticks[port].axes[axis].pos); + activate (joysticks[port].axes[axis].pos); } } else if (value < -t) @@ -689,21 +698,21 @@ VControl_ProcessJoyAxis (int port, int axis, int value) { if (joysticks[port].axes[axis].polarity == 1) { - _deactivate (joysticks[port].axes[axis].pos); + deactivate (joysticks[port].axes[axis].pos); } joysticks[port].axes[axis].polarity = -1; - _activate (joysticks[port].axes[axis].neg); + activate (joysticks[port].axes[axis].neg); } } else { if (joysticks[port].axes[axis].polarity == -1) { - _deactivate (joysticks[port].axes[axis].neg); + deactivate (joysticks[port].axes[axis].neg); } else if (joysticks[port].axes[axis].polarity == 1) { - _deactivate (joysticks[port].axes[axis].pos); + deactivate (joysticks[port].axes[axis].pos); } joysticks[port].axes[axis].polarity = 0; } @@ -717,21 +726,21 @@ VControl_ProcessJoyHat (int port, int which, Uint8 value) return; old = joysticks[port].hats[which].last; if (!(old & SDL_HAT_LEFT) && (value & SDL_HAT_LEFT)) - _activate (joysticks[port].hats[which].left); + activate (joysticks[port].hats[which].left); if (!(old & SDL_HAT_RIGHT) && (value & SDL_HAT_RIGHT)) - _activate (joysticks[port].hats[which].right); + activate (joysticks[port].hats[which].right); if (!(old & SDL_HAT_UP) && (value & SDL_HAT_UP)) - _activate (joysticks[port].hats[which].up); + activate (joysticks[port].hats[which].up); if (!(old & SDL_HAT_DOWN) && (value & SDL_HAT_DOWN)) - _activate (joysticks[port].hats[which].down); + activate (joysticks[port].hats[which].down); if ((old & SDL_HAT_LEFT) && !(value & SDL_HAT_LEFT)) - _deactivate (joysticks[port].hats[which].left); + deactivate (joysticks[port].hats[which].left); if ((old & SDL_HAT_RIGHT) && !(value & SDL_HAT_RIGHT)) - _deactivate (joysticks[port].hats[which].right); + deactivate (joysticks[port].hats[which].right); if ((old & SDL_HAT_UP) && !(value & SDL_HAT_UP)) - _deactivate (joysticks[port].hats[which].up); + deactivate (joysticks[port].hats[which].up); if ((old & SDL_HAT_DOWN) && !(value & SDL_HAT_DOWN)) - _deactivate (joysticks[port].hats[which].down); + deactivate (joysticks[port].hats[which].down); joysticks[port].hats[which].last = value; } @@ -764,6 +773,8 @@ VControl_HandleEvent (const SDL_Event *e) { case SDL_KEYDOWN: VControl_ProcessKeyDown (e->key.keysym.sym); + last_interesting = *e; + event_ready = 1; break; case SDL_KEYUP: VControl_ProcessKeyUp (e->key.keysym.sym); @@ -773,9 +784,13 @@ VControl_HandleEvent (const SDL_Event *e) break; case SDL_JOYHATMOTION: VControl_ProcessJoyHat (e->jhat.which, e->jhat.hat, e->jhat.value); + last_interesting = *e; + event_ready = 1; break; case SDL_JOYBUTTONDOWN: VControl_ProcessJoyButtonDown (e->jbutton.which, e->jbutton.button); + last_interesting = *e; + event_ready = 1; break; case SDL_JOYBUTTONUP: VControl_ProcessJoyButtonUp (e->jbutton.which, e->jbutton.button); @@ -792,7 +807,7 @@ VControl_RegisterNameTable (VControl_NameBinding *table) } static char * -_target2name (int *target) +target2name (int *target) { VControl_NameBinding *b = nametable; while (b->target) @@ -807,7 +822,7 @@ _target2name (int *target) } static int * -_name2target (char *name) +name2target (char *name) { VControl_NameBinding *b = nametable; while (b->target) @@ -822,11 +837,11 @@ _name2target (char *name) } static void -_dump_keybindings (FILE *out, keybinding *kb, char *name) +dump_keybindings (FILE *out, keybinding *kb, char *name) { while (kb != NULL) { - char *targetname = _target2name (kb->target); + char *targetname = target2name (kb->target); fprintf (out, "%s: %s\n", targetname, name); kb = kb->next; } @@ -845,7 +860,7 @@ VControl_Dump (FILE *out) if (kb != NULL) { sprintf (namebuffer, "key %s", VControl_code2name (i)); - _dump_keybindings (out, kb, namebuffer); + dump_keybindings (out, kb, namebuffer); } } @@ -860,9 +875,9 @@ VControl_Dump (FILE *out) for (j = 0; j < joysticks[i].numaxes; j++) { sprintf (namebuffer, "joystick %d axis %d negative", i, j); - _dump_keybindings (out, joysticks[i].axes[j].neg, namebuffer); + dump_keybindings (out, joysticks[i].axes[j].neg, namebuffer); sprintf (namebuffer, "joystick %d axis %d positive", i, j); - _dump_keybindings (out, joysticks[i].axes[j].pos, namebuffer); + dump_keybindings (out, joysticks[i].axes[j].pos, namebuffer); } for (j = 0; j < joysticks[i].numbuttons; j++) { @@ -870,19 +885,19 @@ VControl_Dump (FILE *out) if (kb != NULL) { sprintf (namebuffer, "joystick %d button %d", i, j); - _dump_keybindings (out, kb, namebuffer); + dump_keybindings (out, kb, namebuffer); } } for (j = 0; j < joysticks[i].numhats; j++) { sprintf (namebuffer, "joystick %d hat %d left", i, j); - _dump_keybindings (out, joysticks[i].hats[j].left, namebuffer); + dump_keybindings (out, joysticks[i].hats[j].left, namebuffer); sprintf (namebuffer, "joystick %d hat %d right", i, j); - _dump_keybindings (out, joysticks[i].hats[j].right, namebuffer); + dump_keybindings (out, joysticks[i].hats[j].right, namebuffer); sprintf (namebuffer, "joystick %d hat %d up", i, j); - _dump_keybindings (out, joysticks[i].hats[j].up, namebuffer); + dump_keybindings (out, joysticks[i].hats[j].up, namebuffer); sprintf (namebuffer, "joystick %d hat %d down", i, j); - _dump_keybindings (out, joysticks[i].hats[j].down, namebuffer); + dump_keybindings (out, joysticks[i].hats[j].down, namebuffer); } } } @@ -903,6 +918,186 @@ VControl_Dump (FILE *out) #endif } +/* Iterator routines. iter_target holds the target keybinding. + iter_device is -1 for the keyboard, otherwise it is joystick + #(iter_device/3). (iter_device%3) gives whether we're checking the + joystick's axes (0), buttons (1), or hats (2). */ + +static int *iter_target; +static int iter_device, iter_index; + +void +VControl_StartIter (int *target) +{ + iter_target = target; + iter_device = -1; + iter_index = 0; +} + +void +VControl_StartIterByName (char *targetname) +{ + VControl_StartIter (name2target (targetname)); +} + +int +VControl_NextBindingName (char *buffer) +{ + if ((buffer == NULL) || (iter_target == NULL) + || iter_device >= (joycount * 3)) + return 0; + while (iter_device < (joycount * 3)) + { + if (iter_device == -1) /* keyboard */ + { + keybinding *kb = bindings[iter_index]; + int done = 0; + while (kb != NULL) + { + if (kb->target == iter_target) + { + strncpy (buffer, VControl_code2name (iter_index), 40); + buffer[39] = 0; + done = 1; + } + kb = kb->next; + } + if (++iter_index == SDLK_LAST) + { + iter_device = 0; + iter_index = 0; + } + if (done) return 1; + } + else + { + int i = iter_device / 3; + int t = iter_device % 3; + if (!joysticks[i].stick) /* Joystick wasn't opened; this binding is dead */ + { + iter_device++; + iter_index = 0; + } + else + { + int done = 0; + switch (t) + { + case 0: { /* Axes */ + int axis = iter_index / 2; + int dir = iter_index % 2; + if (axis >= joysticks[i].numaxes) + { + iter_device++; + iter_index = 0; + } + else + { + keybinding *kb = (dir) ? joysticks[i].axes[axis].pos : joysticks[i].axes[axis].neg; + while (kb != NULL) + { + if (kb->target == iter_target) + { + done = 1; + switch (iter_index) { + case 0: sprintf (buffer, "Joy%d left", i); break; + case 1: sprintf (buffer, "Joy%d right", i); break; + case 2: sprintf (buffer, "Joy%d up", i); break; + case 3: sprintf (buffer, "Joy%d down", i); break; + default: sprintf (buffer, "Joy%d A%d %s", i, axis, dir ? "high" : "low"); break; + } + } + kb = kb->next; + } + iter_index++; + } + break; + } + case 1: { /* Buttons */ + keybinding *kb = joysticks[i].buttons[iter_index]; + if (iter_index >= joysticks[i].numbuttons) + { + iter_device++; + iter_index = 0; + } + else + { + while (kb != NULL) + { + if (kb->target == iter_target) + { + done = 1; + sprintf (buffer, "Joy%d B%d", i, iter_index); + } + kb = kb->next; + } + iter_index++; + } + break; + } + case 2: { /* Hats */ + int hat = iter_index / 4; + int hatd = iter_index % 4; + if (hat >= joysticks[i].numhats) + { + iter_device++; + iter_index = 0; + } + else + { + keybinding *kb; + switch (hatd) + { + case 0: kb = joysticks[i].hats[hat].left; break; + case 1: kb = joysticks[i].hats[hat].right; break; + case 2: kb = joysticks[i].hats[hat].up; break; + default: kb = joysticks[i].hats[hat].down; break; + } + while (kb != NULL) + { + if (kb->target == iter_target) + { + done = 1; + switch (hatd) + { + case 0: sprintf (buffer, "Joy%d hat%d left", i, hat); break; + case 1: sprintf (buffer, "Joy%d hat%d right", i, hat); break; + case 2: sprintf (buffer, "Joy%d hat%d up", i, hat); break; + default: sprintf (buffer, "Joy%d hat%d down", i, hat); break; + } + } + kb = kb->next; + } + iter_index++; + } + break; + } + } + if (done) return 1; + } + } + } + return 0; +} + +/* Tracking the last interesting event */ + +void +VControl_ClearEvent (void) +{ + event_ready = 0; +} + +int +VControl_GetLastEvent (SDL_Event *e) +{ + if (event_ready && e != NULL) + { + *e = last_interesting; + } + return event_ready; +} + /* Configuration file grammar is as follows: One command per line, * hashes introduce comments that persist to end of line. Blank lines * are ignored. @@ -943,7 +1138,7 @@ VControl_Dump (FILE *out) #define LINE_SIZE 256 #define TOKEN_SIZE 64 -typedef struct _vcontrol_parse_state { +typedef struct vcontrol_parse_state { char line[LINE_SIZE]; char token[TOKEN_SIZE]; int index; @@ -952,7 +1147,7 @@ typedef struct _vcontrol_parse_state { } parse_state; static void -_next_token (parse_state *state) +next_token (parse_state *state) { int index, base; @@ -982,7 +1177,7 @@ _next_token (parse_state *state) } static void -_next_line (parse_state *state, uio_Stream *in) +next_line (parse_state *state, uio_Stream *in) { int i, ch = 0; state->linenum++; @@ -1019,24 +1214,24 @@ _next_line (parse_state *state, uio_Stream *in) } static void -_expected_error (parse_state *state, char *expected) +expected_error (parse_state *state, char *expected) { fprintf (stderr, "VControl: Expected '%s' on config file line %d\n", expected, state->linenum); state->error = 1; } static void -_consume (parse_state *state, char *expected) +consume (parse_state *state, char *expected) { if (stricmp (expected, state->token)) { - _expected_error (state, expected); + expected_error (state, expected); } - _next_token (state); + next_token (state); } static int -_consume_keyname (parse_state *state) +consume_keyname (parse_state *state) { int keysym = VControl_name2code (state->token); if (!keysym) @@ -1044,12 +1239,12 @@ _consume_keyname (parse_state *state) fprintf (stderr, "VControl: Illegal key name '%s' on config file line %d\n", state->token, state->linenum); state->error = 1; } - _next_token (state); + next_token (state); return keysym; } static int * -_consume_idname (parse_state *state) +consume_idname (parse_state *state) { int *result = NULL; int index = 0; @@ -1060,7 +1255,7 @@ _consume_idname (parse_state *state) if (index == 0) { - fprintf (stderr, "VControl: Can't happen: blank token to _consume_idname (line %d)\n", state->linenum); + fprintf (stderr, "VControl: Can't happen: blank token to consume_idname (line %d)\n", state->linenum); state->error = 1; return NULL; } @@ -1068,25 +1263,25 @@ _consume_idname (parse_state *state) index--; if (state->token[index] != ':') { - _expected_error (state, ":"); + expected_error (state, ":"); return NULL; } state->token[index] = 0; /* remove trailing colon */ - result = _name2target (state->token); + result = name2target (state->token); if (!result) { fprintf (stderr, "VControl: Illegal command type '%s' on config file line %d\n", state->token, state->linenum); state->error = 1; } - _next_token (state); + next_token (state); return result; } static int -_consume_num (parse_state *state) +consume_num (parse_state *state) { char *end; int result = strtol (state->token, &end, 10); @@ -1095,12 +1290,12 @@ _consume_num (parse_state *state) fprintf (stderr, "VControl: Expected integer on config line %d\n", state->linenum); state->error = 1; } - _next_token (state); + next_token (state); return result; } static int -_consume_polarity (parse_state *state) +consume_polarity (parse_state *state) { int result = 0; if (!stricmp (state->token, "positive")) @@ -1113,14 +1308,14 @@ _consume_polarity (parse_state *state) } else { - _expected_error (state, "positive' or 'negative"); + expected_error (state, "positive' or 'negative"); } - _next_token (state); + next_token (state); return result; } static Uint8 -_consume_dir (parse_state *state) +consume_dir (parse_state *state) { Uint8 result = 0; if (!stricmp (state->token, "left")) @@ -1141,28 +1336,28 @@ _consume_dir (parse_state *state) } else { - _expected_error (state, "left', 'right', 'up' or 'down"); + expected_error (state, "left', 'right', 'up' or 'down"); } - _next_token (state); + next_token (state); return result; } static void -_parse_joybinding (parse_state *state, int *target) +parse_joybinding (parse_state *state, int *target) { int sticknum; - _consume (state, "joystick"); - sticknum = _consume_num (state); + consume (state, "joystick"); + sticknum = consume_num (state); if (!state->error) { if (!stricmp (state->token, "axis")) { int axisnum; - _consume (state, "axis"); - axisnum = _consume_num (state); + consume (state, "axis"); + axisnum = consume_num (state); if (!state->error) { - int polarity = _consume_polarity (state); + int polarity = consume_polarity (state); if (!state->error) { if (VControl_AddJoyAxisBinding (sticknum, axisnum, polarity, target)) @@ -1175,8 +1370,8 @@ _parse_joybinding (parse_state *state, int *target) else if (!stricmp (state->token, "button")) { int buttonnum; - _consume (state, "button"); - buttonnum = _consume_num (state); + consume (state, "button"); + buttonnum = consume_num (state); if (!state->error) { if (VControl_AddJoyButtonBinding (sticknum, buttonnum, target)) @@ -1188,11 +1383,11 @@ _parse_joybinding (parse_state *state, int *target) else if (!stricmp (state->token, "hat")) { int hatnum; - _consume (state, "hat"); - hatnum = _consume_num (state); + consume (state, "hat"); + hatnum = consume_num (state); if (!state->error) { - Uint8 dir = _consume_dir (state); + Uint8 dir = consume_dir (state); if (!state->error) { if (VControl_AddJoyHatBinding (sticknum, hatnum, dir, target)) @@ -1204,23 +1399,23 @@ _parse_joybinding (parse_state *state, int *target) } else { - _expected_error (state, "axis', 'button', or 'hat"); + expected_error (state, "axis', 'button', or 'hat"); } } } static void -_parse_binding (parse_state *state) +parse_binding (parse_state *state) { - int *target = _consume_idname (state); + int *target = consume_idname (state); if (!state->error) { if (!stricmp (state->token, "key")) { /* Parse key binding */ int keysym; - _consume (state, "key"); - keysym = _consume_keyname (state); + consume (state, "key"); + keysym = consume_keyname (state); if (!state->error) { if (VControl_AddKeyBinding (keysym, target)) @@ -1231,20 +1426,20 @@ _parse_binding (parse_state *state) } else if (!stricmp (state->token, "joystick")) { - _parse_joybinding (state, target); + parse_joybinding (state, target); } else { - _expected_error (state, "key' or 'joystick"); + expected_error (state, "key' or 'joystick"); } } } static void -_parse_config_line (parse_state *state) +parse_config_line (parse_state *state) { state->error = 0; - _next_token (state); + next_token (state); if (!state->token[0]) { /* Blank line, skip it */ @@ -1253,10 +1448,10 @@ _parse_config_line (parse_state *state) if (!stricmp (state->token, "joystick")) { int sticknum, threshold = 0; - _consume (state, "joystick"); - sticknum = _consume_num (state); - if (!state->error) _consume (state, "threshold"); - if (!state->error) threshold = _consume_num (state); + consume (state, "joystick"); + sticknum = consume_num (state); + if (!state->error) consume (state, "threshold"); + if (!state->error) threshold = consume_num (state); if (!state->error) { if (VControl_SetJoyThreshold (sticknum, threshold)) @@ -1272,8 +1467,8 @@ _parse_config_line (parse_state *state) } if (!stricmp (state->token, "version")) { - _consume (state, "version"); - version = _consume_num (state); + consume (state, "version"); + version = consume_num (state); if (!state->error) { validlines++; @@ -1281,7 +1476,7 @@ _parse_config_line (parse_state *state) return; } /* Otherwise, it must be a binding */ - _parse_binding (state); + parse_binding (state); if (!state->error) { validlines++; @@ -1301,10 +1496,10 @@ VControl_ReadConfiguration (uio_Stream *in) errors = version = validlines = 0; while (1) { - _next_line (&ps, in); + next_line (&ps, in); if (!ps.line[0]) break; - _parse_config_line (&ps); + parse_config_line (&ps); if (ps.error) { errors++; diff --git a/sc2/src/sc2code/libs/input/sdl/vcontrol.h b/sc2/src/sc2code/libs/input/sdl/vcontrol.h index 1fe212a91..07a8bd0f3 100644 --- a/sc2/src/sc2code/libs/input/sdl/vcontrol.h +++ b/sc2/src/sc2code/libs/input/sdl/vcontrol.h @@ -43,7 +43,7 @@ void VControl_ResetInput (void); * Only one name table may be registered at a time; subsequent calls * replace the previous values. */ -typedef struct _vcontrol_namebinding { +typedef struct vcontrol_namebinding { char *name; int *target; } VControl_NameBinding; @@ -61,4 +61,18 @@ int VControl_ReadConfiguration (uio_Stream *in); int VControl_GetErrorCount (void); int VControl_GetValidCount (void); +/* Iterator control. Start an iteration with StartIter or + StartIterByName; then call NextBindingName with a char array of at + least 40 bytes in size until it returns 0. Produces names. */ + +void VControl_StartIter (int *target); +void VControl_StartIterByName (char *targetname); +int VControl_NextBindingName (char *buffer); + +/* Tracking the "last interesting event." Used to poll to find new + control keys. */ + +void VControl_ClearEvent (void); +int VControl_GetLastEvent (SDL_Event *e); + #endif