From 36977a5eda6e0fac2f2e73ab662688da4ef06687 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 22 Aug 2017 22:53:18 +0100 Subject: [PATCH] SDL_SetRelativeMouseMode(SDL_TRUE) already does what HalfWarpMouse does Also, don't post an ev_mouse event_t if not in relative mouse mode, so the camera doesn't jerk when the mouse enters the window --- src/sdl/i_video.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 137f4e12..9cebe494 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -611,13 +611,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { - event_t event; - int wwidth, wheight; - if (USE_MOUSEINPUT) { - SDL_GetWindowSize(window, &wwidth, &wheight); - if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) { SDLdoUngrabMouse(); @@ -628,40 +623,31 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) // add on the offsets so we can make an overall event later. if (SDL_GetRelativeMouseMode()) { - //event.data2 = evt.xrel; - //event.data3 = -evt.yrel; if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - mousemovex += evt.xrel; //(INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth)); - mousemovey += -evt.yrel; //(INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); + mousemovex += evt.xrel; + mousemovey += -evt.yrel; SDL_SetWindowGrab(window, SDL_TRUE); } return; } - // If the event is from warping the pointer back to middle + // If the event is from warping the pointer to middle // of the screen then ignore it. if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } - SDL_memset(&event, 0, sizeof(event_t)); - - event.type = ev_mouse; - - event.data2 = (INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth)); - event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); - - event.type = ev_mouse; - + // Don't send an event_t if not in relative mouse mode anymore, + // just grab and set relative mode + // this fixes the stupid camera jerk on mouse entering bug + // -- Monster Iestyn if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - D_PostEvent(&event); SDL_SetWindowGrab(window, SDL_TRUE); - if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) - wrapmouseok = SDL_TRUE; - HalfWarpMouse(wwidth, wheight); + if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful + wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? } } }