+
+ // collect the joystick data, if possible
+ if (IN_ReadJoystick () != true)
+ {
+ return;
+ }
+
+ if (in_speed.state & 1)
+ speed = cl_movespeedkey.value;
+ else
+ speed = 1;
+ // LordHavoc: viewzoom affects sensitivity for sniping
+ aspeed = speed * host_realframetime * cl.viewzoom;
+
+ // loop through the axes
+ for (i = 0; i < JOY_MAX_AXES; i++)
+ {
+ // get the floating point zero-centered, potentially-inverted data for the current axis
+ fAxisValue = (float) *pdwRawValue[i];
+ // move centerpoint to zero
+ fAxisValue -= 32768.0;
+
+ if (joy_wwhack2.integer != 0.0)
+ {
+ if (dwAxisMap[i] == 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;
+
+ switch (dwAxisMap[i])
+ {
+ case AxisForward:
+ if ((joy_advanced.integer == 0) && mouselook)
+ {
+ // user wants forward control to become look control
+ if (fabs(fAxisValue) > joy_pitchthreshold.value)
+ {
+ // if mouse invert is on, invert the joystick pitch value
+ // only absolute control support here (joy_advanced is false)
+ if (m_pitch.value < 0.0)
+ {
+ cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
+ }
+ else
+ {
+ cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
+ }
+ V_StopPitchDrift();
+ }
+ else
+ {
+ // no pitch movement
+ // disable pitch return-to-center unless requested by user
+ // *** this code can be removed when the lookspring bug is fixed
+ // *** the bug always has the lookspring feature on
+ if(lookspring.value == 0.0)
+ V_StopPitchDrift();
+ }
+ }
+ else
+ {
+ // user wants forward control to be forward control
+ if (fabs(fAxisValue) > joy_forwardthreshold.value)
+ {
+ cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
+ }
+ }
+ break;
+
+ case AxisSide:
+ if (fabs(fAxisValue) > joy_sidethreshold.value)
+ {
+ cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
+ }
+ break;
+
+ case AxisTurn:
+ if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
+ {
+ // user wants turn control to become side control
+ if (fabs(fAxisValue) > joy_sidethreshold.value)
+ {
+ cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
+ }
+ }
+ else
+ {
+ // user wants turn control to be turn control
+ if (fabs(fAxisValue) > joy_yawthreshold.value)
+ {
+ if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
+ {
+ cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
+ }
+ else
+ {
+ cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
+ }
+
+ }
+ }
+ break;
+
+ case AxisLook:
+ if (mouselook)
+ {
+ if (fabs(fAxisValue) > joy_pitchthreshold.value)
+ {
+ // pitch movement detected and pitch movement desired by user
+ if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
+ {
+ cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
+ }
+ else
+ {
+ cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
+ }
+ V_StopPitchDrift();
+ }
+ else
+ {
+ // no pitch movement
+ // disable pitch return-to-center unless requested by user
+ // *** this code can be removed when the lookspring bug is fixed
+ // *** the bug always has the lookspring feature on
+ if(lookspring.integer == 0)
+ V_StopPitchDrift();
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+static void IN_Init(void)
+{
+ uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
+
+ // joystick variables
+ Cvar_RegisterVariable (&in_joystick);
+ Cvar_RegisterVariable (&joy_name);
+ Cvar_RegisterVariable (&joy_advanced);
+ Cvar_RegisterVariable (&joy_advaxisx);
+ Cvar_RegisterVariable (&joy_advaxisy);
+ Cvar_RegisterVariable (&joy_advaxisz);
+ Cvar_RegisterVariable (&joy_advaxisr);
+ Cvar_RegisterVariable (&joy_advaxisu);
+ Cvar_RegisterVariable (&joy_advaxisv);
+ Cvar_RegisterVariable (&joy_forwardthreshold);
+ Cvar_RegisterVariable (&joy_sidethreshold);
+ Cvar_RegisterVariable (&joy_pitchthreshold);
+ Cvar_RegisterVariable (&joy_yawthreshold);
+ Cvar_RegisterVariable (&joy_forwardsensitivity);
+ Cvar_RegisterVariable (&joy_sidesensitivity);
+ Cvar_RegisterVariable (&joy_pitchsensitivity);
+ Cvar_RegisterVariable (&joy_yawsensitivity);
+ Cvar_RegisterVariable (&joy_wwhack1);
+ Cvar_RegisterVariable (&joy_wwhack2);
+ Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
+}
+
+static void IN_Shutdown(void)
+{
+ IN_DeactivateMouse ();
+ IN_ShowMouse ();
+
+ if (g_pMouse)
+ IDirectInputDevice_Release(g_pMouse);
+ g_pMouse = NULL;
+
+ if (g_pdi)
+ IDirectInput_Release(g_pdi);
+ g_pdi = NULL;