diff options
author | Simon Howard | 2006-11-06 17:59:39 +0000 |
---|---|---|
committer | Simon Howard | 2006-11-06 17:59:39 +0000 |
commit | 3e9f2abe794b5511e6f913f825c97fe639464c1b (patch) | |
tree | 66512603434c29ba5999e5d9b22d0cf3a78a47de /src | |
parent | 61e6842f06a8960112d46af9637ea81811bc80ad (diff) | |
download | chocolate-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
Diffstat (limited to 'src')
-rw-r--r-- | src/i_video.c | 21 |
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; } |