]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - in_svgalib.c
added viewzoom extension to QC and client (smooth sniper zooming, with sensitivity...
[xonotic/darkplaces.git] / in_svgalib.c
index 7c258a0c5a252b560cccaf9e40ba7e95d80f475f..c84c6d65fc872715869933098f35456b8b15b13d 100644 (file)
@@ -58,12 +58,12 @@ static int  mouse_buttonstate;
 static int     mouse_oldbuttonstate;
 static float   mouse_x, mouse_y;
 static float   old_mouse_x, old_mouse_y;
 static int     mouse_oldbuttonstate;
 static float   mouse_x, mouse_y;
 static float   old_mouse_x, old_mouse_y;
-static int     mx, my;
+static int     mx, my, uimx, uimy;
 
 
-static void IN_init_kb();
-static void IN_init_mouse();
+static void IN_init_kb(void);
+static void IN_init_mouse(void);
 
 
-cvar_t m_filter = {"m_filter","0"};
+cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
 
 static void keyhandler(int scancode, int state)
 {
 
 static void keyhandler(int scancode, int state)
 {
@@ -80,6 +80,8 @@ static void keyhandler(int scancode, int state)
 static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
 {
        mouse_buttonstate = buttonstate;
 static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
 {
        mouse_buttonstate = buttonstate;
+       uimx += dx;
+       uimy += dy;
        mx += dx;
        my += dy;
        if (drx > 0) {
        mx += dx;
        my += dy;
        if (drx > 0) {
@@ -92,17 +94,12 @@ static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int d
 }
 
 
 }
 
 
-void Force_CenterView_f(void)
-{
-       cl.viewangles[PITCH] = 0;
-}
-
-
 void IN_Init(void)
 {
        if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
        if (COM_CheckParm("-nomouse")) UseMouse = 0;
 
 void IN_Init(void)
 {
        if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
        if (COM_CheckParm("-nomouse")) UseMouse = 0;
 
+       uimx = uimy = 0;
        if (UseKeyboard)
                IN_init_kb();
        if (UseMouse)
        if (UseKeyboard)
                IN_init_kb();
        if (UseMouse)
@@ -111,7 +108,7 @@ void IN_Init(void)
        in_svgalib_inited = 1;
 }
 
        in_svgalib_inited = 1;
 }
 
-static void IN_init_kb()
+static void IN_init_kb(void)
 {
        int i;
 
 {
        int i;
 
@@ -231,14 +228,13 @@ static void IN_init_kb()
        keyboard_seteventhandler(keyhandler);
 }
 
        keyboard_seteventhandler(keyhandler);
 }
 
-static void IN_init_mouse()
+static void IN_init_mouse(void)
 {
        int mtype;
        char *mousedev;
        int mouserate = MOUSE_DEFAULTSAMPLERATE;
 
        Cvar_RegisterVariable (&m_filter);
 {
        int mtype;
        char *mousedev;
        int mouserate = MOUSE_DEFAULTSAMPLERATE;
 
        Cvar_RegisterVariable (&m_filter);
-       Cmd_AddCommand("force_centerview", Force_CenterView_f);
 
        mouse_buttons = 3;
 
 
        mouse_buttons = 3;
 
@@ -271,8 +267,10 @@ void IN_Shutdown(void)
 {
        Con_Printf("IN_Shutdown\n");
 
 {
        Con_Printf("IN_Shutdown\n");
 
-       if (UseMouse) mouse_close();
-       if (UseKeyboard) keyboard_close();
+       if (UseMouse)
+               mouse_close();
+       if (UseKeyboard)
+               keyboard_close();
        in_svgalib_inited = 0;
 }
 
        in_svgalib_inited = 0;
 }
 
@@ -324,14 +322,23 @@ void IN_Commands(void)
 
 void IN_Move(usercmd_t *cmd)
 {
 
 void IN_Move(usercmd_t *cmd)
 {
-       int mouselook = (in_mlook.state & 1) || freelook.value;
-       if (!UseMouse) return;
+       int mouselook = (in_mlook.state & 1) || freelook.integer;
+       if (!UseMouse)
+               return;
 
        /* Poll mouse values */
        while (mouse_update())
                ;
 
 
        /* Poll mouse values */
        while (mouse_update())
                ;
 
-       if (m_filter.value)
+       if (key_dest != key_game)
+       {
+               ui_mouseupdaterelative(uimx, uimy);
+               uimx = uimy = 0;
+               return;
+       }
+       uimx = uimy = 0;
+
+       if (m_filter.integer)
        {
                mouse_x = (mx + old_mouse_x) * 0.5;
                mouse_y = (my + old_mouse_y) * 0.5;
        {
                mouse_x = (mx + old_mouse_x) * 0.5;
                mouse_y = (my + old_mouse_y) * 0.5;
@@ -346,16 +353,18 @@ void IN_Move(usercmd_t *cmd)
        /* Clear for next update */
        mx = my = 0;
 
        /* Clear for next update */
        mx = my = 0;
 
-       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 */
 
        /* 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;
 
                cmd->sidemove += m_side.value * mouse_x;
        else
                cl.viewangles[YAW] -= m_yaw.value * mouse_x;
 
-       if (mouselook) V_StopPitchDrift();
+       if (mouselook)
+               V_StopPitchDrift();
 
        // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
        if (mouselook && !(in_strafe.state & 1))
 
        // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
        if (mouselook && !(in_strafe.state & 1))