]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cleaned up mouse input system
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Feb 2002 01:38:47 +0000 (01:38 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 28 Feb 2002 01:38:47 +0000 (01:38 +0000)
fixed a bug with svc_setangle on pitch (it was immediately getting clamped in some cases, which made it quite useless)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1589 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
cl_main.c
in_svgalib.c
in_win.c
input.h
vid.h
vid_glx.c
vid_shared.c

index 030ffa29275e0d94bde104c1ebfbac5a666fc493..661b05a45cdef0590f9f90cb9bfd041f07311ddb 100644 (file)
@@ -261,7 +261,6 @@ void CL_AdjustAngles (void)
        {
                cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right);
                cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left);
-               cl.viewangles[YAW] = ANGLEMOD(cl.viewangles[YAW]);
        }
        if (in_klook.state & 1)
        {
@@ -279,18 +278,12 @@ void CL_AdjustAngles (void)
        if (up || down)
                V_StopPitchDrift ();
 
-       // LordHavoc: changed from 80 to 90 (straight up)
-       if (cl.viewangles[PITCH] > 90)
-               cl.viewangles[PITCH] = 90;
-       // LordHavoc: changed from -70 to -90 (straight down)
-       if (cl.viewangles[PITCH] < -90)
-               cl.viewangles[PITCH] = -90;
-
-       if (cl.viewangles[ROLL] > 50)
-               cl.viewangles[ROLL] = 50;
-       if (cl.viewangles[ROLL] < -50)
-               cl.viewangles[ROLL] = -50;
-               
+       cl.viewangles[YAW] = ANGLEMOD(cl.viewangles[YAW]);
+       cl.viewangles[PITCH] = ANGLEMOD(cl.viewangles[PITCH]);
+       cl.viewangles[ROLL] = ANGLEMOD(cl.viewangles[ROLL]);
+
+       cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value);
+       cl.viewangles[ROLL] = bound(-50, cl.viewangles[ROLL], 50);
 }
 
 /*
index 13037820abf37b450eead51f5ffddeeaaac3853d..30b275604c1db4386e04fe46e530bd9582c24a7f 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -831,9 +831,13 @@ void CL_SendCmd (void)
        // get basic movement from keyboard
                CL_BaseMove (&cmd);
 
+               IN_PreMove(); // OS independent code
+
        // allow mice or other external controllers to add to the move
                IN_Move (&cmd);
 
+               IN_PostMove(); // OS independent code
+
        // send the unreliable message
                CL_SendMove (&cmd);
        }
index bf31dbe12e28c571b8a52d4d8e9721ed1c663b2f..fe0719dbba4b7367bd6eddb040c2fe053632a028 100644 (file)
@@ -63,8 +63,6 @@ static int    mx, my, uimx, uimy;
 static void IN_init_kb(void);
 static void IN_init_mouse(void);
 
-cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
-
 static void keyhandler(int scancode, int state)
 {
        int sc;
@@ -234,8 +232,6 @@ static void IN_init_mouse(void)
        char *mousedev;
        int mouserate = MOUSE_DEFAULTSAMPLERATE;
 
-       Cvar_RegisterVariable (&m_filter);
-
        mouse_buttons = 3;
 
        mtype = vga_getmousetype();
@@ -322,7 +318,6 @@ void IN_Commands(void)
 
 void IN_Move(usercmd_t *cmd)
 {
-       int mouselook = (in_mlook.state & 1) || freelook.integer;
        if (!UseMouse)
                return;
 
@@ -331,52 +326,13 @@ void IN_Move(usercmd_t *cmd)
                ;
 
        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;
-       }
        else
-       {
-               mouse_x = mx;
-               mouse_y = my;
-       }
-       old_mouse_x = mx;
-       old_mouse_y = my;
-       /* Clear for next update */
-       mx = my = 0;
-
-       // 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.integer && mouselook))
-               cmd->sidemove += m_side.value * mouse_x;
-       else
-               cl.viewangles[YAW] -= m_yaw.value * mouse_x;
-
-       if (mouselook)
-               V_StopPitchDrift();
-
-       // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
-       if (mouselook && !(in_strafe.state & 1))
-               cl.viewangles[PITCH] += m_pitch.value * mouse_y;
-       else
-       {
-               if ((in_strafe.state & 1) && noclip_anglehack)
-                       cmd->upmove -= m_forward.value * mouse_y;
-               else
-                       cmd->forwardmove -= m_forward.value * mouse_y;
-       }
-       cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value);
+               IN_Mouse(cmd, mx, my);
+       mx = 0;
+       my = 0;
+       uimx = 0;
+       uimy = 0;
 }
 
 void IN_HandlePause (qboolean pause)
index 94c343731e41555ee7385df723cd936c78e33d2a..35e01381a0e64d5c8f7406ce85249e61e2bdb720 100644 (file)
--- a/in_win.c
+++ b/in_win.c
@@ -33,8 +33,6 @@ HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
        LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
 
 // mouse variables
-cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
-
 int                    mouse_buttons;
 int                    mouse_oldbuttonstate;
 POINT          current_pos;
@@ -438,9 +436,6 @@ IN_Init
 */
 void IN_Init (void)
 {
-       // mouse variables
-       Cvar_RegisterVariable (&m_filter);
-
        // joystick variables
        Cvar_RegisterVariable (&in_joystick);
        Cvar_RegisterVariable (&joy_name);
@@ -633,52 +628,11 @@ void IN_MouseMove (usercmd_t *cmd)
                my_accum = 0;
        }
 
-//if (mx ||  my)
-//     Con_DPrintf("mx=%d, my=%d\n", mx, my);
+       IN_Mouse(cmd, mx, my);
 
-       if (m_filter.integer)
-       {
-               mouse_x = (mx + old_mouse_x) * 0.5;
-               mouse_y = (my + old_mouse_y) * 0.5;
-       }
-       else
-       {
-               mouse_x = mx;
-               mouse_y = my;
-       }
-
-       old_mouse_x = mx;
-       old_mouse_y = my;
-
-       // 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.integer && mouselook))
-               cmd->sidemove += m_side.value * mouse_x;
-       else
-               cl.viewangles[YAW] -= m_yaw.value * mouse_x;
-
-       if (mouselook)
-               V_StopPitchDrift ();
-       
-       // LordHavoc: changed limits on pitch from -70 to 80, to -90 to 90
-       if (mouselook && !(in_strafe.state & 1))
-               cl.viewangles[PITCH] += m_pitch.value * mouse_y;
-       else
-       {
-               if ((in_strafe.state & 1) && noclip_anglehack)
-                       cmd->upmove -= m_forward.value * mouse_y;
-               else
-                       cmd->forwardmove -= m_forward.value * mouse_y;
-       }
-
-// if the mouse has moved, force it to the center, so there's room to move
-       if (mx || my)
-       {
+       // if the mouse has moved, force it to the center, so there's room to move
+       if (!dinput && (mx || my))
                SetCursorPos (window_center_x, window_center_y);
-       }
 }
 
 
@@ -1182,10 +1136,4 @@ void IN_JoyMove (usercmd_t *cmd)
                        break;
                }
        }
-
-       // bounds check pitch
-       if (cl.viewangles[PITCH] > 80.0)
-               cl.viewangles[PITCH] = 80.0;
-       if (cl.viewangles[PITCH] < -70.0)
-               cl.viewangles[PITCH] = -70.0;
 }
diff --git a/input.h b/input.h
index c3daa1700e9d8d0212929cad8b455586dfb3841e..a44a5eec615afe0ac3ea112922f5d4d82c78c6ef 100644 (file)
--- a/input.h
+++ b/input.h
@@ -19,6 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 // input.h -- external (non-keyboard) input devices
 
+extern cvar_t in_pitch_min;
+extern cvar_t in_pitch_max;
+
 void IN_Init (void);
 
 void IN_Shutdown (void);
@@ -29,6 +32,11 @@ void IN_Commands (void);
 void IN_Move (usercmd_t *cmd);
 // add additional movement on top of the keyboard move cmd
 
+void IN_PreMove(void);
+void IN_PostMove(void);
+
+void IN_Mouse(usercmd_t *cmd, float mx, float my);
+
 void IN_ClearStates (void);
 // restores all button and position states to defaults
 
diff --git a/vid.h b/vid.h
index 7339528258059e5d896a3f0d4321e58284426918..2df5d6fc0fc6c99b862e64384f5a77351164f24a 100644 (file)
--- a/vid.h
+++ b/vid.h
@@ -40,9 +40,6 @@ extern cvar_t vid_mode;
 extern cvar_t vid_mouse;
 extern cvar_t vid_fullscreen;
 
-extern cvar_t in_pitch_min;
-extern cvar_t in_pitch_max;
-
 void VID_InitCvars(void);
 
 void GL_Init (void);
index 5fa9867b6ec74b5c0ee2dcf8019a0e8f8e363f88..c4282cf34f5da6a18c8a4d7d12aca26f9c07281a 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -60,7 +60,6 @@ static int p_mouse_x, p_mouse_y;
 
 cvar_t vid_dga = {CVAR_SAVE, "vid_dga", "1"};
 cvar_t vid_dga_mouseaccel = {0, "vid_dga_mouseaccel", "1"};
-cvar_t m_filter = {0, "m_filter", "0"};
 
 qboolean vidmode_ext = false;
 
@@ -635,7 +634,6 @@ void VID_Init(void)
 
        Cvar_RegisterVariable (&vid_dga);
        Cvar_RegisterVariable (&vid_dga_mouseaccel);
-       Cvar_RegisterVariable (&m_filter);
 
 // interpret command-line params
 
@@ -830,53 +828,12 @@ void IN_Commands (void)
 {
 }
 
-/*
-===========
-IN_Move
-===========
-*/
-void IN_MouseMove (usercmd_t *cmd)
-{
-       if (!mouse_avail)
-               return;
-
-       if (m_filter.integer)
-       {
-               mouse_x = (mouse_x + old_mouse_x) * 0.5;
-               mouse_y = (mouse_y + old_mouse_y) * 0.5;
-
-               old_mouse_x = mouse_x;
-               old_mouse_y = mouse_y;
-       }
-
-       // LordHavoc: viewzoom affects mouse sensitivity for sniping
-       mouse_x *= sensitivity.value * cl.viewzoom;
-       mouse_y *= sensitivity.value * cl.viewzoom;
-
-       if (in_strafe.state & 1)
-               cmd->sidemove += m_side.value * mouse_x;
-       else
-               cl.viewangles[YAW] -= m_yaw.value * mouse_x;
-
-       //if (freelook)
-               V_StopPitchDrift ();
-
-       if (/*freelook && */!(in_strafe.state & 1))
-               cl.viewangles[PITCH] += m_pitch.value * mouse_y;
-       else
-       {
-               if ((in_strafe.state & 1) && noclip_anglehack)
-                       cmd->upmove -= m_forward.value * mouse_y;
-               else
-                       cmd->forwardmove -= m_forward.value * mouse_y;
-       }
-       mouse_x = mouse_y = 0.0;
-}
-
 void IN_Move (usercmd_t *cmd)
 {
-       IN_MouseMove(cmd);
-       cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value);
+       if (mouseavail)
+               In_Mouse(cmd, mouse_x, mouse_y);
+       mouse_x = 0;
+       mouse_y = 0;
 }
 
 
index 79451a54ec33ad94b3e54f713ab37a5d6cd4aa53..6730f55f4382e47fd959d031f59106cf83a6a244 100644 (file)
@@ -20,6 +20,8 @@ cvar_t gl_combine = {0, "gl_combine", "1"};
 cvar_t in_pitch_min = {0, "in_pitch_min", "-90"};
 cvar_t in_pitch_max = {0, "in_pitch_max", "90"};
 
+cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
+
 // GL_ARB_multitexture
 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
 void (GLAPIENTRY *qglActiveTexture) (GLenum);
@@ -167,6 +169,58 @@ void Force_CenterView_f (void)
        cl.viewangles[PITCH] = 0;
 }
 
+void IN_PreMove(void)
+{
+}
+
+void IN_PostMove(void)
+{
+}
+
+void IN_Mouse(usercmd_t *cmd, float mx, float my)
+{
+       int mouselook = (in_mlook.state & 1) || freelook.integer;
+       float mouse_x, mouse_y;
+       static float old_mouse_x = 0, old_mouse_y = 0;
+
+       if (m_filter.integer)
+       {
+               mouse_x = (mx + old_mouse_x) * 0.5;
+               mouse_y = (my + old_mouse_y) * 0.5;
+       }
+       else
+       {
+               mouse_x = mx;
+               mouse_y = my;
+       }
+
+       old_mouse_x = mx;
+       old_mouse_y = my;
+
+       // 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.integer && mouselook))
+               cmd->sidemove += m_side.value * mouse_x;
+       else
+               cl.viewangles[YAW] -= m_yaw.value * mouse_x;
+
+       if (mouselook)
+               V_StopPitchDrift();
+
+       if (mouselook && !(in_strafe.state & 1))
+               cl.viewangles[PITCH] += m_pitch.value * mouse_y;
+       else
+       {
+               if ((in_strafe.state & 1) && noclip_anglehack)
+                       cmd->upmove -= m_forward.value * mouse_y;
+               else
+                       cmd->forwardmove -= m_forward.value * mouse_y;
+       }
+}
+
 void VID_InitCvars(void)
 {
        Cvar_RegisterVariable(&vid_mode);
@@ -175,5 +229,6 @@ void VID_InitCvars(void)
        Cvar_RegisterVariable(&gl_combine);
        Cvar_RegisterVariable(&in_pitch_min);
        Cvar_RegisterVariable(&in_pitch_max);
+       Cvar_RegisterVariable(&m_filter);
        Cmd_AddCommand("force_centerview", Force_CenterView_f);
 }