x11drv: Remove some of the mouse lag in games

Vitaliy Margolen wine-patch at kievinfo.com
Sun Oct 23 18:42:57 CDT 2005


This patch removes mouse lag for me in Half Life 1 in single player mode.
Apparently there are still a lag in multi player mode.

Vitaliy Margolen

changelog:
  x11drv/mouse.c
  - Use InterlockedExchange instead of x11_lock/unlock for internal pointer ops.
-------------- next part --------------
Index: mouse.c
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/mouse.c,v
retrieving revision 1.25
diff -u -p -r1.25 mouse.c
--- mouse.c	16 Aug 2005 16:02:45 -0000	1.25
+++ mouse.c	23 Oct 2005 21:57:18 -0000
@@ -72,7 +72,7 @@ static const UINT button_up_flags[NB_BUT
     MOUSEEVENTF_XUP
 };
 
-POINT cursor_pos;
+POINTS cursor_pos;
 
 /***********************************************************************
  *		get_coords
@@ -230,7 +230,7 @@ static void queue_raw_mouse_message( UIN
 void X11DRV_send_mouse_input( HWND hwnd, DWORD flags, DWORD x, DWORD y,
                               DWORD data, DWORD time, DWORD extra_info, UINT injected_flags )
 {
-    POINT pt;
+    POINTS pt;
 
     if (flags & MOUSEEVENTF_ABSOLUTE)
     {
@@ -244,9 +244,7 @@ void X11DRV_send_mouse_input( HWND hwnd,
             pt.x = x;
             pt.y = y;
         }
-        wine_tsx11_lock();
-        cursor_pos = pt;
-        wine_tsx11_unlock();
+        InterlockedExchange((PLONG)&cursor_pos, *(PLONG)&pt);
     }
     else if (flags & MOUSEEVENTF_MOVE)
     {
@@ -266,23 +264,20 @@ void X11DRV_send_mouse_input( HWND hwnd,
             if ((y > accel[1]) && (accel[2] == 2)) yMult = 4;
         }
 
-        wine_tsx11_lock();
-        pt.x = cursor_pos.x + (long)x * xMult;
-        pt.y = cursor_pos.y + (long)y * yMult;
+        InterlockedExchange((PLONG)&pt, *(PLONG)&cursor_pos);
+        pt.x += (int)x * xMult;
+        pt.y += (int)y * yMult;
 
         /* Clip to the current screen size */
         if (pt.x < 0) pt.x = 0;
         else if (pt.x >= screen_width) pt.x = screen_width - 1;
         if (pt.y < 0) pt.y = 0;
         else if (pt.y >= screen_height) pt.y = screen_height - 1;
-        cursor_pos = pt;
-        wine_tsx11_unlock();
+        InterlockedExchange((PLONG)&cursor_pos, *(PLONG)&pt);
     }
     else
     {
-        wine_tsx11_lock();
-        pt = cursor_pos;
-        wine_tsx11_unlock();
+        InterlockedExchange((PLONG)&pt, *(PLONG)&cursor_pos);
     }
 
     if (flags & MOUSEEVENTF_MOVE)
@@ -291,7 +286,7 @@ void X11DRV_send_mouse_input( HWND hwnd,
                                  extra_info, injected_flags );
         if (injected_flags & LLMHF_INJECTED)  /* we have to actually move the cursor */
         {
-            TRACE( "warping to (%ld,%ld)\n", pt.x, pt.y );
+            TRACE( "warping to (%d,%d)\n", pt.x, pt.y );
             wine_tsx11_lock();
             XWarpPointer( thread_display(), root_window, root_window, 0, 0, 0, 0, pt.x, pt.y );
             wine_tsx11_unlock();
@@ -697,9 +692,8 @@ BOOL X11DRV_SetCursorPos( INT x, INT y )
 
     wine_tsx11_lock();
     XWarpPointer( display, root_window, root_window, 0, 0, 0, 0, x, y );
-    cursor_pos.x = x;
-    cursor_pos.y = y;
     wine_tsx11_unlock();
+    InterlockedExchange((PLONG)&cursor_pos, MAKELONG(x, y));
     return TRUE;
 }
 
@@ -712,19 +706,20 @@ BOOL X11DRV_GetCursorPos(LPPOINT pos)
     Window root, child;
     int rootX, rootY, winX, winY;
     unsigned int xstate;
+    BOOL res;
 
     wine_tsx11_lock();
-    if (XQueryPointer( display, root_window, &root, &child,
-                       &rootX, &rootY, &winX, &winY, &xstate ))
+    res = XQueryPointer( display, root_window, &root, &child,
+                         &rootX, &rootY, &winX, &winY, &xstate );
+    wine_tsx11_unlock();
+    if (res)
     {
         update_key_state( xstate );
         update_button_state( xstate );
         TRACE("pointer at (%d,%d)\n", winX, winY );
-        cursor_pos.x = winX;
-        cursor_pos.y = winY;
+        InterlockedExchange((PLONG)&cursor_pos, MAKELONG(winX, winY));
     }
-    *pos = cursor_pos;
-    wine_tsx11_unlock();
+    POINTSTOPOINT(*pos, cursor_pos);
     return TRUE;
 }
 
Index: x11drv.h
===================================================================
RCS file: /home/wine/wine/dlls/x11drv/x11drv.h,v
retrieving revision 1.79
diff -u -p -r1.79 x11drv.h
--- x11drv.h	26 Sep 2005 11:04:12 -0000	1.79
+++ x11drv.h	23 Oct 2005 21:57:18 -0000
@@ -545,7 +545,7 @@ extern int copy_default_colors;
 extern int alloc_system_colors;
 
 extern BYTE key_state_table[256];
-extern POINT cursor_pos;
+extern POINTS cursor_pos;
 
 /* atoms */
 


More information about the wine-patches mailing list