From f4705b01f4be780d877314a170f661c26ad327d8 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 21 Nov 2016 19:42:39 +0000 Subject: [PATCH 1/9] Don't call SDLESSet Turns out sdl12's version of this function only did stuff for DC/GP2X ports; support for them have been cut out for SDL2, so for now let's just not use the function at all --- src/sdl/i_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 71baca51..95d2a0ab 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1494,10 +1494,12 @@ void VID_PrepareModeList(void) #endif } +#if 0 static inline void SDLESSet(void) { SDL2STUB(); } +#endif INT32 VID_SetMode(INT32 modeNum) { @@ -1718,7 +1720,7 @@ void I_StartupGraphics(void) borderlesswindow = M_CheckParm("-borderless"); //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY>>1,SDL_DEFAULT_REPEAT_INTERVAL<<2); - SDLESSet(); + //SDLESSet(); // unused VID_Command_ModeList_f(); #ifdef HWRENDER if (M_CheckParm("-opengl") || rendermode == render_opengl) From 168f8d5c5eb9d2ff517169632289265bbbb29a70 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 21 Nov 2016 20:40:02 +0000 Subject: [PATCH 2/9] Un-stub Surfaceinfo and just print the parts that still work in SDL2 This means the console command vid_info also works properly too now (well, it does nothing in OpenGL mind) --- src/sdl/i_video.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 95d2a0ab..70396e0c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -434,13 +434,8 @@ static void VID_Command_NumModes_f (void) static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) { -#if 1 - (void)infoSurface; - (void)SurfaceText; - SDL2STUB(); -#else INT32 vfBPP; - const SDL_Surface *VidSur = SDL_GetVideoSurface(); + //const SDL_Surface *VidSur = SDL_GetVideoSurface(); // SDL2 doesn't have this if (!infoSurface) return; @@ -453,15 +448,16 @@ static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) CONS_Printf("\x82" "%s\n", SurfaceText); CONS_Printf(M_GetText(" %ix%i at %i bit color\n"), infoSurface->w, infoSurface->h, vfBPP); + /* if (infoSurface->flags&SDL_HWSURFACE) CONS_Printf("%s", M_GetText(" Stored in video memory\n")); else if (infoSurface->flags&SDL_OPENGL) CONS_Printf("%s", M_GetText(" Stored in an OpenGL context\n")); - else if (infoSurface->flags&SDL_PREALLOC) + else */if (infoSurface->flags&SDL_PREALLOC) CONS_Printf("%s", M_GetText(" Uses preallocated memory\n")); else CONS_Printf("%s", M_GetText(" Stored in system memory\n")); - +/* if (infoSurface->flags&SDL_ASYNCBLIT) CONS_Printf("%s", M_GetText(" Uses asynchronous blits if possible\n")); else @@ -491,11 +487,13 @@ static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) CONS_Printf("%s", M_GetText(" Uses hardware acceleration blit\n")); if (infoSurface->flags&SDL_SRCCOLORKEY) CONS_Printf("%s", M_GetText(" Use colorkey blitting\n")); +*/ if (infoSurface->flags&SDL_RLEACCEL) CONS_Printf("%s", M_GetText(" Colorkey RLE acceleration blit\n")); +/* if (infoSurface->flags&SDL_SRCALPHA) CONS_Printf("%s", M_GetText(" Use alpha blending acceleration blit\n")); -#endif +*/ } static void VID_Command_Info_f (void) From 208546165baf2b28803ff0114f22f676c806ddfc Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 21 Nov 2016 20:59:44 +0000 Subject: [PATCH 3/9] Comment out SDL2STUB from Impl_SetWindowIcon --- 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 70396e0c..6ddfc391 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1620,7 +1620,7 @@ static void Impl_SetWindowIcon(void) { return; } - SDL2STUB(); + //SDL2STUB(); // Monster Iestyn: why is this stubbed? SDL_SetWindowIcon(window, icoSurface); } From 1606a45b186d340b7d800322dcd83a1e0531e433 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 21 Nov 2016 22:07:05 +0000 Subject: [PATCH 4/9] Some cleanup/reorganisation in SDLSetMode and Impl_CreateWindow --- src/sdl/i_video.c | 67 +++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6ddfc391..791d0752 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -189,14 +189,14 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) wasfullscreen = SDL_TRUE; SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } - else if (!fullscreen && wasfullscreen) + else if (wasfullscreen) { wasfullscreen = SDL_FALSE; SDL_SetWindowFullscreen(window, 0); SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED_DISPLAY(1), SDL_WINDOWPOS_CENTERED_DISPLAY(1)); } - else if (!wasfullscreen) + else { // Reposition window only in windowed mode SDL_SetWindowSize(window, width, height); @@ -1550,6 +1550,12 @@ INT32 VID_SetMode(INT32 modeNum) static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) { int flags = 0; + + if (rendermode == render_none) // dedicated + { + return SDL_TRUE; // Monster Iestyn -- not sure if it really matters what we return here tbh + } + if (window != NULL) { return SDL_FALSE; @@ -1568,38 +1574,43 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) #ifdef HWRENDER if (rendermode == render_opengl) { - window = SDL_CreateWindow("SRB2 "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - realwidth, realheight, flags | SDL_WINDOW_OPENGL); - if (window != NULL) - { - sdlglcontext = SDL_GL_CreateContext(window); - if (sdlglcontext == NULL) - { - SDL_DestroyWindow(window); - I_Error("Failed to create a GL context: %s\n", SDL_GetError()); - } - else - { - SDL_GL_MakeCurrent(window, sdlglcontext); - } - } - else return SDL_FALSE; + flags |= SDL_WINDOW_OPENGL; } #endif + + // Create a window + window = SDL_CreateWindow("SRB2 "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + realwidth, realheight, flags); + + if (window == NULL) + { + CONS_Printf(M_GetText("Couldn't create window: %s\n"), SDL_GetError()); + return SDL_FALSE; + } + + // Renderer-specific stuff +#ifdef HWRENDER + if (rendermode == render_opengl) + { + sdlglcontext = SDL_GL_CreateContext(window); + if (sdlglcontext == NULL) + { + SDL_DestroyWindow(window); + I_Error("Failed to create a GL context: %s\n", SDL_GetError()); + } + SDL_GL_MakeCurrent(window, sdlglcontext); + } + else +#endif if (rendermode == render_soft) { - window = SDL_CreateWindow("SRB2 "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - realwidth, realheight, flags); - if (window != NULL) + renderer = SDL_CreateRenderer(window, -1, (usesdl2soft ? SDL_RENDERER_SOFTWARE : 0) | (cv_vidwait.value && !usesdl2soft ? SDL_RENDERER_PRESENTVSYNC : 0)); + if (renderer == NULL) { - renderer = SDL_CreateRenderer(window, -1, (usesdl2soft ? SDL_RENDERER_SOFTWARE : 0) | (cv_vidwait.value && !usesdl2soft ? SDL_RENDERER_PRESENTVSYNC : 0)); - if (renderer != NULL) - { - SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT); - } - else return SDL_FALSE; + CONS_Printf(M_GetText("Couldn't create rendering context: %s\n"), SDL_GetError()); + return SDL_FALSE; } - else return SDL_FALSE; + SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT); } return SDL_TRUE; From 153ba39f1983a20cc3ae17e5828e7702be321e34 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 22 Nov 2016 22:41:02 +0000 Subject: [PATCH 5/9] Remove remnants of SDLK_ stuff, we use scancodes now not keycodes (Apparently SDLK_LMETA/SDLK_RMETA don't exist anymore in SDL2 anyway?) --- src/sdl/i_video.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 791d0752..a7a6ed15 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -33,14 +33,6 @@ #pragma warning(default : 4214 4244) #endif -#if SDL_VERSION_ATLEAST(1,3,0) -#define SDLK_EQUALS SDLK_KP_EQUALSAS400 -#define SDLK_LMETA SDLK_LGUI -#define SDLK_RMETA SDLK_RGUI -#else -#define HAVE_SDLMETAKEYS -#endif - #ifdef HAVE_TTF #include "i_ttf.h" #endif From 5cf4767aed86e25ec401e33cc7a35e6f5a10148b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 23 Nov 2016 16:51:37 +0000 Subject: [PATCH 6/9] Clearing away lots of disabled code (some of it would no longer work on SDL2 anyway) --- src/sdl/i_video.c | 281 +--------------------------------------------- 1 file changed, 2 insertions(+), 279 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a7a6ed15..5b83a881 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -424,10 +424,10 @@ static void VID_Command_NumModes_f (void) CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes()); } +// SDL2 doesn't have SDL_GetVideoSurface or a lot of the SDL_Surface flags that SDL 1.2 had static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) { INT32 vfBPP; - //const SDL_Surface *VidSur = SDL_GetVideoSurface(); // SDL2 doesn't have this if (!infoSurface) return; @@ -440,52 +440,12 @@ static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) CONS_Printf("\x82" "%s\n", SurfaceText); CONS_Printf(M_GetText(" %ix%i at %i bit color\n"), infoSurface->w, infoSurface->h, vfBPP); - /* - if (infoSurface->flags&SDL_HWSURFACE) - CONS_Printf("%s", M_GetText(" Stored in video memory\n")); - else if (infoSurface->flags&SDL_OPENGL) - CONS_Printf("%s", M_GetText(" Stored in an OpenGL context\n")); - else */if (infoSurface->flags&SDL_PREALLOC) + if (infoSurface->flags&SDL_PREALLOC) CONS_Printf("%s", M_GetText(" Uses preallocated memory\n")); else CONS_Printf("%s", M_GetText(" Stored in system memory\n")); -/* - if (infoSurface->flags&SDL_ASYNCBLIT) - CONS_Printf("%s", M_GetText(" Uses asynchronous blits if possible\n")); - else - CONS_Printf("%s", M_GetText(" Uses synchronous blits if possible\n")); - - if (infoSurface->flags&SDL_ANYFORMAT) - CONS_Printf("%s", M_GetText(" Allows any pixel-format\n")); - - if (infoSurface->flags&SDL_HWPALETTE) - CONS_Printf("%s", M_GetText(" Has exclusive palette access\n")); - else if (VidSur == infoSurface) - CONS_Printf("%s", M_GetText(" Has nonexclusive palette access\n")); - - if (infoSurface->flags&SDL_DOUBLEBUF) - CONS_Printf("%s", M_GetText(" Double buffered\n")); - else if (VidSur == infoSurface) - CONS_Printf("%s", M_GetText(" No hardware flipping\n")); - - if (infoSurface->flags&SDL_FULLSCREEN) - CONS_Printf("%s", M_GetText(" Full screen\n")); - else if (infoSurface->flags&SDL_RESIZABLE) - CONS_Printf("%s", M_GetText(" Resizable window\n")); - else if (VidSur == infoSurface) - CONS_Printf("%s", M_GetText(" Nonresizable window\n")); - - if (infoSurface->flags&SDL_HWACCEL) - CONS_Printf("%s", M_GetText(" Uses hardware acceleration blit\n")); - if (infoSurface->flags&SDL_SRCCOLORKEY) - CONS_Printf("%s", M_GetText(" Use colorkey blitting\n")); -*/ if (infoSurface->flags&SDL_RLEACCEL) CONS_Printf("%s", M_GetText(" Colorkey RLE acceleration blit\n")); -/* - if (infoSurface->flags&SDL_SRCALPHA) - CONS_Printf("%s", M_GetText(" Use alpha blending acceleration blit\n")); -*/ } static void VID_Command_Info_f (void) @@ -569,23 +529,6 @@ static void VID_Command_Mode_f (void) setmodeneeded = modenum+1; // request vid mode change } -#if 0 -#if defined(RPC_NO_WINDOWS_H) -static VOID MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - UNREFERENCED_PARAMETER(hWnd); - UNREFERENCED_PARAMETER(message); - UNREFERENCED_PARAMETER(wParam); - switch (message) - { - case WM_SETTEXT: - COM_BufAddText((LPCSTR)lParam); - break; - } -} -#endif -#endif - static inline void SDLJoyRemap(event_t *event) { (void)event; @@ -944,218 +887,6 @@ void I_GetEvent(void) // 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; - -#if 0 - SDL_Event inputEvent; - static SDL_bool sdlquit = SDL_FALSE; //Alam: once, just once - event_t event; - - if (!graphics_started) - return; - - memset(&inputEvent, 0x00, sizeof(inputEvent)); - while (SDL_PollEvent(&inputEvent)) - { - memset(&event,0x00,sizeof (event_t)); - switch (inputEvent.type) - { - case SDL_ACTIVEEVENT: - if (inputEvent.active.state & (SDL_APPACTIVE|SDL_APPINPUTFOCUS)) - { - // pause music when alt-tab - if (inputEvent.active.gain /*&& !paused */) - { - static SDL_bool firsttimeonmouse = SDL_TRUE; - if (!firsttimeonmouse) - { - if (cv_usemouse.value) I_StartupMouse(); - } - else firsttimeonmouse = SDL_FALSE; - //if (!netgame && !con_destlines) paused = false; - if (gamestate == GS_LEVEL) - if (!paused) I_ResumeSong(0); //resume it - } - else /*if (!paused)*/ - { - if (!disable_mouse) - SDLforceUngrabMouse(); - if (!netgame && gamestate == GS_LEVEL) paused = true; - memset(gamekeydown, 0, NUMKEYS); - //S_PauseSound(); - if (gamestate == GS_LEVEL) - I_PauseSong(0); //pause it - } - } - if (MOUSE_MENU) - { - SDLdoUngrabMouse(); - break; - } - if ((SDL_APPMOUSEFOCUS&inputEvent.active.state) && USE_MOUSEINPUT && inputEvent.active.gain) - HalfWarpMouse(realwidth, realheight); - break; - case SDL_KEYDOWN: - case SDL_KEYUP: - /// \todo inputEvent.key.which? - if (inputEvent.type == SDL_KEYUP) - event.type = ev_keyup; - else if (inputEvent.type == SDL_KEYDOWN) - event.type = ev_keydown; - else break; - event.data1 = SDLatekey(inputEvent.key.keysym.sym); - if (event.data1) D_PostEvent(&event); - break; - case SDL_MOUSEMOTION: - /// \todo inputEvent.motion.which - if (MOUSE_MENU) - { - SDLdoUngrabMouse(); - break; - } - //if (USE_MOUSEINPUT) TODO SDL2 stub - { - // If the event is from warping the pointer back to middle - // of the screen then ignore it. - if ((inputEvent.motion.x == realwidth/2) && - (inputEvent.motion.y == realheight/2)) - { - break; - } - else - { - event.data2 = +inputEvent.motion.xrel; - event.data3 = -inputEvent.motion.yrel; - } - event.type = ev_mouse; - D_PostEvent(&event); - // Warp the pointer back to the middle of the window - // or we cannot move any further if it's at a border. - if ((inputEvent.motion.x < (realwidth/2 )-(realwidth/4 )) || - (inputEvent.motion.y < (realheight/2)-(realheight/4)) || - (inputEvent.motion.x > (realwidth/2 )+(realwidth/4 )) || - (inputEvent.motion.y > (realheight/2)+(realheight/4) ) ) - { - //if (SDL_GRAB_ON == SDL_WM_GrabInput(SDL_GRAB_QUERY) || !mousegrabok) - HalfWarpMouse(realwidth, realheight); - } - } - break; - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - /// \todo inputEvent.button.which - if (USE_MOUSEINPUT) - { - if (inputEvent.type == SDL_MOUSEBUTTONUP) - event.type = ev_keyup; - else if (inputEvent.type == SDL_MOUSEBUTTONDOWN) - event.type = ev_keydown; - else break; - if (inputEvent.button.button==SDL_BUTTON_WHEELUP || inputEvent.button.button==SDL_BUTTON_WHEELDOWN) - { - if (inputEvent.type == SDL_MOUSEBUTTONUP) - event.data1 = 0; //Alam: dumb! this could be a real button with some mice - else - event.data1 = KEY_MOUSEWHEELUP + inputEvent.button.button - SDL_BUTTON_WHEELUP; - } - else if (inputEvent.button.button == SDL_BUTTON_MIDDLE) - event.data1 = KEY_MOUSE1+2; - else if (inputEvent.button.button == SDL_BUTTON_RIGHT) - event.data1 = KEY_MOUSE1+1; - else if (inputEvent.button.button <= MOUSEBUTTONS) - event.data1 = KEY_MOUSE1 + inputEvent.button.button - SDL_BUTTON_LEFT; - if (event.data1) D_PostEvent(&event); - } - break; - case SDL_JOYAXISMOTION: - inputEvent.jaxis.which++; - inputEvent.jaxis.axis++; - event.data1 = event.data2 = event.data3 = INT32_MAX; - if (cv_usejoystick.value == inputEvent.jaxis.which) - { - event.type = ev_joystick; - } - else if (cv_usejoystick.value == inputEvent.jaxis.which) - { - event.type = ev_joystick2; - } - else break; - //axis - if (inputEvent.jaxis.axis > JOYAXISSET*2) - break; - //vaule - if (inputEvent.jaxis.axis%2) - { - event.data1 = inputEvent.jaxis.axis / 2; - event.data2 = SDLJoyAxis(inputEvent.jaxis.value, event.type); - } - else - { - inputEvent.jaxis.axis--; - event.data1 = inputEvent.jaxis.axis / 2; - event.data3 = SDLJoyAxis(inputEvent.jaxis.value, event.type); - } - D_PostEvent(&event); - break; - case SDL_JOYBALLMOTION: - case SDL_JOYHATMOTION: - break; //NONE - case SDL_JOYBUTTONDOWN: - case SDL_JOYBUTTONUP: - inputEvent.jbutton.which++; - if (cv_usejoystick.value == inputEvent.jbutton.which) - event.data1 = KEY_JOY1; - else if (cv_usejoystick.value == inputEvent.jbutton.which) - event.data1 = KEY_2JOY1; - else break; - if (inputEvent.type == SDL_JOYBUTTONUP) - event.type = ev_keyup; - else if (inputEvent.type == SDL_JOYBUTTONDOWN) - event.type = ev_keydown; - else break; - if (inputEvent.jbutton.button < JOYBUTTONS) - event.data1 += inputEvent.jbutton.button; - else - break; - SDLJoyRemap(&event); - if (event.type != ev_console) D_PostEvent(&event); - break; - case SDL_QUIT: - if (!sdlquit) - { - sdlquit = SDL_TRUE; - M_QuitResponse('y'); - } - break; -#if defined(RPC_NO_WINDOWS_H) - case SDL_SYSWMEVENT: - MainWndproc(inputEvent.syswm.msg->hwnd, - inputEvent.syswm.msg->msg, - inputEvent.syswm.msg->wParam, - inputEvent.syswm.msg->lParam); - break; -#endif - case SDL_VIDEORESIZE: - if (gamestate == GS_LEVEL || gamestate == GS_TITLESCREEN || gamestate == GS_EVALUATION) - setmodeneeded = VID_GetModeForSize(inputEvent.resize.w,inputEvent.resize.h)+1; - if (render_soft == rendermode) - { - SDLSetMode(realwidth, realheight, vid.bpp*8, surfaceFlagsW); - if (vidSurface) SDL_SetColors(vidSurface, localPalette, 0, 256); - } - else - SDLSetMode(realwidth, realheight, vid.bpp*8, surfaceFlagsW); - if (!vidSurface) - I_Error("Could not reset vidmode: %s\n",SDL_GetError()); - break; - case SDL_VIDEOEXPOSE: - exposevideo = SDL_TRUE; - break; - default: - break; - } - } - //reset wheel like in win32, I don't understand it but works -#endif } void I_StartupMouse(void) @@ -1484,13 +1215,6 @@ void VID_PrepareModeList(void) #endif } -#if 0 -static inline void SDLESSet(void) -{ - SDL2STUB(); -} -#endif - INT32 VID_SetMode(INT32 modeNum) { SDLdoUngrabMouse(); @@ -1721,7 +1445,6 @@ void I_StartupGraphics(void) borderlesswindow = M_CheckParm("-borderless"); //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY>>1,SDL_DEFAULT_REPEAT_INTERVAL<<2); - //SDLESSet(); // unused VID_Command_ModeList_f(); #ifdef HWRENDER if (M_CheckParm("-opengl") || rendermode == render_opengl) From 8bbbeff2a9910fb5b57750a35a65d8e24b1cc387 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 23 Nov 2016 17:08:37 +0000 Subject: [PATCH 7/9] Make Impl_SDL_Scancode_To_Keycode look a bit neater This way it's easier by eye to see from the list which SDL scancode maps to which SRB2 key code --- src/sdl/i_video.c | 181 ++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 120 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5b83a881..aa572e6e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -274,129 +274,70 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) } switch (code) { - case SDL_SCANCODE_F11: // F11 and F12 are - return KEY_F11; // separated from the - case SDL_SCANCODE_F12: // rest of the function - return KEY_F12; // keys + // F11 and F12 are separated from the rest of the function keys + case SDL_SCANCODE_F11: return KEY_F11; + case SDL_SCANCODE_F12: return KEY_F12; - case SDL_SCANCODE_KP_0: - return KEY_KEYPAD0; - case SDL_SCANCODE_KP_1: - return KEY_KEYPAD1; - case SDL_SCANCODE_KP_2: - return KEY_KEYPAD2; - case SDL_SCANCODE_KP_3: - return KEY_KEYPAD3; - case SDL_SCANCODE_KP_4: - return KEY_KEYPAD4; - case SDL_SCANCODE_KP_5: - return KEY_KEYPAD5; - case SDL_SCANCODE_KP_6: - return KEY_KEYPAD6; - case SDL_SCANCODE_KP_7: - return KEY_KEYPAD7; - case SDL_SCANCODE_KP_8: - return KEY_KEYPAD8; - case SDL_SCANCODE_KP_9: - return KEY_KEYPAD9; + case SDL_SCANCODE_KP_0: return KEY_KEYPAD0; + case SDL_SCANCODE_KP_1: return KEY_KEYPAD1; + case SDL_SCANCODE_KP_2: return KEY_KEYPAD2; + case SDL_SCANCODE_KP_3: return KEY_KEYPAD3; + case SDL_SCANCODE_KP_4: return KEY_KEYPAD4; + case SDL_SCANCODE_KP_5: return KEY_KEYPAD5; + case SDL_SCANCODE_KP_6: return KEY_KEYPAD6; + case SDL_SCANCODE_KP_7: return KEY_KEYPAD7; + case SDL_SCANCODE_KP_8: return KEY_KEYPAD8; + case SDL_SCANCODE_KP_9: return KEY_KEYPAD9; - case SDL_SCANCODE_RETURN: - return KEY_ENTER; - case SDL_SCANCODE_ESCAPE: - return KEY_ESCAPE; - case SDL_SCANCODE_BACKSPACE: - return KEY_BACKSPACE; - case SDL_SCANCODE_TAB: - return KEY_TAB; - case SDL_SCANCODE_SPACE: - return KEY_SPACE; - case SDL_SCANCODE_MINUS: - return KEY_MINUS; - case SDL_SCANCODE_EQUALS: - return KEY_EQUALS; - case SDL_SCANCODE_LEFTBRACKET: - return '['; - case SDL_SCANCODE_RIGHTBRACKET: - return ']'; - case SDL_SCANCODE_BACKSLASH: - return '\\'; - case SDL_SCANCODE_NONUSHASH: - return '#'; - case SDL_SCANCODE_SEMICOLON: - return ';'; - case SDL_SCANCODE_APOSTROPHE: - return '\''; - case SDL_SCANCODE_GRAVE: - return '`'; - case SDL_SCANCODE_COMMA: - return ','; - case SDL_SCANCODE_PERIOD: - return '.'; - case SDL_SCANCODE_SLASH: - return '/'; - case SDL_SCANCODE_CAPSLOCK: - return KEY_CAPSLOCK; - case SDL_SCANCODE_PRINTSCREEN: - return 0; // undefined? - case SDL_SCANCODE_SCROLLLOCK: - return KEY_SCROLLLOCK; - case SDL_SCANCODE_PAUSE: - return KEY_PAUSE; - case SDL_SCANCODE_INSERT: - return KEY_INS; - case SDL_SCANCODE_HOME: - return KEY_HOME; - case SDL_SCANCODE_PAGEUP: - return KEY_PGUP; - case SDL_SCANCODE_DELETE: - return KEY_DEL; - case SDL_SCANCODE_END: - return KEY_END; - case SDL_SCANCODE_PAGEDOWN: - return KEY_PGDN; - case SDL_SCANCODE_RIGHT: - return KEY_RIGHTARROW; - case SDL_SCANCODE_LEFT: - return KEY_LEFTARROW; - case SDL_SCANCODE_DOWN: - return KEY_DOWNARROW; - case SDL_SCANCODE_UP: - return KEY_UPARROW; - case SDL_SCANCODE_NUMLOCKCLEAR: - return KEY_NUMLOCK; - case SDL_SCANCODE_KP_DIVIDE: - return KEY_KPADSLASH; - case SDL_SCANCODE_KP_MULTIPLY: - return '*'; // undefined? - case SDL_SCANCODE_KP_MINUS: - return KEY_MINUSPAD; - case SDL_SCANCODE_KP_PLUS: - return KEY_PLUSPAD; - case SDL_SCANCODE_KP_ENTER: - return KEY_ENTER; - case SDL_SCANCODE_KP_PERIOD: - return KEY_KPADDEL; - case SDL_SCANCODE_NONUSBACKSLASH: - return '\\'; + case SDL_SCANCODE_RETURN: return KEY_ENTER; + case SDL_SCANCODE_ESCAPE: return KEY_ESCAPE; + case SDL_SCANCODE_BACKSPACE: return KEY_BACKSPACE; + case SDL_SCANCODE_TAB: return KEY_TAB; + case SDL_SCANCODE_SPACE: return KEY_SPACE; + case SDL_SCANCODE_MINUS: return KEY_MINUS; + case SDL_SCANCODE_EQUALS: return KEY_EQUALS; + case SDL_SCANCODE_LEFTBRACKET: return '['; + case SDL_SCANCODE_RIGHTBRACKET: return ']'; + case SDL_SCANCODE_BACKSLASH: return '\\'; + case SDL_SCANCODE_NONUSHASH: return '#'; + case SDL_SCANCODE_SEMICOLON: return ';'; + case SDL_SCANCODE_APOSTROPHE: return '\''; + case SDL_SCANCODE_GRAVE: return '`'; + case SDL_SCANCODE_COMMA: return ','; + case SDL_SCANCODE_PERIOD: return '.'; + case SDL_SCANCODE_SLASH: return '/'; + case SDL_SCANCODE_CAPSLOCK: return KEY_CAPSLOCK; + case SDL_SCANCODE_PRINTSCREEN: return 0; // undefined? + case SDL_SCANCODE_SCROLLLOCK: return KEY_SCROLLLOCK; + case SDL_SCANCODE_PAUSE: return KEY_PAUSE; + case SDL_SCANCODE_INSERT: return KEY_INS; + case SDL_SCANCODE_HOME: return KEY_HOME; + case SDL_SCANCODE_PAGEUP: return KEY_PGUP; + case SDL_SCANCODE_DELETE: return KEY_DEL; + case SDL_SCANCODE_END: return KEY_END; + case SDL_SCANCODE_PAGEDOWN: return KEY_PGDN; + case SDL_SCANCODE_RIGHT: return KEY_RIGHTARROW; + case SDL_SCANCODE_LEFT: return KEY_LEFTARROW; + case SDL_SCANCODE_DOWN: return KEY_DOWNARROW; + case SDL_SCANCODE_UP: return KEY_UPARROW; + case SDL_SCANCODE_NUMLOCKCLEAR: return KEY_NUMLOCK; + case SDL_SCANCODE_KP_DIVIDE: return KEY_KPADSLASH; + case SDL_SCANCODE_KP_MULTIPLY: return '*'; // undefined? + case SDL_SCANCODE_KP_MINUS: return KEY_MINUSPAD; + case SDL_SCANCODE_KP_PLUS: return KEY_PLUSPAD; + case SDL_SCANCODE_KP_ENTER: return KEY_ENTER; + case SDL_SCANCODE_KP_PERIOD: return KEY_KPADDEL; + case SDL_SCANCODE_NONUSBACKSLASH: return '\\'; - case SDL_SCANCODE_LSHIFT: - return KEY_LSHIFT; - case SDL_SCANCODE_RSHIFT: - return KEY_RSHIFT; - case SDL_SCANCODE_LCTRL: - return KEY_LCTRL; - case SDL_SCANCODE_RCTRL: - return KEY_RCTRL; - case SDL_SCANCODE_LALT: - return KEY_LALT; - case SDL_SCANCODE_RALT: - return KEY_RALT; - case SDL_SCANCODE_LGUI: - return KEY_LEFTWIN; - case SDL_SCANCODE_RGUI: - return KEY_RIGHTWIN; - default: - break; + case SDL_SCANCODE_LSHIFT: return KEY_LSHIFT; + case SDL_SCANCODE_RSHIFT: return KEY_RSHIFT; + case SDL_SCANCODE_LCTRL: return KEY_LCTRL; + case SDL_SCANCODE_RCTRL: return KEY_RCTRL; + case SDL_SCANCODE_LALT: return KEY_LALT; + case SDL_SCANCODE_RALT: return KEY_RALT; + case SDL_SCANCODE_LGUI: return KEY_LEFTWIN; + case SDL_SCANCODE_RGUI: return KEY_RIGHTWIN; + default: break; } #ifdef HWRENDER DBG_Printf("Unknown incoming scancode: %d, represented %c\n", From 347b5318811db5a57108f0a1cca9addc6a046910 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 25 Nov 2016 21:13:39 +0000 Subject: [PATCH 8/9] (Messiness warning) attempt to start using SDL_SetRelativeMouseMode instead of the old hacks of making the mouse do movement without leaving the window and be hidden Seems to work so far though --- src/sdl/i_video.c | 66 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index aa572e6e..b0b3d256 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -527,7 +527,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { - static SDL_bool firsttimeonmouse = SDL_TRUE; + //static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -535,17 +535,21 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { case SDL_WINDOWEVENT_ENTER: mousefocus = SDL_TRUE; + //CONS_Printf("Window gained mouse focus!\n"); break; case SDL_WINDOWEVENT_LEAVE: mousefocus = SDL_FALSE; + //CONS_Printf("Window lost mouse focus!\n"); break; case SDL_WINDOWEVENT_FOCUS_GAINED: kbfocus = SDL_TRUE; mousefocus = SDL_TRUE; + //CONS_Printf("Window gained keyboard focus!\n"); break; case SDL_WINDOWEVENT_FOCUS_LOST: kbfocus = SDL_FALSE; mousefocus = SDL_FALSE; + //CONS_Printf("Window lost keyboard focus!\n"); break; case SDL_WINDOWEVENT_MAXIMIZED: break; @@ -558,11 +562,14 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (!paused) I_ResumeSong(0); //resume it - if (!firsttimeonmouse) + /*if (!firsttimeonmouse) { if (cv_usemouse.value) I_StartupMouse(); } //else firsttimeonmouse = SDL_FALSE; + + if (!disable_mouse && cv_usemouse.value) + SDL_SetRelativeMouseMode(SDL_TRUE);*/ } else if (!mousefocus && !kbfocus) { @@ -570,15 +577,34 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) window_notinfocus = true; I_PauseSong(0); - if (!disable_mouse) + /*if (!disable_mouse) { SDLforceUngrabMouse(); - } + SDL_SetRelativeMouseMode(SDL_FALSE); + HalfWarpMouse(realwidth, realheight); // warp to center + }*/ memset(gamekeydown, 0, NUMKEYS); // TODO this is a scary memset - if (MOUSE_MENU) + /*if (MOUSE_MENU) { SDLdoUngrabMouse(); + }*/ + } + + if (!disable_mouse) + { + if (mousefocus) + { + //if (cv_usemouse.value) + //SDL_SetRelativeMouseMode(SDL_TRUE); + } + else + { + if (SDL_GetRelativeMouseMode() == SDL_TRUE) + { + SDL_SetRelativeMouseMode(SDL_FALSE); + HalfWarpMouse(realwidth, realheight); // warp to center + } } } @@ -614,15 +640,15 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) { - SDLdoUngrabMouse(); + //SDLdoUngrabMouse(); return; } - if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + /*if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } - else + else*/ { event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth)); event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); @@ -632,9 +658,13 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - D_PostEvent(&event); - SDL_SetWindowGrab(window, SDL_TRUE); - HalfWarpMouse(wwidth, wheight); + if (SDL_GetRelativeMouseMode() == SDL_FALSE) + SDL_SetRelativeMouseMode(SDL_TRUE); + else + D_PostEvent(&event); + //SDL_SetRelativeMouseMode(SDL_TRUE); + //SDL_SetWindowGrab(window, SDL_TRUE); + //HalfWarpMouse(wwidth, wheight); } } } @@ -832,11 +862,18 @@ void I_GetEvent(void) void I_StartupMouse(void) { - static SDL_bool firsttimeonmouse = SDL_TRUE; + //static SDL_bool firsttimeonmouse = SDL_TRUE; if (disable_mouse) return; - + if (cv_usemouse.value) + SDL_SetRelativeMouseMode(SDL_TRUE); + else if (SDL_GetRelativeMouseMode() == SDL_TRUE) { + SDLdoUngrabMouse(); + SDL_SetRelativeMouseMode(SDL_FALSE); + HalfWarpMouse(realwidth, realheight); // warp to center + } +/* if (!firsttimeonmouse) HalfWarpMouse(realwidth, realheight); // warp to center else @@ -845,6 +882,7 @@ void I_StartupMouse(void) return; else SDLdoUngrabMouse(); +*/ } // @@ -1470,7 +1508,7 @@ void I_StartupGraphics(void) realheight = (Uint16)vid.height; VID_Command_Info_f(); - if (!disable_mouse) SDL_ShowCursor(SDL_DISABLE); + if (!disable_mouse) SDL_SetRelativeMouseMode(SDL_TRUE); SDLdoUngrabMouse(); graphics_started = true; From ae3e11369e828acc3ae352cfab10bb068274f8ce Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 30 Nov 2016 17:21:28 +0000 Subject: [PATCH 9/9] Revert "(Messiness warning) attempt to start using SDL_SetRelativeMouseMode instead of the old hacks of making the mouse do movement without leaving the window and be hidden" This reverts commit 347b5318811db5a57108f0a1cca9addc6a046910. (Too experimental, may end up adding new bugs; let's just keep it to clean up for now) --- src/sdl/i_video.c | 66 ++++++++++------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b0b3d256..aa572e6e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -527,7 +527,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { - //static SDL_bool firsttimeonmouse = SDL_TRUE; + static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -535,21 +535,17 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { case SDL_WINDOWEVENT_ENTER: mousefocus = SDL_TRUE; - //CONS_Printf("Window gained mouse focus!\n"); break; case SDL_WINDOWEVENT_LEAVE: mousefocus = SDL_FALSE; - //CONS_Printf("Window lost mouse focus!\n"); break; case SDL_WINDOWEVENT_FOCUS_GAINED: kbfocus = SDL_TRUE; mousefocus = SDL_TRUE; - //CONS_Printf("Window gained keyboard focus!\n"); break; case SDL_WINDOWEVENT_FOCUS_LOST: kbfocus = SDL_FALSE; mousefocus = SDL_FALSE; - //CONS_Printf("Window lost keyboard focus!\n"); break; case SDL_WINDOWEVENT_MAXIMIZED: break; @@ -562,14 +558,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (!paused) I_ResumeSong(0); //resume it - /*if (!firsttimeonmouse) + if (!firsttimeonmouse) { if (cv_usemouse.value) I_StartupMouse(); } //else firsttimeonmouse = SDL_FALSE; - - if (!disable_mouse && cv_usemouse.value) - SDL_SetRelativeMouseMode(SDL_TRUE);*/ } else if (!mousefocus && !kbfocus) { @@ -577,34 +570,15 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) window_notinfocus = true; I_PauseSong(0); - /*if (!disable_mouse) + if (!disable_mouse) { SDLforceUngrabMouse(); - SDL_SetRelativeMouseMode(SDL_FALSE); - HalfWarpMouse(realwidth, realheight); // warp to center - }*/ + } memset(gamekeydown, 0, NUMKEYS); // TODO this is a scary memset - /*if (MOUSE_MENU) + if (MOUSE_MENU) { SDLdoUngrabMouse(); - }*/ - } - - if (!disable_mouse) - { - if (mousefocus) - { - //if (cv_usemouse.value) - //SDL_SetRelativeMouseMode(SDL_TRUE); - } - else - { - if (SDL_GetRelativeMouseMode() == SDL_TRUE) - { - SDL_SetRelativeMouseMode(SDL_FALSE); - HalfWarpMouse(realwidth, realheight); // warp to center - } } } @@ -640,15 +614,15 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) { - //SDLdoUngrabMouse(); + SDLdoUngrabMouse(); return; } - /*if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } - else*/ + else { event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth)); event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); @@ -658,13 +632,9 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - if (SDL_GetRelativeMouseMode() == SDL_FALSE) - SDL_SetRelativeMouseMode(SDL_TRUE); - else - D_PostEvent(&event); - //SDL_SetRelativeMouseMode(SDL_TRUE); - //SDL_SetWindowGrab(window, SDL_TRUE); - //HalfWarpMouse(wwidth, wheight); + D_PostEvent(&event); + SDL_SetWindowGrab(window, SDL_TRUE); + HalfWarpMouse(wwidth, wheight); } } } @@ -862,18 +832,11 @@ void I_GetEvent(void) void I_StartupMouse(void) { - //static SDL_bool firsttimeonmouse = SDL_TRUE; + static SDL_bool firsttimeonmouse = SDL_TRUE; if (disable_mouse) return; - if (cv_usemouse.value) - SDL_SetRelativeMouseMode(SDL_TRUE); - else if (SDL_GetRelativeMouseMode() == SDL_TRUE) { - SDLdoUngrabMouse(); - SDL_SetRelativeMouseMode(SDL_FALSE); - HalfWarpMouse(realwidth, realheight); // warp to center - } -/* + if (!firsttimeonmouse) HalfWarpMouse(realwidth, realheight); // warp to center else @@ -882,7 +845,6 @@ void I_StartupMouse(void) return; else SDLdoUngrabMouse(); -*/ } // @@ -1508,7 +1470,7 @@ void I_StartupGraphics(void) realheight = (Uint16)vid.height; VID_Command_Info_f(); - if (!disable_mouse) SDL_SetRelativeMouseMode(SDL_TRUE); + if (!disable_mouse) SDL_ShowCursor(SDL_DISABLE); SDLdoUngrabMouse(); graphics_started = true;