diff --git a/include/QF/joystick.h b/include/QF/joystick.h index b44a58476..bc9d7f68f 100644 --- a/include/QF/joystick.h +++ b/include/QF/joystick.h @@ -49,14 +49,24 @@ typedef enum { js_button, // axis button } js_dest_t; +typedef enum { + js_amp, + js_pre_amp, + js_deadzone, + js_offset, + js_type, + js_axis_button, +} js_opt_t; + struct joy_axis { - int current; - float amp; - float pre_amp; - float offset; + int current; + float amp; + float pre_amp; + int deadzone; + float offset; js_dest_t dest; - int axis; // if linear delta - int num_buttons; // if axis button + int axis; // if linear delta + int num_buttons; // if axis button struct joy_axis_button *axis_buttons; // if axis button }; @@ -130,4 +140,11 @@ void JOY_Close (void); */ void JOY_Read (void); + +const char * JOY_GetOption_c (int i); +int JOY_GetOption_i (const char *c); + +const char * JOY_GetDest_c (int i); +int JOY_GetDest_i (const char *c); + #endif // __QF_joystick_h_ diff --git a/libs/video/targets/joy.c b/libs/video/targets/joy.c index 9ffa7ad6a..aafc46beb 100644 --- a/libs/video/targets/joy.c +++ b/libs/video/targets/joy.c @@ -37,8 +37,10 @@ #include "QF/mathlib.h" #include "QF/sys.h" #include "QF/va.h" +#include "QF/cmd.h" #include "compat.h" +#include cvar_t *joy_device; // Joystick device name cvar_t *joy_enable; // Joystick enabling flag @@ -123,7 +125,10 @@ JOY_Move (void) for (i = 0; i < JOY_MAX_AXES; i++) { ja = &joy_axes[i]; - value = amp * ja->amp * (ja->offset + ja->current * pre * ja->pre_amp); + if (abs(ja->offset) + abs(ja->current) < abs(ja->offset) + abs(ja->deadzone)) + ja->current = -ja->offset; + + value = amp * ja->amp * (ja->offset + ja->current * pre * ja->pre_amp) / 120.0f; switch (ja->dest) { case js_none: // ignore axis @@ -179,6 +184,122 @@ joyamp_f (cvar_t *var) Cvar_Set (var, va ("%g", max (0.0001, var->value))); } +typedef struct { + const char *name; + js_dest_t destnum; +} js_dests_t; + +typedef struct { + const char *name; + js_dest_t optnum; +} js_opts_t; + +js_dests_t js_dests[] = { + {"none", js_none}, // ignore axis + {"movement", js_position}, // linear delta + {"aim", js_angles}, // linear delta + {"button", js_button}, // axis button +}; + + +js_opts_t js_opts[] = { + {"amp", js_amp}, + {"pre_amp", js_pre_amp}, + {"deadzone",js_deadzone}, + {"offset", js_offset}, + {"type", js_type}, + {"button", js_axis_button}, +}; + +const char * +JOY_GetOption_c (int i) +{ + js_opts_t *opt; + for (opt=&js_opts[0]; opt->name; opt++) { + if ((int)opt->optnum == i) + return opt->name; + } + + return NULL; +} + +int +JOY_GetOption_i (const char *c) +{ + js_opts_t *opt; + for (opt=&js_opts[0]; opt->name; opt++) { + if (!strcmp(opt->name, c)) + return opt->optnum; + } + + return -1; //Failure code; +} + +const char * +JOY_GetDest_c (int i) +{ + js_dests_t *dest; + for (dest=&js_dests[0]; dest->name; dest++) { + if ((int)dest->destnum == i) + return dest->name; + } + + return NULL; +} + +int +JOY_GetDest_i (const char *c) +{ + js_dests_t *dest; + for (dest=&js_dests[0]; dest->name; dest++) { + if (!strcmp(dest->name, c)) + return dest->destnum; + } + + return -1; //Failure code; +} + +static void +in_joy_f (void) +{ + int i, ax, c = Cmd_Argc(); + + if (c < 3) { + Sys_Printf ("in_joy [ ]* : Configures the joystick behaviour\n"); + } + + ax = strtol(Cmd_Argv(1), NULL ,0); + + i = 2; + while(i