Incompatible changes are tracked in the keys.cfg file now

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1102 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2003-08-20 17:28:29 +00:00
parent 8c1d2a017e
commit ed8d195bd0
5 changed files with 197 additions and 42 deletions
+1
View File
@@ -1,4 +1,5 @@
Changes towards version 0.3:
- Version checks inside the input code to flag incompatible changes --Michael
- Install location for content on unix systems is now ${prefix}/share/uqm
instead of ${prefix}/lib/uqm - SvdB
- New main menu graphics from MarkVera, Paxtez, Nic (bug #393)
+7 -2
View File
@@ -1,5 +1,8 @@
# Default UQM input configuration file.
# This is a VCONTROL version 1 config file (UQM 0.3 or later).
version 1
# Keyboard control definitions follow this point. Most keys can be
# described in a straightforward manner; consult the name table in
# src/sc2code/libs/input/sdl/keynames.c for the names of unusual keys.
@@ -86,10 +89,12 @@ Exit: key F10
Abort: key F12
# This is a sample joystick configuration. This is intended to work
# primarily under WinXP with a USB analag/digital gamepad. The
# primarily under WinXP with a USB analog/digital gamepad. The
# digital aspect of the gamepad happens to present itself to the
# system as a POV hat. This configuration allows either the digital
# or analog stick to be used simultaneously.
# or analog stick to be used simultaneously. More importantly, it
# gives us a chance to give examples for all of the various input types
# that UQM can handle.
# joystick 0 threshold 10000 # How far to move before it counts; 0-30000
# Menu-Left: joystick 0 axis 0 negative
+24 -13
View File
@@ -37,6 +37,8 @@ UWORD UNICODEToKBD (UNICODE which_key);
static BOOLEAN _in_character_mode = FALSE;
#define VCONTROL_VERSION 1
static VControl_NameBinding control_names[] = {
{ "Menu-Up", (int *)&ImmediateMenuState.up },
{ "Menu-Down", (int *)&ImmediateMenuState.down },
@@ -97,31 +99,40 @@ initKeyConfig(void) {
}
errors = VControl_ReadConfiguration (fp);
res_CloseResFile (fp);
if (errors)
if (errors || (VControl_GetConfigFileVersion () != VCONTROL_VERSION))
{
fprintf (stderr, "%d errors encountered in key configuration "
"file.\n", errors);
/* This code should go away in 0.3; it's just
fprintf (stderr, "%d errors encountered in key configuration file.\n", errors);
/* This code should go away in 0.4; it's just
* to force people to upgrade and forestall a
* bunch of "none of my keys work anymore" bugs.
*/
if (errors > 5)
if (VControl_GetValidCount () == 0)
{
fprintf (stderr, "Hey! you haven't updated your keys.cfg to "
"use the new system, have you?\nDelete keys.cfg and "
"try again.\n");
fprintf (stderr, "If you've done that and it STILL doesn't "
"work, make sure your content/starcon.key is up to"
"date.\n");
fprintf (stderr, "\nI didn't understand a single line in your configuration file.\n");
fprintf (stderr, "This is likely because you're still using a 0.2 era or earlier keys.cfg.\n");
fprintf (stderr, "Please delete your keys.cfg file and try again.\n");
fprintf (stderr, "That will give you a new template to edit.\n\n");
fprintf (stderr, "If you've done that and it STILL doesn't work, make sure you've\n");
fprintf (stderr, "properly updated your content, too.\n");
}
else
{
fprintf (stderr, "Repair your keys.cfg file to continue.\n");
if (VControl_GetConfigFileVersion () != VCONTROL_VERSION)
{
fprintf (stderr, "\nThe control scheme for UQM has changed since you last updated keys.cfg.\n");
fprintf (stderr, "(I'm using control scheme version %d, while your config file appears to be\nfor version %d.)\n", VCONTROL_VERSION, VControl_GetConfigFileVersion ());
fprintf (stderr, "You should delete your keys.cfg file and rerun UQM to get a new template to\nedit.\n\n");
fprintf (stderr, "If you've done that and it STILL doesn't work, make sure you've\n");
fprintf (stderr, "properly updated your content, too.\n");
}
else
{
fprintf (stderr, "\nRepair your keys.cfg file to continue.\n");
}
}
exit (1);
}
}
int
+150 -18
View File
@@ -48,6 +48,10 @@ static int joycount;
static keypool *pool;
static VControl_NameBinding *nametable;
/* Statistics variables - set by VControl_ReadConfiguration */
static int version, errors, validlines;
static keypool *
_allocate_key_chunk (void)
{
@@ -215,16 +219,18 @@ VControl_Uninit (void)
_name_uninit ();
}
void
int
VControl_SetJoyThreshold (int port, int threshold)
{
if (port >= 0 && port < joycount)
{
joysticks[port].threshold = threshold;
return 0;
}
else
{
fprintf (stderr, "VControl_SetJoyThreshold passed illegal port %d\n", port);
return -1;
}
}
@@ -278,7 +284,7 @@ _add_binding (keybinding **newptr, int *target)
/* Sanity check. */
if (!newbinding)
{
fprintf (stderr, "VControl_AddKeyBinding failed to find a free binding slot!\n");
fprintf (stderr, "_add_binding failed to find a free binding slot!\n");
return;
}
@@ -344,19 +350,77 @@ _deactivate (keybinding *i)
}
}
void
VControl_AddKeyBinding (int symbol, int *target)
int
VControl_AddBinding (SDL_Event *e, int *target)
{
_add_binding(&bindings[symbol], target);
int result;
switch (e->type)
{
case SDL_KEYDOWN:
result = VControl_AddKeyBinding (e->key.keysym.sym, target);
break;
case SDL_JOYAXISMOTION:
result = VControl_AddJoyAxisBinding (e->jaxis.which, e->jaxis.axis, (e->jaxis.value < 0) ? -1 : 1, target);
break;
case SDL_JOYHATMOTION:
result = VControl_AddJoyHatBinding (e->jhat.which, e->jhat.hat, e->jhat.value, target);
break;
case SDL_JOYBUTTONDOWN:
result = VControl_AddJoyButtonBinding (e->jbutton.which, e->jbutton.button, target);
break;
default:
fprintf (stderr, "VControl_AddBinding didn't understand argument event\n");
result = -1;
break;
}
return result;
}
void
VControl_RemoveKeyBinding (int symbol, int *target)
VControl_RemoveBinding (SDL_Event *e, int *target)
{
switch (e->type)
{
case SDL_KEYDOWN:
VControl_RemoveKeyBinding (e->key.keysym.sym, target);
break;
case SDL_JOYAXISMOTION:
VControl_RemoveJoyAxisBinding (e->jaxis.which, e->jaxis.axis, (e->jaxis.value < 0) ? -1 : 1, target);
break;
case SDL_JOYHATMOTION:
VControl_RemoveJoyHatBinding (e->jhat.which, e->jhat.hat, e->jhat.value, target);
break;
case SDL_JOYBUTTONDOWN:
VControl_RemoveJoyButtonBinding (e->jbutton.which, e->jbutton.button, target);
break;
default:
fprintf (stderr, "VControl_RemoveBinding didn't understand argument event\n");
break;
}
}
int
VControl_AddKeyBinding (SDLKey symbol, int *target)
{
if ((symbol < 0) || (symbol >= SDLK_LAST)) {
fprintf (stderr, "VControl: Illegal key index %d\n", symbol);
return -1;
}
_add_binding(&bindings[symbol], target);
return 0;
}
void
VControl_RemoveKeyBinding (SDLKey symbol, int *target)
{
if ((symbol < 0) || (symbol >= SDLK_LAST)) {
fprintf (stderr, "VControl: Illegal key index %d\n", symbol);
return;
}
_remove_binding (&bindings[symbol], target);
}
void
int
VControl_AddJoyAxisBinding (int port, int axis, int polarity, int *target)
{
if (port >= 0 && port < joycount)
@@ -377,17 +441,21 @@ VControl_AddJoyAxisBinding (int port, int axis, int polarity, int *target)
else
{
fprintf (stderr, "VControl: Attempted to bind to polarity zero\n");
return -1;
}
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal axis %d\n", axis);
return -1;
}
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal port %d\n", port);
return -1;
}
return 0;
}
void
@@ -424,7 +492,7 @@ VControl_RemoveJoyAxisBinding (int port, int axis, int polarity, int *target)
}
}
void
int
VControl_AddJoyButtonBinding (int port, int button, int *target)
{
if (port >= 0 && port < joycount)
@@ -435,15 +503,18 @@ VControl_AddJoyButtonBinding (int port, int button, int *target)
if ((button >= 0) && (button < j->numbuttons))
{
_add_binding(&joysticks[port].buttons[button], target);
return 0;
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal button %d\n", button);
return -1;
}
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal port %d\n", port);
return -1;
}
}
@@ -470,7 +541,7 @@ VControl_RemoveJoyButtonBinding (int port, int button, int *target)
}
}
void
int
VControl_AddJoyHatBinding (int port, int which, Uint8 dir, int *target)
{
if (port >= 0 && port < joycount)
@@ -499,16 +570,20 @@ VControl_AddJoyHatBinding (int port, int which, Uint8 dir, int *target)
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal direction\n");
return -1;
}
return 0;
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal hat %d\n", which);
return -1;
}
}
else
{
fprintf (stderr, "VControl: Attempted to bind to illegal port %d\n", port);
return -1;
}
}
@@ -562,13 +637,13 @@ VControl_RemoveAllBindings ()
}
void
VControl_ProcessKeyDown (int symbol)
VControl_ProcessKeyDown (SDLKey symbol)
{
_activate (bindings[symbol]);
}
void
VControl_ProcessKeyUp (int symbol)
VControl_ProcessKeyUp (SDLKey symbol)
{
_deactivate (bindings[symbol]);
}
@@ -847,6 +922,7 @@ VControl_Dump (FILE *out)
*
* configline <- IDNAME binding
* | "joystick" NUM "threshold" NUM
* | "version" NUM
*
* binding <- "key" KEYNAME
* | "joystick" NUM joybinding
@@ -1089,7 +1165,10 @@ _parse_joybinding (parse_state *state, int *target)
int polarity = _consume_polarity (state);
if (!state->error)
{
VControl_AddJoyAxisBinding (sticknum, axisnum, polarity, target);
if (VControl_AddJoyAxisBinding (sticknum, axisnum, polarity, target))
{
state->error = 1;
}
}
}
}
@@ -1100,7 +1179,10 @@ _parse_joybinding (parse_state *state, int *target)
buttonnum = _consume_num (state);
if (!state->error)
{
VControl_AddJoyButtonBinding (sticknum, buttonnum, target);
if (VControl_AddJoyButtonBinding (sticknum, buttonnum, target))
{
state->error = 1;
}
}
}
else if (!stricmp (state->token, "hat"))
@@ -1113,7 +1195,10 @@ _parse_joybinding (parse_state *state, int *target)
Uint8 dir = _consume_dir (state);
if (!state->error)
{
VControl_AddJoyHatBinding (sticknum, hatnum, dir, target);
if (VControl_AddJoyHatBinding (sticknum, hatnum, dir, target))
{
state->error = 1;
}
}
}
}
@@ -1138,7 +1223,10 @@ _parse_binding (parse_state *state)
keysym = _consume_keyname (state);
if (!state->error)
{
VControl_AddKeyBinding (keysym, target);
if (VControl_AddKeyBinding (keysym, target))
{
state->error = 1;
}
}
}
else if (!stricmp (state->token, "joystick"))
@@ -1171,26 +1259,46 @@ _parse_config_line (parse_state *state)
if (!state->error) threshold = _consume_num (state);
if (!state->error)
{
VControl_SetJoyThreshold (sticknum, threshold);
if (VControl_SetJoyThreshold (sticknum, threshold))
{
state->error = 1;
}
}
if (!state->error)
{
validlines++;
}
return;
}
if (!stricmp (state->token, "version"))
{
_consume (state, "version");
version = _consume_num (state);
if (!state->error)
{
validlines++;
}
return;
}
/* Otherwise, it must be a binding */
_parse_binding (state);
if (!state->error)
{
validlines++;
}
}
int
VControl_ReadConfiguration (uio_Stream *in)
{
parse_state ps;
int errors;
if (!in)
{
fprintf (stderr, "VControl: Invalid configuration file stream\n");
return 1;
}
ps.linenum = 0;
errors = 0;
errors = version = validlines = 0;
while (1)
{
_next_line (&ps, in);
@@ -1205,6 +1313,30 @@ VControl_ReadConfiguration (uio_Stream *in)
return errors;
}
int
VControl_GetErrorCount (void)
{
return errors;
}
int
VControl_GetValidCount (void)
{
return validlines;
}
int
VControl_GetConfigFileVersion (void)
{
return version;
}
void
VControl_SetConfigFileVersion (int v)
{
version = v;
}
#if 0
/* This was kinda handy for proving (lack of) buffer overrun
* vulnerabilities, but there's no real need for it otherwise. */
+14 -8
View File
@@ -11,14 +11,14 @@ void VControl_Init (void);
void VControl_Uninit (void);
/* Control of bindings */
void VControl_AddKeyBinding (int symbol, int *target);
void VControl_RemoveKeyBinding (int symbol, int *target);
void VControl_AddJoyAxisBinding (int port, int axis, int polarity, int *target);
int VControl_AddKeyBinding (SDLKey symbol, int *target);
void VControl_RemoveKeyBinding (SDLKey symbol, int *target);
int VControl_AddJoyAxisBinding (int port, int axis, int polarity, int *target);
void VControl_RemoveJoyAxisBinding (int port, int axis, int polarity, int *target);
void VControl_SetJoyThreshold (int port, int threshold);
void VControl_AddJoyButtonBinding (int port, int button, int *target);
int VControl_SetJoyThreshold (int port, int threshold);
int VControl_AddJoyButtonBinding (int port, int button, int *target);
void VControl_RemoveJoyButtonBinding (int port, int button, int *target);
void VControl_AddJoyHatBinding (int port, int which, Uint8 dir, int *target);
int VControl_AddJoyHatBinding (int port, int which, Uint8 dir, int *target);
void VControl_RemoveJoyHatBinding (int port, int which, Uint8 dir, int *target);
void VControl_RemoveAllBindings (void);
@@ -27,8 +27,8 @@ void VControl_RemoveAllBindings (void);
* fabricating an SDL_Event.
*/
void VControl_HandleEvent (const SDL_Event *e);
void VControl_ProcessKeyDown (int symbol);
void VControl_ProcessKeyUp (int symbol);
void VControl_ProcessKeyDown (SDLKey symbol);
void VControl_ProcessKeyUp (SDLKey symbol);
void VControl_ProcessJoyButtonDown (int port, int button);
void VControl_ProcessJoyButtonUp (int port, int button);
void VControl_ProcessJoyAxis (int port, int axis, int value);
@@ -50,9 +50,15 @@ typedef struct _vcontrol_namebinding {
void VControl_RegisterNameTable (VControl_NameBinding *table);
/* Version number control */
int VControl_GetConfigFileVersion (void);
void VControl_SetConfigFileVersion (int v);
/* Dump a configuration file corresponding to the current bindings and names. */
void VControl_Dump (FILE *out);
/* Read a configuration file. Returns number of errors encountered. */
int VControl_ReadConfiguration (uio_Stream *in);
int VControl_GetErrorCount (void);
int VControl_GetValidCount (void);
#endif