]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - in_win.c
added viewzoom extension to QC and client (smooth sniper zooming, with sensitivity...
[xonotic/darkplaces.git] / in_win.c
index d27f5976987734582a8e3498540ce679ea45f0eb..4d5ddbe9704cd720f418307a5b8aca37ebe10992 100644 (file)
--- a/in_win.c
+++ b/in_win.c
@@ -33,7 +33,7 @@ HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
        LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
 
 // mouse variables
-cvar_t m_filter = {"m_filter","0"};
+cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
 
 int                    mouse_buttons;
 int                    mouse_oldbuttonstate;
@@ -83,25 +83,25 @@ PDWORD      pdwRawValue[JOY_MAX_AXES];
 // each time.  this avoids any problems with getting back to a default usage
 // or when changing from one controller to another.  this way at least something
 // works.
-cvar_t in_joystick = {"joystick","0", true};
-cvar_t joy_name = {"joyname", "joystick"};
-cvar_t joy_advanced = {"joyadvanced", "0"};
-cvar_t joy_advaxisx = {"joyadvaxisx", "0"};
-cvar_t joy_advaxisy = {"joyadvaxisy", "0"};
-cvar_t joy_advaxisz = {"joyadvaxisz", "0"};
-cvar_t joy_advaxisr = {"joyadvaxisr", "0"};
-cvar_t joy_advaxisu = {"joyadvaxisu", "0"};
-cvar_t joy_advaxisv = {"joyadvaxisv", "0"};
-cvar_t joy_forwardthreshold = {"joyforwardthreshold", "0.15"};
-cvar_t joy_sidethreshold = {"joysidethreshold", "0.15"};
-cvar_t joy_pitchthreshold = {"joypitchthreshold", "0.15"};
-cvar_t joy_yawthreshold = {"joyyawthreshold", "0.15"};
-cvar_t joy_forwardsensitivity = {"joyforwardsensitivity", "-1.0"};
-cvar_t joy_sidesensitivity = {"joysidesensitivity", "-1.0"};
-cvar_t joy_pitchsensitivity = {"joypitchsensitivity", "1.0"};
-cvar_t joy_yawsensitivity = {"joyyawsensitivity", "-1.0"};
-cvar_t joy_wwhack1 = {"joywwhack1", "0.0"};
-cvar_t joy_wwhack2 = {"joywwhack2", "0.0"};
+cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
+cvar_t joy_name = {0, "joyname", "joystick"};
+cvar_t joy_advanced = {0, "joyadvanced", "0"};
+cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
+cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
+cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
+cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
+cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
+cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
+cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
+cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
+cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
+cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
+cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
+cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
+cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
+cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
+cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
+cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
 
 qboolean       joy_avail, joy_advancedinit, joy_haspov;
 DWORD          joy_oldbuttonstate, joy_oldpovstate;
@@ -534,13 +534,17 @@ IN_MouseMove
 */
 void IN_MouseMove (usercmd_t *cmd)
 {
-       int                                     i, mx, my, mouselook = (in_mlook.state & 1) || freelook.value;
+       int                                     i, mx, my, mouselook = (in_mlook.state & 1) || freelook.integer;
        DIDEVICEOBJECTDATA      od;
        DWORD                           dwElements;
        HRESULT                         hr;
 
        if (!mouseactive)
+       {
+               GetCursorPos (&current_pos);
+               ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
                return;
+       }
 
        if (dinput)
        {
@@ -592,7 +596,7 @@ void IN_MouseMove (usercmd_t *cmd)
                                        else
                                                mstate_di &= ~(1<<1);
                                        break;
-                                       
+
                                case DIMOFS_BUTTON2:
                                        if (od.dwData & 0x80)
                                                mstate_di |= (1<<2);
@@ -616,8 +620,8 @@ void IN_MouseMove (usercmd_t *cmd)
                        {
                                Key_Event (K_MOUSE1 + i, false);
                        }
-               }       
-                       
+               }
+
                mouse_oldbuttonstate = mstate_di;
        }
        else
@@ -632,7 +636,7 @@ void IN_MouseMove (usercmd_t *cmd)
 //if (mx ||  my)
 //     Con_DPrintf("mx=%d, my=%d\n", mx, my);
 
-       if (m_filter.value)
+       if (m_filter.integer)
        {
                mouse_x = (mx + old_mouse_x) * 0.5;
                mouse_y = (my + old_mouse_y) * 0.5;
@@ -646,11 +650,12 @@ void IN_MouseMove (usercmd_t *cmd)
        old_mouse_x = mx;
        old_mouse_y = my;
 
-       mouse_x *= sensitivity.value;
-       mouse_y *= sensitivity.value;
+       // LordHavoc: viewzoom affects mouse sensitivity for sniping
+       mouse_x *= sensitivity.value * cl.viewzoom;
+       mouse_y *= sensitivity.value * cl.viewzoom;
 
 // add mouse X/Y movement to cmd
-       if ( (in_strafe.state & 1) || (lookstrafe.value && mouselook))
+       if ( (in_strafe.state & 1) || (lookstrafe.integer && mouselook))
                cmd->sidemove += m_side.value * mouse_x;
        else
                cl.viewangles[YAW] -= m_yaw.value * mouse_x;
@@ -855,7 +860,7 @@ void Joy_AdvancedUpdate_f (void)
                pdwRawValue[i] = RawValuePointer(i);
        }
 
-       if( joy_advanced.value == 0.0)
+       if( joy_advanced.integer == 0)
        {
                // default joystick initialization
                // 2 axes only with joystick control
@@ -993,7 +998,7 @@ qboolean IN_ReadJoystick (void)
                // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
                // rather than having 32768 be the zero point, they have the zero point at 32668
                // go figure -- anyway, now we get the full resolution out of the device
-               if (joy_wwhack1.value != 0.0)
+               if (joy_wwhack1.integer != 0.0)
                {
                        ji.dwUpos += 100;
                }
@@ -1020,7 +1025,7 @@ void IN_JoyMove (usercmd_t *cmd)
 {
        float   speed, aspeed;
        float   fAxisValue, fTemp;
-       int             i, mouselook = (in_mlook.state & 1) || freelook.value;
+       int             i, mouselook = (in_mlook.state & 1) || freelook.integer;
 
        // complete initialization if first time in
        // this is needed as cvars are not available at initialization time
@@ -1031,11 +1036,11 @@ void IN_JoyMove (usercmd_t *cmd)
        }
 
        // verify joystick is available and that the user wants to use it
-       if (!joy_avail || !in_joystick.value)
+       if (!joy_avail || !in_joystick.integer)
        {
                return; 
        }
+
        // collect the joystick data, if possible
        if (IN_ReadJoystick () != true)
        {
@@ -1046,7 +1051,8 @@ void IN_JoyMove (usercmd_t *cmd)
                speed = cl_movespeedkey.value;
        else
                speed = 1;
-       aspeed = speed * host_realframetime;
+       // LordHavoc: viewzoom affects sensitivity for sniping
+       aspeed = speed * host_realframetime * cl.viewzoom;
 
        // loop through the axes
        for (i = 0; i < JOY_MAX_AXES; i++)
@@ -1056,7 +1062,7 @@ void IN_JoyMove (usercmd_t *cmd)
                // move centerpoint to zero
                fAxisValue -= 32768.0;
 
-               if (joy_wwhack2.value != 0.0)
+               if (joy_wwhack2.integer != 0.0)
                {
                        if (dwAxisMap[i] == AxisTurn)
                        {
@@ -1078,7 +1084,7 @@ void IN_JoyMove (usercmd_t *cmd)
                switch (dwAxisMap[i])
                {
                case AxisForward:
-                       if ((joy_advanced.value == 0.0) && mouselook)
+                       if ((joy_advanced.integer == 0) && mouselook)
                        {
                                // user wants forward control to become look control
                                if (fabs(fAxisValue) > joy_pitchthreshold.value)
@@ -1123,7 +1129,7 @@ void IN_JoyMove (usercmd_t *cmd)
                        break;
 
                case AxisTurn:
-                       if ((in_strafe.state & 1) || (lookstrafe.value && mouselook))
+                       if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
                        {
                                // user wants turn control to become side control
                                if (fabs(fAxisValue) > joy_sidethreshold.value)
@@ -1171,7 +1177,7 @@ void IN_JoyMove (usercmd_t *cmd)
                                        // 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)
+                                       if(lookspring.integer == 0)
                                                V_StopPitchDrift();
                                }
                        }