From 542a3723b2d413ea7a3a6cd5cce88cfd95572689 Mon Sep 17 00:00:00 2001 From: orbea Date: Sun, 27 Oct 2024 10:12:15 -0700 Subject: [PATCH 1/3] main: require SDL2 --- src/main/eventloop.c | 85 +----------------------------------- src/main/netplay.c | 5 +-- src/main/sdl_key_converter.h | 16 ------- src/main/workqueue.c | 5 +-- src/osd/osd.c | 2 - 5 files changed, 4 insertions(+), 109 deletions(-) diff --git a/src/main/eventloop.c b/src/main/eventloop.c index 49de3de94..6625638b4 100644 --- a/src/main/eventloop.c +++ b/src/main/eventloop.c @@ -25,43 +25,8 @@ #include #include #include -#if ! SDL_VERSION_ATLEAST(1,3,0) - -#define SDL_SCANCODE_ESCAPE SDLK_ESCAPE -#define SDL_NUM_SCANCODES SDLK_LAST -#define SDL_SCANCODE_F5 SDLK_F5 -#define SDL_SCANCODE_F7 SDLK_F7 -#define SDL_SCANCODE_F9 SDLK_F9 -#define SDL_SCANCODE_F10 SDLK_F10 -#define SDL_SCANCODE_F11 SDLK_F11 -#define SDL_SCANCODE_F12 SDLK_F12 -#define SDL_SCANCODE_P SDLK_p -#define SDL_SCANCODE_M SDLK_m -#define SDL_SCANCODE_RIGHTBRACKET SDLK_RIGHTBRACKET -#define SDL_SCANCODE_LEFTBRACKET SDLK_LEFTBRACKET -#define SDL_SCANCODE_F SDLK_f -#define SDL_SCANCODE_Y SDLK_y -#define SDL_SCANCODE_SLASH SDLK_SLASH -#define SDL_SCANCODE_G SDLK_g -#define SDL_SCANCODE_RETURN SDLK_RETURN -#define SDL_SCANCODE_0 SDLK_0 -#define SDL_SCANCODE_1 SDLK_1 -#define SDL_SCANCODE_2 SDLK_2 -#define SDL_SCANCODE_3 SDLK_3 -#define SDL_SCANCODE_4 SDLK_4 -#define SDL_SCANCODE_5 SDLK_5 -#define SDL_SCANCODE_6 SDLK_6 -#define SDL_SCANCODE_7 SDLK_7 -#define SDL_SCANCODE_8 SDLK_8 -#define SDL_SCANCODE_9 SDLK_9 -#define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN - -#define SDL_SetEventFilter(func, data) SDL_SetEventFilter(func) -#define event_sdl_filter(userdata, event) event_sdl_filter(const event) - -#else - SDL_JoystickID l_iJoyInstanceID[10]; -#endif + +SDL_JoystickID l_iJoyInstanceID[10]; #define M64P_CORE_PROTOTYPES 1 #include "api/callbacks.h" @@ -196,9 +161,7 @@ static int MatchJoyCommand(const SDL_Event *event, eJoyCommand cmd) else if (phrase_str[1] >= '0' && phrase_str[1] <= '9') { dev_number = phrase_str[1] - '0'; -#if SDL_VERSION_ATLEAST(2,0,0) dev_number = l_iJoyInstanceID[dev_number]; -#endif } else { @@ -319,24 +282,15 @@ static int SDLCALL event_sdl_filter(void *userdata, SDL_Event *event) break; case SDL_KEYDOWN: -#if SDL_VERSION_ATLEAST(1,3,0) if (event->key.repeat) return 0; event_sdl_keydown(event->key.keysym.scancode, event->key.keysym.mod); -#else - event_sdl_keydown(event->key.keysym.sym, event->key.keysym.mod); -#endif return 0; case SDL_KEYUP: -#if SDL_VERSION_ATLEAST(1,3,0) event_sdl_keyup(event->key.keysym.scancode, event->key.keysym.mod); -#else - event_sdl_keyup(event->key.keysym.sym, event->key.keysym.mod); -#endif return 0; -#if SDL_VERSION_ATLEAST(1,3,0) case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_RESIZED: @@ -352,22 +306,6 @@ static int SDLCALL event_sdl_filter(void *userdata, SDL_Event *event) break; } break; -#else - case SDL_VIDEORESIZE: - // call the video plugin. if the video plugin supports resizing, it will resize its viewport and call - // VidExt_ResizeWindow to update the window manager handling our opengl output window - gfx.resizeVideoOutput(event->resize.w, event->resize.h); - return 0; // consumed the event - break; - -#ifdef WIN32 - case SDL_SYSWMEVENT: - if(event->syswm.msg->msg == WM_MOVE) - gfx.moveScreen(0,0); // The video plugin is responsible for getting the new window position - return 0; // consumed the event - break; -#endif -#endif #ifndef NO_KEYBINDINGS // if joystick action is detected, check if it's mapped to a special function @@ -491,13 +429,8 @@ void event_initialize(void) { if (!SDL_WasInit(SDL_INIT_JOYSTICK)) SDL_InitSubSystem(SDL_INIT_JOYSTICK); -#if SDL_VERSION_ATLEAST(2,0,0) SDL_Joystick *thisJoy = SDL_JoystickOpen(device); l_iJoyInstanceID[device] = SDL_JoystickInstanceID(thisJoy); -#else - if (!SDL_JoystickOpened(device)) - SDL_JoystickOpen(device); -#endif } phrase_str = strtok(NULL, ","); @@ -508,17 +441,7 @@ void event_initialize(void) /* set up SDL event filter and disable key repeat */ -#if !SDL_VERSION_ATLEAST(2,0,0) - SDL_EnableKeyRepeat(0, 0); -#endif SDL_SetEventFilter(event_sdl_filter, NULL); - -#if defined(WIN32) && !SDL_VERSION_ATLEAST(1,3,0) - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - - if (SDL_EventState(SDL_SYSWMEVENT, SDL_QUERY) != SDL_ENABLE) - DebugMessage(M64MSG_WARNING, "Failed to change event state: %s", SDL_GetError()); -#endif } int event_set_core_defaults(void) @@ -559,11 +482,7 @@ int event_set_core_defaults(void) int key = SDL_SCANCODE_UNKNOWN; for (int slot = 0; slot < 10; slot++) { -#if ! SDL_VERSION_ATLEAST(1,3,0) - key = SDL_SCANCODE_0 + slot; -#else key = slot == 0 ? SDL_SCANCODE_0 : SDL_SCANCODE_1 + (slot - 1); -#endif sprintf(kbdSaveSlotStr, "%s%i", kbdSaveSlot, slot); sprintf(kbdSaveSlotHelpStr, "SDL keysym for save slot %i", slot); ConfigSetDefaultInt(l_CoreEventsConfig, kbdSaveSlotStr, sdl_native2keysym(key), kbdSaveSlotHelpStr); diff --git a/src/main/netplay.c b/src/main/netplay.c index 4d18627ee..8ff773ccd 100644 --- a/src/main/netplay.c +++ b/src/main/netplay.c @@ -312,11 +312,8 @@ static int netplay_ensure_valid(uint8_t control_id) if (l_udpChannel == -1) return 0; -#if SDL_VERSION_ATLEAST(2,0,0) SDL_Thread* thread = SDL_CreateThread(netplay_require_response, "Netplay key request", &control_id); -#else - SDL_Thread* thread = SDL_CreateThread(netplay_require_response, &control_id); -#endif + while (!check_valid(control_id, l_cin_compats[control_id].netplay_count) && l_udpChannel != -1) netplay_process(); int success; diff --git a/src/main/sdl_key_converter.h b/src/main/sdl_key_converter.h index d87081f5f..84fce4dee 100644 --- a/src/main/sdl_key_converter.h +++ b/src/main/sdl_key_converter.h @@ -27,8 +27,6 @@ uint16_t sdl_keysym2scancode(uint16_t keysym); uint16_t sdl_scancode2keysym(uint16_t scancode); -#if SDL_VERSION_ATLEAST(1,3,0) - static osal_inline uint16_t sdl_keysym2native(uint16_t keysym) { return sdl_keysym2scancode(keysym); @@ -38,17 +36,3 @@ static osal_inline uint16_t sdl_native2keysym(uint16_t native) { return sdl_scancode2keysym(native); } - -#else - -static osal_inline uint16_t sdl_keysym2native(uint16_t keysym) -{ - return keysym; -} - -static osal_inline uint16_t sdl_native2keysym(uint16_t native) -{ - return native; -} - -#endif diff --git a/src/main/workqueue.c b/src/main/workqueue.c index 2dd28d949..8efcc573c 100644 --- a/src/main/workqueue.c +++ b/src/main/workqueue.c @@ -131,11 +131,8 @@ int workqueue_init(void) return -1; } -#if SDL_VERSION_ATLEAST(2,0,0) thread->thread = SDL_CreateThread(workqueue_thread_handler, "m64pwq", thread); -#else - thread->thread = SDL_CreateThread(workqueue_thread_handler, thread); -#endif + if (!thread->thread) { DebugMessage(M64MSG_ERROR, "Could not create workqueue thread handler"); SDL_UnlockMutex(workqueue_mgmt.lock); diff --git a/src/osd/osd.c b/src/osd/osd.c index 5930fbdfd..684d7352c 100644 --- a/src/osd/osd.c +++ b/src/osd/osd.c @@ -234,7 +234,6 @@ void osd_init(int width, int height) return; } -#if SDL_VERSION_ATLEAST(2,0,0) int gl_context; VidExt_GL_GetAttribute(M64P_GL_CONTEXT_PROFILE_MASK, &gl_context); if (gl_context == M64P_GL_CONTEXT_PROFILE_CORE) @@ -242,7 +241,6 @@ void osd_init(int width, int height) DebugMessage(M64MSG_WARNING, "OSD not compatible with OpenGL core context. OSD deactivated."); return; } -#endif // clear statics for (i = 0; i < OSD_NUM_CORNERS; i++) From dea7dfd603872d551901d51d7cadd2578142a3a8 Mon Sep 17 00:00:00 2001 From: orbea Date: Sun, 27 Oct 2024 10:22:15 -0700 Subject: [PATCH 2/3] api: require SDL2 --- src/api/vidext.c | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/src/api/vidext.c b/src/api/vidext.c index 98c8bc14f..1c0ebe083 100644 --- a/src/api/vidext.c +++ b/src/api/vidext.c @@ -43,13 +43,12 @@ #include "m64p_vidext.h" #include "vidext.h" -#if SDL_VERSION_ATLEAST(2,0,0) - #ifndef USE_GLES - static int l_ForceCompatibilityContext = 1; - #endif -#include "vidext_sdl2_compat.h" +#ifndef USE_GLES +static int l_ForceCompatibilityContext = 1; #endif +#include "vidext_sdl2_compat.h" + /* local variables */ static m64p_video_extension_functions l_ExternalVideoFuncTable = {17, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; static int l_VideoExtensionActive = 0; @@ -134,13 +133,11 @@ EXPORT m64p_error CALL VidExt_InitWithRenderMode(m64p_render_mode RenderMode) l_RenderMode = RenderMode; #endif -#if SDL_VERSION_ATLEAST(2,0,0) SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); /* retrieve default swap interval/VSync */ if (RenderMode == M64P_RENDER_OPENGL) { l_SwapControl = SDL_GL_GetSwapInterval(); } -#endif #if SDL_VERSION_ATLEAST(2,24,0) /* fix DPI scaling issues on Windows */ @@ -188,9 +185,7 @@ EXPORT m64p_error CALL VidExt_Quit(void) return M64ERR_NOT_INIT; SDL_ShowCursor(SDL_ENABLE); -#if SDL_VERSION_ATLEAST(2,0,0) SDL2_DestroyWindow(); -#endif #ifdef VIDEXT_VULKAN if (l_RenderMode == M64P_RENDER_VULKAN) { SDL_Vulkan_UnloadLibrary(); @@ -264,7 +259,6 @@ EXPORT m64p_error CALL VidExt_ListFullscreenRates(m64p_2d_size Size, int *NumRat if (l_VideoExtensionActive) return (*l_ExternalVideoFuncTable.VidExtFuncListRates)(Size, NumRates, Rates); -#if SDL_VERSION_ATLEAST(2,0,0) if (!SDL_WasInit(SDL_INIT_VIDEO)) return M64ERR_NOT_INIT; @@ -299,10 +293,6 @@ EXPORT m64p_error CALL VidExt_ListFullscreenRates(m64p_2d_size Size, int *NumRat *NumRates = rateCount; return M64ERR_SUCCESS; -#else - // SDL1 doesn't support getting refresh rates - return M64ERR_UNSUPPORTED; -#endif } EXPORT m64p_error CALL VidExt_SetVideoMode(int Width, int Height, int BitsPerPixel, m64p_video_mode ScreenMode, m64p_video_flags Flags) @@ -377,14 +367,12 @@ EXPORT m64p_error CALL VidExt_SetVideoMode(int Width, int Height, int BitsPerPix SDL_ShowCursor(SDL_DISABLE); -#if SDL_VERSION_ATLEAST(2,0,0) /* set swap interval/VSync */ if (l_RenderMode == M64P_RENDER_OPENGL && SDL_GL_SetSwapInterval(l_SwapControl) != 0) { DebugMessage(M64MSG_ERROR, "SDL swap interval (VSync) set failed: %s", SDL_GetError()); } -#endif l_Fullscreen = (ScreenMode == M64VIDEO_FULLSCREEN); l_VideoOutputActive = 1; @@ -409,7 +397,6 @@ EXPORT m64p_error CALL VidExt_SetVideoModeWithRate(int Width, int Height, int Re return rval; } -#if SDL_VERSION_ATLEAST(2,0,0) if (!SDL_WasInit(SDL_INIT_VIDEO) || !SDL_VideoWindow) return M64ERR_NOT_INIT; @@ -486,10 +473,6 @@ EXPORT m64p_error CALL VidExt_SetVideoModeWithRate(int Width, int Height, int Re StateChanged(M64CORE_VIDEO_SIZE, (Width << 16) | Height); return M64ERR_SUCCESS; -#else - // SDL1 doesn't support setting refresh rates - return M64ERR_UNSUPPORTED; -#endif } EXPORT m64p_error CALL VidExt_ResizeWindow(int Width, int Height) @@ -643,16 +626,11 @@ static const GLAttrMapNode GLAttrMap[] = { { M64P_GL_GREEN_SIZE, SDL_GL_GREEN_SIZE }, { M64P_GL_BLUE_SIZE, SDL_GL_BLUE_SIZE }, { M64P_GL_ALPHA_SIZE, SDL_GL_ALPHA_SIZE }, -#if !SDL_VERSION_ATLEAST(1,3,0) - { M64P_GL_SWAP_CONTROL, SDL_GL_SWAP_CONTROL }, -#endif { M64P_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLEBUFFERS }, { M64P_GL_MULTISAMPLESAMPLES, SDL_GL_MULTISAMPLESAMPLES } -#if SDL_VERSION_ATLEAST(2,0,0) ,{ M64P_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MAJOR_VERSION }, { M64P_GL_CONTEXT_MINOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION }, { M64P_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_MASK } -#endif }; static const int mapSize = sizeof(GLAttrMap) / sizeof(GLAttrMapNode); @@ -677,7 +655,6 @@ EXPORT m64p_error CALL VidExt_GL_SetAttribute(m64p_GLattr Attr, int Value) } /* translate the GL context type mask if necessary */ -#if SDL_VERSION_ATLEAST(2,0,0) if (Attr == M64P_GL_CONTEXT_PROFILE_MASK) { switch (Value) @@ -698,7 +675,6 @@ EXPORT m64p_error CALL VidExt_GL_SetAttribute(m64p_GLattr Attr, int Value) Value = 0; } } -#endif for (i = 0; i < mapSize; i++) { @@ -727,13 +703,11 @@ EXPORT m64p_error CALL VidExt_GL_GetAttribute(m64p_GLattr Attr, int *pValue) if (!SDL_WasInit(SDL_INIT_VIDEO)) return M64ERR_NOT_INIT; -#if SDL_VERSION_ATLEAST(2,0,0) if (Attr == M64P_GL_SWAP_CONTROL) { *pValue = SDL_GL_GetSwapInterval(); return M64ERR_SUCCESS; } -#endif for (i = 0; i < mapSize; i++) { @@ -743,7 +717,6 @@ EXPORT m64p_error CALL VidExt_GL_GetAttribute(m64p_GLattr Attr, int *pValue) if (SDL_GL_GetAttribute(GLAttrMap[i].sdlAttr, &NewValue) != 0) return M64ERR_SYSTEM_FAIL; /* translate the GL context type mask if necessary */ -#if SDL_VERSION_ATLEAST(2,0,0) if (Attr == M64P_GL_CONTEXT_PROFILE_MASK) { switch (NewValue) @@ -761,7 +734,6 @@ EXPORT m64p_error CALL VidExt_GL_GetAttribute(m64p_GLattr Attr, int *pValue) NewValue = 0; } } -#endif *pValue = NewValue; return M64ERR_SUCCESS; } From 7e8193188ec9cf3217ad567694fe4ae82f8215f8 Mon Sep 17 00:00:00 2001 From: orbea Date: Thu, 31 Oct 2024 17:37:28 -0700 Subject: [PATCH 3/3] Remove SDL 1 from the README --- README | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index c346bff9e..101850196 100644 --- a/README +++ b/README @@ -22,7 +22,7 @@ README Sections *Binary Package Requirements* - - SDL 1.2 or 2.0 + - SDL 2 - libpng - freetype 2 - zlib diff --git a/README.md b/README.md index c7c5fc64b..53e66a372 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ as well as a user interface program (called a front-end). **Binary Package Requirements** - - SDL 1.2 or 2.0 + - SDL 2 - libpng - freetype 2 - zlib