Skip to content

Commit

Permalink
Merge pull request #1094 from orbea/SDL2
Browse files Browse the repository at this point in the history
Require SDL2
  • Loading branch information
richard42 authored Nov 3, 2024
2 parents 485afc5 + 7e81931 commit b1dc082
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 143 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ README Sections

*Binary Package Requirements*

- SDL 1.2 or 2.0
- SDL 2
- libpng
- freetype 2
- zlib
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 4 additions & 32 deletions src/api/vidext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand All @@ -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++)
{
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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)
Expand All @@ -761,7 +734,6 @@ EXPORT m64p_error CALL VidExt_GL_GetAttribute(m64p_GLattr Attr, int *pValue)
NewValue = 0;
}
}
#endif
*pValue = NewValue;
return M64ERR_SUCCESS;
}
Expand Down
85 changes: 2 additions & 83 deletions src/main/eventloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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"
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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, ",");
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/main/netplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions src/main/sdl_key_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
5 changes: 1 addition & 4 deletions src/main/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/osd/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ 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)
{
DebugMessage(M64MSG_WARNING, "OSD not compatible with OpenGL core context. OSD deactivated.");
return;
}
#endif

// clear statics
for (i = 0; i < OSD_NUM_CORNERS; i++)
Expand Down

0 comments on commit b1dc082

Please sign in to comment.