summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-11-06 17:59:39 +0000
committerSimon Howard2006-11-06 17:59:39 +0000
commit3e9f2abe794b5511e6f913f825c97fe639464c1b (patch)
tree66512603434c29ba5999e5d9b22d0cf3a78a47de
parent61e6842f06a8960112d46af9637ea81811bc80ad (diff)
downloadchocolate-doom-3e9f2abe794b5511e6f913f825c97fe639464c1b.tar.gz
chocolate-doom-3e9f2abe794b5511e6f913f825c97fe639464c1b.tar.bz2
chocolate-doom-3e9f2abe794b5511e6f913f825c97fe639464c1b.zip
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
-rw-r--r--src/i_video.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/i_video.c b/src/i_video.c
index c45d3640..469b113d 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -439,6 +439,20 @@ void I_GetEvent(void)
}
}
+// 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 @@ static void I_ReadMouse(void)
if (MouseShouldBeGrabbed())
{
- SDL_WarpMouse(screen->w / 2, screen->h / 2);
- SDL_PumpEvents();
- SDL_GetRelativeMouseState(NULL, NULL);
+ CenterMouse();
}
}
@@ -1150,9 +1162,10 @@ void I_InitGraphics(void)
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;
}