From e4d57ad72ce5720dcfe56064ba246f0553a91dd5 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 7 Jun 2016 15:54:08 -0400 Subject: [PATCH 01/11] SDL2: try out relative mouse mode --- src/sdl/i_video.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b5168dad5..0a8b4aa74 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -127,7 +127,8 @@ static Uint8 BitsPerPixel = 16; Uint16 realwidth = BASEVIDWIDTH; Uint16 realheight = BASEVIDHEIGHT; static SDL_bool mousegrabok = SDL_TRUE; -#define HalfWarpMouse(x,y) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) +static SDL_bool wrapmouseok = SDL_FALSE; +#define HalfWarpMouse(x,y) if (wrapmouseok) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) static SDL_bool videoblitok = SDL_FALSE; static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; @@ -417,6 +418,8 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) static void SDLdoUngrabMouse(void) { SDL_SetWindowGrab(window, SDL_FALSE); + wrapmouseok = SDL_FALSE; + SDL_SetRelativeMouseMode(SDL_FALSE); } void SDLforceUngrabMouse(void) @@ -424,6 +427,8 @@ void SDLforceUngrabMouse(void) if (SDL_WasInit(SDL_INIT_VIDEO)==SDL_INIT_VIDEO && window != NULL) { SDL_SetWindowGrab(window, SDL_FALSE); + wrapmouseok = SDL_FALSE; + SDL_SetRelativeMouseMode(SDL_FALSE); } } @@ -760,6 +765,8 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { D_PostEvent(&event); SDL_SetWindowGrab(window, SDL_TRUE); + if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) + wrapmouseok = SDL_TRUE; HalfWarpMouse(wwidth, wheight); } } From 70ce9421e42174794e430b0257e177aa3c226d6f Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 7 Jun 2016 16:19:24 -0400 Subject: [PATCH 02/11] SDL2: fixup ambiguous else in I_StartupMouse() --- src/sdl/i_video.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 0a8b4aa74..16ccbc6f8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1183,7 +1183,9 @@ void I_StartupMouse(void) return; if (!firsttimeonmouse) + { HalfWarpMouse(realwidth, realheight); // warp to center + } else firsttimeonmouse = SDL_FALSE; if (cv_usemouse.value) From 246e0c21bed6cf7cf208c1d66e5e79f1a93e2d48 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 7 Jun 2016 16:59:32 -0400 Subject: [PATCH 03/11] SDL2: do not use silly math in rel mode --- src/sdl/i_video.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 16ccbc6f8..53761f600 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -749,7 +749,12 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) return; } - if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + if (!wrapmouseok) + { + event.data2 = evt.xrel; + event.data3 = evt.yrel; + } + else if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } From 366e870b0e30ce1493a62bea86b5690870a6ce2e Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 7 Jun 2016 17:16:11 -0400 Subject: [PATCH 04/11] SDL2: check Rel Mouse Mode directly --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 53761f600..9800c8cc7 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -749,7 +749,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) return; } - if (!wrapmouseok) + if (SDL_GetRelativeMouseMode()) { event.data2 = evt.xrel; event.data3 = evt.yrel; From 35404be1e04f0a8e8dbf5c723bd3e49f0221bef1 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 7 Aug 2017 16:37:03 -0400 Subject: [PATCH 05/11] SDL: y input is flipped --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1f1fd8a11..2d6698cc8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -624,7 +624,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetRelativeMouseMode()) { event.data2 = evt.xrel; - event.data3 = evt.yrel; + event.data3 = -evt.yrel; } else if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { From 2d661fef18eeb4fa2dc221d1af5713ff75383dcc Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 25 Jun 2017 20:22:01 +0100 Subject: [PATCH 06/11] Turns out we don't need to use SDL_SetWindowTitle on its own, since SDL_CreateWindow already deals with the window title anyway. So I've disabled everything related to Impl_SetWindowName for now Also what were you thinking Fury?!? window shouldn't be NULL for SDL_SetWindowTitle, you backwards person you --- src/sdl/i_video.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2d6698cc8..2bcef9160 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -159,7 +159,7 @@ static INT32 windowedModes[MAXWINMODES][2] = static void Impl_VideoSetupSDLBuffer(void); static void Impl_VideoSetupBuffer(void); static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); -static void Impl_SetWindowName(const char *title); +//static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) @@ -1198,7 +1198,7 @@ INT32 VID_SetMode(INT32 modeNum) } vid.modenum = -1; } - Impl_SetWindowName("SRB2 "VERSIONSTRING); + //Impl_SetWindowName("SRB2 "VERSIONSTRING); SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); @@ -1281,14 +1281,16 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) return SDL_TRUE; } +/* static void Impl_SetWindowName(const char *title) { - if (window != NULL) + if (window == NULL) { return; } SDL_SetWindowTitle(window, title); } +*/ static void Impl_SetWindowIcon(void) { From 758e9c455888dea5b7cabfa77da267a2ded7e8e8 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 19 Aug 2017 21:39:04 +0100 Subject: [PATCH 07/11] Merge all (relative) mouse motion events into one mouse event This fixes SDL2_RelMouse's weaker sensitivity for me on Windows (but apparently not for others??) --- src/sdl/i_video.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2bcef9160..d1ec5d447 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -606,6 +606,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) if (event.data1) D_PostEvent(&event); } +static int mousemovex, mousemovey; + static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { event_t event; @@ -623,10 +625,20 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetRelativeMouseMode()) { - event.data2 = evt.xrel; - event.data3 = -evt.yrel; + //event.data2 = evt.xrel; + //event.data3 = -evt.yrel; + if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) + { + mousemovex += evt.xrel; + mousemovey += -evt.yrel; + SDL_SetWindowGrab(window, SDL_TRUE); + } + return; } - else if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + + SDL_memset(&event, 0, sizeof(event_t)); + + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } @@ -792,7 +804,8 @@ void I_GetEvent(void) SDL_Event evt; // We only want the first motion event, // otherwise we'll end up catching the warp back to center. - int mouseMotionOnce = 0; + //int mouseMotionOnce = 0; + mousemovex = mousemovey = 0; if (!graphics_started) { @@ -811,8 +824,9 @@ void I_GetEvent(void) Impl_HandleKeyboardEvent(evt.key, evt.type); break; case SDL_MOUSEMOTION: - if (!mouseMotionOnce) Impl_HandleMouseMotionEvent(evt.motion); - mouseMotionOnce = 1; + //if (!mouseMotionOnce) + Impl_HandleMouseMotionEvent(evt.motion); + //mouseMotionOnce = 1; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: @@ -835,6 +849,17 @@ void I_GetEvent(void) } } + if (mousemovex || mousemovey) + { + event_t event; + SDL_memset(&event, 0, sizeof(event_t)); + event.type = ev_mouse; + event.data1 = 0; + event.data2 = mousemovex; + event.data3 = mousemovey; + D_PostEvent(&event); + } + // In order to make wheels act like buttons, we have to set their state to Up. // This is because wheel messages don't have an up/down state. gamekeydown[KEY_MOUSEWHEELDOWN] = gamekeydown[KEY_MOUSEWHEELUP] = 0; From 10cbe2c82b5e375a558275265977f2a6f2542243 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 19 Aug 2017 22:54:30 +0100 Subject: [PATCH 08/11] Turns out the issue was with fullscreen! All I have to do is factor in the resolution/real window size ratio apparently (which was already done before) Also changed movemousex/y to INT32 --- src/sdl/i_video.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index d1ec5d447..81acb516b 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -606,7 +606,7 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) if (event.data1) D_PostEvent(&event); } -static int mousemovex, mousemovey; +static INT32 mousemovex, mousemovey; static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { @@ -629,8 +629,8 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) //event.data3 = -evt.yrel; if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - mousemovex += evt.xrel; - mousemovey += -evt.yrel; + mousemovex += (INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth)); + mousemovey += (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); SDL_SetWindowGrab(window, SDL_TRUE); } return; From 821a1810f74771991f535b9f4c27ae4a69821100 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 21 Aug 2017 21:38:29 +0100 Subject: [PATCH 09/11] Moved lrounding of mouse motion events to the actual point an event is made Also did some cleanup and moving around, as well as adding comments --- src/sdl/i_video.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 81acb516b..137f4e120 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -107,6 +107,9 @@ static SDL_bool disable_mouse = SDL_FALSE; // first entry in the modelist which is not bigger than MAXVIDWIDTHxMAXVIDHEIGHT static INT32 firstEntry = 0; +// Total mouse motion X/Y offsets +static INT32 mousemovex = 0, mousemovey = 0; + // SDL vars static SDL_Surface *vidSurface = NULL; static SDL_Surface *bufSurface = NULL; @@ -606,8 +609,6 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) if (event.data1) D_PostEvent(&event); } -static INT32 mousemovex, mousemovey; - static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { event_t event; @@ -623,30 +624,34 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) return; } + // If using relative mouse mode, don't post an event_t just now, + // 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 += (INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth)); - mousemovey += (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); + mousemovex += evt.xrel; //(INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth)); + mousemovey += -evt.yrel; //(INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); SDL_SetWindowGrab(window, SDL_TRUE); } return; } - SDL_memset(&event, 0, sizeof(event_t)); - + // If the event is from warping the pointer back to middle + // of the screen then ignore it. if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } - else - { - event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth)); - event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); - } + + 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; @@ -805,13 +810,14 @@ void I_GetEvent(void) // We only want the first motion event, // otherwise we'll end up catching the warp back to center. //int mouseMotionOnce = 0; - mousemovex = mousemovey = 0; if (!graphics_started) { return; } + mousemovex = mousemovey = 0; + while (SDL_PollEvent(&evt)) { switch (evt.type) @@ -849,14 +855,17 @@ void I_GetEvent(void) } } + // Send all relative mouse movement as one single mouse event. if (mousemovex || mousemovey) { event_t event; - SDL_memset(&event, 0, sizeof(event_t)); + int wwidth, wheight; + SDL_GetWindowSize(window, &wwidth, &wheight); + //SDL_memset(&event, 0, sizeof(event_t)); event.type = ev_mouse; event.data1 = 0; - event.data2 = mousemovex; - event.data3 = mousemovey; + event.data2 = (INT32)lround(mousemovex * ((float)wwidth / (float)realwidth)); + event.data3 = (INT32)lround(mousemovey * ((float)wheight / (float)realheight)); D_PostEvent(&event); } From 36977a5eda6e0fac2f2e73ab662688da4ef06687 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 22 Aug 2017 22:53:18 +0100 Subject: [PATCH 10/11] 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 137f4e120..9cebe4945 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? } } } From 50917d2ee2e3103a1aeac10e3aed2b1d4ad3e75c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 30 Aug 2017 19:21:23 +0100 Subject: [PATCH 11/11] P_FloorzAtPos: Check the normal floor's slope as well as FOF slopes, silly. --- src/p_map.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_map.c b/src/p_map.c index 81bf9ebee..f319acea8 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -4000,6 +4000,11 @@ fixed_t P_FloorzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) sector_t *sec = R_PointInSubsector(x, y)->sector; fixed_t floorz = sec->floorheight; +#ifdef ESLOPE + if (sec->f_slope) + floorz = P_GetZAt(sec->f_slope, x, y); +#endif + // Intercept the stupid 'fall through 3dfloors' bug Tails 03-17-2002 if (sec->ffloors) {