more clean up of IN_Activate, added cl_ignoremousemove to merge some code
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 May 2005 23:10:38 +0000 (23:10 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 May 2005 23:10:38 +0000 (23:10 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5283 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
client.h
vid_glx.c
vid_sdl.c
vid_wgl.c

index 6d13866..9012907 100644 (file)
@@ -319,6 +319,8 @@ void CL_AdjustAngles (void)
        cl.viewangles[ROLL] = bound(-50, cl.viewangles[ROLL], 50);
 }
 
+qboolean cl_ignoremousemove = false;
+
 /*
 ================
 CL_Move
@@ -373,6 +375,14 @@ void CL_Move (void)
        // allow mice or other external controllers to add to the move
        IN_Move ();
 
+       // ignore a mouse move if mouse was activated/deactivated this frame
+       if (cl_ignoremousemove)
+       {
+               cl_ignoremousemove = false;
+               in_mouse_x = 0;
+               in_mouse_y = 0;
+       }
+
        // apply m_filter if it is on
        mx = in_mouse_x;
        my = in_mouse_y;
index ce6a0c3..9cdc2c5 100644 (file)
--- a/client.h
+++ b/client.h
@@ -736,6 +736,7 @@ void CL_ExpandEntities(int num);
 int  CL_ReadFromServer (void);
 void CL_WriteToServer (void);
 void CL_Move (void);
+extern qboolean cl_ignoremousemove;
 
 
 float CL_KeyState (kbutton_t *key);
index b0553f3..64fa66c 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -91,7 +91,6 @@ static qboolean vid_usingmouse = false;
 static qboolean vid_usemouse = false;
 static qboolean vid_usingvsync = false;
 static qboolean vid_usevsync = false;
-static qboolean ignoremousemove = false;
 static float   mouse_x, mouse_y;
 static int p_mouse_x, p_mouse_y;
 
@@ -292,7 +291,7 @@ static void IN_Activate (qboolean grab)
                        XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
 
                        mouse_x = mouse_y = 0;
-                       ignoremousemove = true;
+                       cl_ignoremousemove = true;
                        vid_usingmouse = true;
                }
        }
@@ -312,7 +311,7 @@ static void IN_Activate (qboolean grab)
                        if (win)
                                XUndefineCursor(vidx11_display, win);
 
-                       ignoremousemove = true;
+                       cl_ignoremousemove = true;
                        vid_usingmouse = false;
                }
        }
@@ -524,14 +523,6 @@ static void HandleEvents(void)
                p_mouse_y = scr_height / 2;
                XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, p_mouse_x, p_mouse_y);
        }
-
-       // if told to ignore one mouse move, do so
-       if (ignoremousemove)
-       {
-               ignoremousemove = false;
-               mouse_x = 0;
-               mouse_y = 0;
-       }
 }
 
 static void *prjobj = NULL;
@@ -885,7 +876,6 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
 
        vid_usingmouse = false;
        vid_usingvsync = false;
-       ignoremousemove = true;
        vid_hidden = false;
        vid_activewindow = true;
        GL_Init();
index 1aee0c8..42dbd46 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -28,9 +28,6 @@ static qboolean vid_isfullscreen;
 
 static SDL_Surface *screen;
 
-static void IN_Init( void );
-static void IN_Shutdown( void );
-
 /////////////////////////
 // Input handling
 ////
@@ -209,6 +206,7 @@ static void IN_Activate( qboolean grab )
                if (!vid_usingmouse)
                {
                        vid_usingmouse = true;
+                       cl_ignoremousemove = true;
                        SDL_WM_GrabInput( SDL_GRAB_ON );
                        SDL_ShowCursor( SDL_DISABLE );
                }
@@ -218,6 +216,7 @@ static void IN_Activate( qboolean grab )
                if (vid_usingmouse)
                {
                        vid_usingmouse = false;
+                       cl_ignoremousemove = true;
                        SDL_WM_GrabInput( SDL_GRAB_OFF );
                        SDL_ShowCursor( SDL_ENABLE );
                }
@@ -235,21 +234,6 @@ void IN_Move( void )
        }
 }
 
-static void IN_Init( void )
-{
-       // init keyboard
-       SDL_EnableUNICODE( SDL_ENABLE );
-       // enable key repeat since everyone expects it
-       SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
-       // init mouse
-       vid_usingmouse = false;
-}
-
-static void IN_Shutdown( void )
-{
-}
-
 /////////////////////
 // Message Handling
 ////
@@ -325,7 +309,10 @@ void VID_Init (void)
        vid_isfullscreen = false;
 
        SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter );
-       IN_Init();
+       // init keyboard
+       SDL_EnableUNICODE( SDL_ENABLE );
+       // enable key repeat since everyone expects it
+       SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 }
 
 // set the icon (we dont use SDL here since it would be too much a PITA)
@@ -454,13 +441,12 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
        vid_hidden = false;
        vid_activewindow = false;
        vid_usingmouse = false;
-       IN_Init();
        return true;
 }
 
 void VID_Shutdown (void)
 {
-       IN_Shutdown();
+       IN_Activate(false);
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
index 7c415bb..d4412c3 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -147,7 +147,7 @@ static qboolean     restore_spi;
 static int             originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
 
 static unsigned int uiWheelMessage;
-static qboolean        mouseparmsvalid, mouseactivatetoggle;
+static qboolean        mouseparmsvalid;
 static qboolean        dinput_acquired;
 
 static unsigned int            mstate_di;
@@ -311,22 +311,7 @@ void VID_Finish (void)
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
-       if (vid_usemouse)
-       {
-               if (!vid_usingmouse)
-               {
-                       vid_usingmouse = true;
-                       IN_Activate (true);
-               }
-       }
-       else
-       {
-               if (vid_usingmouse)
-               {
-                       vid_usingmouse = false;
-                       IN_Activate (false);
-               }
-       }
+       IN_Activate(vid_usemouse);
 
        if (r_render.integer && !vid_hidden)
        {
@@ -489,7 +474,6 @@ void AppActivate(BOOL fActive, BOOL minimize)
 
        if (!fActive)
        {
-               vid_usingmouse = false;
                IN_Activate (false);
                if (vid_isfullscreen)
                {
@@ -1044,45 +1028,51 @@ static void IN_Activate (qboolean grab)
 
        if (grab)
        {
-               mouseactivatetoggle = true;
-               if (dinput && g_pMouse)
-               {
-                       IDirectInputDevice_Acquire(g_pMouse);
-                       dinput_acquired = true;
-               }
-               else
+               if (!vid_usingmouse)
                {
-                       RECT window_rect;
-                       window_rect.left = window_x;
-                       window_rect.top = window_y;
-                       window_rect.right = window_x + window_width;
-                       window_rect.bottom = window_y + window_height;
-                       if (mouseparmsvalid)
-                               restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
-                       SetCursorPos (window_center_x, window_center_y);
-                       SetCapture (mainwindow);
-                       ClipCursor (&window_rect);
+                       vid_usingmouse = true;
+                       cl_ignoremousemove = true;
+                       if (dinput && g_pMouse)
+                       {
+                               IDirectInputDevice_Acquire(g_pMouse);
+                               dinput_acquired = true;
+                       }
+                       else
+                       {
+                               RECT window_rect;
+                               window_rect.left = window_x;
+                               window_rect.top = window_y;
+                               window_rect.right = window_x + window_width;
+                               window_rect.bottom = window_y + window_height;
+                               if (mouseparmsvalid)
+                                       restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
+                               SetCursorPos (window_center_x, window_center_y);
+                               SetCapture (mainwindow);
+                               ClipCursor (&window_rect);
+                       }
+                       ShowCursor (false);
                }
-               vid_usingmouse = true;
-               ShowCursor (false);
        }
        else
        {
-               mouseactivatetoggle = false;
-               if (dinput_acquired)
-               {
-                       IDirectInputDevice_Unacquire(g_pMouse);
-                       dinput_acquired = false;
-               }
-               else
+               if (vid_usingmouse)
                {
-                       if (restore_spi)
-                               SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
-                       ClipCursor (NULL);
-                       ReleaseCapture ();
+                       vid_usingmouse = false;
+                       cl_ignoremousemove = true;
+                       if (dinput_acquired)
+                       {
+                               IDirectInputDevice_Unacquire(g_pMouse);
+                               dinput_acquired = false;
+                       }
+                       else
+                       {
+                               if (restore_spi)
+                                       SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
+                               ClipCursor (NULL);
+                               ReleaseCapture ();
+                       }
+                       ShowCursor (true);
                }
-               vid_usingmouse = false;
-               ShowCursor (true);
        }
 }
 
@@ -1224,11 +1214,6 @@ static void IN_StartupMouse (void)
        }
 
        mouse_buttons = 10;
-
-// if a fullscreen video mode was set before the mouse was initialized,
-// set the mouse state appropriately
-       if (mouseactivatetoggle)
-               IN_Activate (true);
 }