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/17] 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/17] 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/17] 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/17] 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 ce1422a70bfba16ae5e8555e572ea70bd50182b4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 30 Apr 2017 22:53:05 +0100 Subject: [PATCH 05/17] Starting work for v.getSpritePatch and v.getSprite2Patch, dunno if these work yet mind --- src/lua_hudlib.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 5b3cd46ce..128a54dc8 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -12,6 +12,7 @@ #include "doomdef.h" #ifdef HAVE_BLUA +#include "fastcmp.h" #include "r_defs.h" #include "r_local.h" #include "st_stuff.h" // hudinfo[] @@ -343,6 +344,122 @@ static int libd_cachePatch(lua_State *L) return 1; } +static int libd_getSpritePatch(lua_State *L) +{ + UINT32 i; // sprite prefix + UINT32 frame = 0; // 'A' + UINT8 angle = 0; + spritedef_t *sprdef; + spriteframe_t *sprframe; + HUDONLY + + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK + { + i = lua_tonumber(L, 1); + if (i >= NUMSPRITES) + return 0; + } + else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK" + { + const char *name = lua_tostring(L, 1); + for (i = 0; i < NUMSPRITES; i++) + if (fastcmp(name, sprnames[i])) + break; + if (i >= NUMSPRITES) + return 0; + } + else + return 0; + + if (i == SPR_PLAY) // Use getSprite2Patch instead! + return 0; + + sprdef = &sprites[i]; + + // set frame number + frame = (luaL_optinteger(L, 2, 0); + frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case + if (frame >= sprdef->numframes) + return 0; + // set angle number + sprframe = sprdef->spriteframes[frame]; + angle = luaL_optinteger(L, 3, 0); + if (angle >= 8) + return 0; + + // push both the patch and it's "flip" value + LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH); + lua_pushboolean(L, (sprframe->flip & (1<= MAXSKINS) + return luaL_error(L, "skin number %d out of range (0 - %d)", i, MAXSKINS-1); + if (i >= numskins) + return 0; + } + else // find skin by name + { + const char *name = luaL_checkstring(L, 1); + for (i = 0; i < numskins; i++) + if (fastcmp(skins[i].name, field)) + break; + if (i >= numskins) + return 0; + } + + lua_remove(L, 1); // remove skin now + + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR2_STND + { + j = lua_tonumber(L, 1); + if (j >= free_spr2) + return 0; + } + else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "STND" + { + const char *name = lua_tostring(L, 1); + for (j = 0; j < free_spr2; j++) + if (fastcmp(name, sprnames[j])) + break; + if (j >= free_spr2) + return 0; + } + else + return 0; + + sprdef = &skins[i].sprites[j]; + + // set frame number + frame = (luaL_optinteger(L, 2, 0); + frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case + if (frame >= sprdef->numframes) + return 0; + // set angle number + sprframe = sprdef->spriteframes[frame]; + angle = luaL_optinteger(L, 3, 0); + if (angle >= 8) + return 0; + + // push both the patch and it's "flip" value + LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH); + lua_pushboolean(L, (sprframe->flip & (1< Date: Sat, 13 May 2017 21:28:44 +0100 Subject: [PATCH 06/17] Fix compiler errors --- src/lua_hudlib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 128a54dc8..9fcfcdd2e 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -377,12 +377,12 @@ static int libd_getSpritePatch(lua_State *L) sprdef = &sprites[i]; // set frame number - frame = (luaL_optinteger(L, 2, 0); + frame = luaL_optinteger(L, 2, 0); frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case if (frame >= sprdef->numframes) return 0; // set angle number - sprframe = sprdef->spriteframes[frame]; + sprframe = &sprdef->spriteframes[frame]; angle = luaL_optinteger(L, 3, 0); if (angle >= 8) return 0; @@ -395,7 +395,8 @@ static int libd_getSpritePatch(lua_State *L) static int libd_getSprite2Patch(lua_State *L) { - UINT32 i, j; // skin number, sprite2 prefix + INT32 i; // skin number + UINT32 j; // sprite2 prefix UINT32 frame = 0; // 'A' UINT8 angle = 0; spritedef_t *sprdef; @@ -406,7 +407,7 @@ static int libd_getSprite2Patch(lua_State *L) if (lua_isnumber(L, 1)) // find skin by number { i = lua_tonumber(L, 1); - if (i >= MAXSKINS) + if (i < 0 || i >= MAXSKINS) return luaL_error(L, "skin number %d out of range (0 - %d)", i, MAXSKINS-1); if (i >= numskins) return 0; @@ -415,7 +416,7 @@ static int libd_getSprite2Patch(lua_State *L) { const char *name = luaL_checkstring(L, 1); for (i = 0; i < numskins; i++) - if (fastcmp(skins[i].name, field)) + if (fastcmp(skins[i].name, name)) break; if (i >= numskins) return 0; @@ -444,12 +445,12 @@ static int libd_getSprite2Patch(lua_State *L) sprdef = &skins[i].sprites[j]; // set frame number - frame = (luaL_optinteger(L, 2, 0); + frame = luaL_optinteger(L, 2, 0); frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case if (frame >= sprdef->numframes) return 0; // set angle number - sprframe = sprdef->spriteframes[frame]; + sprframe = &sprdef->spriteframes[frame]; angle = luaL_optinteger(L, 3, 0); if (angle >= 8) return 0; From d91471b053852b6b67ef6f67a55797d39b477468 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 May 2017 21:43:04 +0100 Subject: [PATCH 07/17] check spr2names not sprnames, whoops --- src/lua_hudlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 9fcfcdd2e..4735d93d1 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -434,7 +434,7 @@ static int libd_getSprite2Patch(lua_State *L) { const char *name = lua_tostring(L, 1); for (j = 0; j < free_spr2; j++) - if (fastcmp(name, sprnames[j])) + if (fastcmp(name, spr2names[j])) break; if (j >= free_spr2) return 0; From e485ac3a7eb4155251349ae4d9049705e0a69297 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 9 Jul 2017 16:33:43 +0100 Subject: [PATCH 08/17] Add support for getting super sprites with v.getSprite2Patch You can either add FF_SPR2SUPER directly to the sprite2 arg if it's a number, or you can use the new (optional) boolean arg between sprite2 and frame, where as you'd expect false = normal and true = super. --- src/lua_hudlib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 4735d93d1..de923ab17 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -344,6 +344,7 @@ static int libd_cachePatch(lua_State *L) return 1; } +// v.getSpritePatch(sprite, [frame, [angle]]) static int libd_getSpritePatch(lua_State *L) { UINT32 i; // sprite prefix @@ -393,6 +394,7 @@ static int libd_getSpritePatch(lua_State *L) return 2; } +// v.getSprite2Patch(skin, sprite, [super?,] [frame, [angle]]) static int libd_getSprite2Patch(lua_State *L) { INT32 i; // skin number @@ -401,6 +403,7 @@ static int libd_getSprite2Patch(lua_State *L) UINT8 angle = 0; spritedef_t *sprdef; spriteframe_t *sprframe; + boolean super = false; // add FF_SPR2SUPER to sprite2 if true HUDONLY // get skin first! @@ -427,6 +430,11 @@ static int libd_getSprite2Patch(lua_State *L) if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR2_STND { j = lua_tonumber(L, 1); + if (j & FF_SPR2SUPER) // e.g. SPR2_STND|FF_SPR2SUPER + { + super = true; + j &= ~FF_SPR2SUPER; // remove flag so the next check doesn't fail + } if (j >= free_spr2) return 0; } @@ -436,12 +444,23 @@ static int libd_getSprite2Patch(lua_State *L) for (j = 0; j < free_spr2; j++) if (fastcmp(name, spr2names[j])) break; + // if you want super flags you'll have to use the optional boolean following this if (j >= free_spr2) return 0; } else return 0; + if (lua_isboolean(L, 2)) // optional boolean for superness + { + super = lua_toboolean(L, 2); // note: this can override FF_SPR2SUPER from sprite number + lua_remove(L, 2); // remove + } + // if it's not boolean then just assume it's the frame number + + if (super) + j |= FF_SPR2SUPER; + sprdef = &skins[i].sprites[j]; // set frame number From 4d740ff7836b01ece3e8a35d33f1e64a0ad5250e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 17 Jul 2017 21:31:33 +0100 Subject: [PATCH 09/17] Change getSpritePatch and getSpritePatch to accept angles 1-8 instead of 0-7, and just decrement the numbers internally 0 now just defaults to front angle (1, or 0 internally), in case people thought it was a separate angle from 1-8 for some reason --- src/lua_hudlib.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index de923ab17..0a6415697 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -384,8 +384,15 @@ static int libd_getSpritePatch(lua_State *L) return 0; // set angle number sprframe = &sprdef->spriteframes[frame]; - angle = luaL_optinteger(L, 3, 0); - if (angle >= 8) + angle = luaL_optinteger(L, 3, 1); + + // convert WAD editor angle numbers (1-8) to internal angle numbers (0-7) + // keep 0 the same since we'll make it default to angle 1 (which is internally 0) + // in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch + if (angle != 0) + angle--; + + if (angle >= 8) // out of range? return 0; // push both the patch and it's "flip" value @@ -470,8 +477,15 @@ static int libd_getSprite2Patch(lua_State *L) return 0; // set angle number sprframe = &sprdef->spriteframes[frame]; - angle = luaL_optinteger(L, 3, 0); - if (angle >= 8) + angle = luaL_optinteger(L, 3, 1); + + // convert WAD editor angle numbers (1-8) to internal angle numbers (0-7) + // keep 0 the same since we'll make it default to angle 1 (which is internally 0) + // in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch + if (angle != 0) + angle--; + + if (angle >= 8) // out of range? return 0; // push both the patch and it's "flip" value From 35404be1e04f0a8e8dbf5c723bd3e49f0221bef1 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 7 Aug 2017 16:37:03 -0400 Subject: [PATCH 10/17] 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 11/17] 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 9703aa2864f6fe693697fa1e939cf1280a8de05a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 16 Aug 2017 21:00:18 +0100 Subject: [PATCH 12/17] Feed skin and sprite2 through P_GetSkinSprite2 to change sprite2 if necessary (if for instance the supplied sprite2 didn't actually exist) --- src/lua_hudlib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 3cdedc3d7..8175f1b9b 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -468,6 +468,8 @@ static int libd_getSprite2Patch(lua_State *L) if (super) j |= FF_SPR2SUPER; + j = P_GetSkinSprite2(&skins[i], j, NULL); // feed skin and current sprite2 through to change sprite2 used if necessary + sprdef = &skins[i].sprites[j]; // set frame number From 758e9c455888dea5b7cabfa77da267a2ded7e8e8 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 19 Aug 2017 21:39:04 +0100 Subject: [PATCH 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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) {