+/*
+===========
+ IN_JoystickGetAxisNum
+===========
+*/
+
+int IN_JoystickGetAxisNum(int ControlListType)
+{
+ int i;
+
+ for (i = 0; i < JOY_MAX_AXES; i++)
+ if (dwAxisMap[i] == (DWORD) ControlListType)
+ return i;
+ return -1;
+}
+
+/*
+===========
+ IN_JoystickGetAxis
+===========
+*/
+static double IN_JoystickGetAxis(int axis, double sensitivity, double deadzone)
+{
+ float fAxisValue, fTemp;
+
+ if (!joy_avail || axis < 0 || axis >= JOY_MAX_AXES)
+ return 0; // no such axis on this joystick
+
+ // get the floating point zero-centered, potentially-inverted data for the current axis
+ fAxisValue = (float) *pdwRawValue[axis];
+
+ // move centerpoint to zero
+ fAxisValue -= 32768.0;
+
+ if (joy_wwhack2.integer != 0.0)
+ {
+ if (dwAxisMap[axis] == AxisTurn)
+ {
+ // this is a special formula for the Logitech WingMan Warrior
+ // y=ax^b; where a = 300 and b = 1.3
+ // also x values are in increments of 800 (so this is factored out)
+ // then bounds check result to level out excessively high spin rates
+ fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
+ if (fTemp > 14000.0)
+ fTemp = 14000.0;
+ // restore direction information
+ fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
+ }
+ }
+
+ // convert range from -32768..32767 to -1..1
+ fAxisValue /= 32768.0;
+
+ // deadzone around center
+ if (fabs(fAxisValue) < deadzone)
+ return 0;
+
+ // apply sensitivity
+ return fAxisValue * sensitivity;
+}
+
+/*
+===========
+ IN_JoystickKeyeventForAxis
+===========
+*/
+
+static void IN_JoystickKeyeventForAxis(int axis, int key_pos, int key_neg)
+{
+ double joytime;
+
+ if (axis < 0 || axis >= JOY_MAX_AXES)
+ return; // no such axis on this joystick
+
+ joytime = Sys_DoubleTime();
+ // no key event, continuous keydown event
+ if (joy_axescache[axis].move == joy_axescache[axis].oldmove)
+ {
+ if (joy_axescache[axis].move != 0 && joytime > joy_axescache[axis].keytime)
+ {
+ //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time);
+ Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1);
+ joy_axescache[axis].keytime = joytime + 0.5 / 20;
+ }
+ return;
+ }
+ // generate key up event
+ if (joy_axescache[axis].oldmove)
+ {
+ //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg), 1, cl.time);
+ Key_Event((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg, 0, 0);
+ }
+ // generate key down event
+ if (joy_axescache[axis].move)
+ {
+ //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time);
+ Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1);
+ joy_axescache[axis].keytime = joytime + 0.5;
+ }
+}
+
+/*
+===========
+ IN_JoystickBlockDoubledKeyEvents
+===========
+*/
+
+static qboolean IN_ReadJoystick (void);
+static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode)
+{
+ int axis;
+
+ if (!joy_axiskeyevents.integer)
+ return false;
+
+ // block keyevent if it's going to be provided by joystick keyevent system
+ if (joy_avail)
+ {
+ // collect the joystick data, if possible
+ if (IN_ReadJoystick() != true)
+ return false;
+ axis = IN_JoystickGetAxisNum(AxisForward);
+ if (keycode == K_UPARROW || keycode == K_DOWNARROW)
+ if (IN_JoystickGetAxis(axis, 1, 0.01) || joy_axescache[axis].move || joy_axescache[axis].oldmove)
+ return true;
+ axis = IN_JoystickGetAxisNum(AxisSide);
+ if (keycode == K_RIGHTARROW || keycode == K_LEFTARROW)
+ if (IN_JoystickGetAxis(axis, 1, 0.01) || joy_axescache[axis].move || joy_axescache[axis].oldmove)
+ return true;
+ }
+
+ return false;
+}