commit 3e9f2abe794b5511e6f913f825c97fe639464c1b
Author: Simon Howard <fraggle@gmail.com>
AuthorDate: Mon Nov 6 17:59:39 2006 +0000
Commit: Simon Howard <fraggle@gmail.com>
CommitDate: Mon Nov 6 17:59:39 2006 +0000
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
---
src/i_video.c | 21 +++++++++++++++++----
1 file 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;
}