shithub: choc

Download patch

ref: 3e9f2abe794b5511e6f913f825c97fe639464c1b
parent: 61e6842f06a8960112d46af9637ea81811bc80ad
author: Simon Howard <fraggle@gmail.com>
date: Mon Nov 6 12:59:39 EST 2006

Center the mouse on startup to prevent abrupt turns when launching a
game from the command line.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 746

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -439,6 +439,20 @@
     }
 }
 
+// Warp the mouse back to the middle of the screen
+
+static void CenterMouse(void)
+{
+    // Warp the the screen center
+
+    SDL_WarpMouse(screen->w / 2, screen->h / 2);
+
+    // Clear any relative movement caused by warping
+
+    SDL_PumpEvents();
+    SDL_GetRelativeMouseState(NULL, NULL);
+}
+
 //
 // Read the change in mouse state to generate mouse motion events
 //
@@ -464,9 +478,7 @@
 
     if (MouseShouldBeGrabbed())
     {
-        SDL_WarpMouse(screen->w / 2, screen->h / 2);
-        SDL_PumpEvents();
-        SDL_GetRelativeMouseState(NULL, NULL);
+        CenterMouse();
     }
 }
 
@@ -1150,9 +1162,10 @@
 
     SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
-    // clear out any events waiting at the start
+    // clear out any events waiting at the start and center the mouse
   
     while (SDL_PollEvent(&dummy));
+    CenterMouse();
 
     initialised = true;
 }