]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
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 6d138662d91942ee3452f4d4dd346cf0e640d98b..9012907d6604de4fba0d966ea824ffddcfa6b0d6 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 ce6a0c36c06aabcc472e0bcc1497a29c64e5cc37..9cdc2c5de87db1c74f8d2f0107277d82a45399bc 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 b0553f30ae54e9c7bda7a155531911851d6cea32..64fa66c7191bad153529ba154d1b9c2282153a9f 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 1aee0c8b8c1ccdc063de726f0e6909ed3b2b2bc0..42dbd46a83736164bb5aa0b805796b18ad8bc10f 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 7c415bba527f96d23011ae8bea2eeb48032902ca..d4412c32cfef9933231636ee5896d087132412d4 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);
 }