diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk index 36f87fe30..907642063 100644 --- a/src/Makefile.d/sdl.mk +++ b/src/Makefile.d/sdl.mk @@ -29,6 +29,8 @@ ifndef NOHW sources+=sdl/ogl_sdl.c endif +NOMIXER=1 + ifdef NOMIXER sources+=sdl/dummy_sound.c else @@ -46,12 +48,16 @@ sources+=sdl/i_threads.c endif ifdef SDL_PKGCONFIG -$(eval $(call Use_pkg_config,SDL)) +$(eval $(call Use_pkg_config,SDL3)) else -SDL_CONFIG?=$(call Prefix,sdl2-config) -SDL_CFLAGS?=$(shell $(SDL_CONFIG) --cflags) -SDL_LDFLAGS?=$(shell $(SDL_CONFIG) \ +#FIXME: this is def not correct +SDL_CFLAGS := -I/usr/local/include/SDL3 +SDL_LDFLAGS := -L/usr/local/lib -lSDL3 +#SDL_CONFIG?=$(call Prefix,sdl2-config) +#SDL_CFLAGS?=$(shell $(SDL_CONFIG) --cflags) +#SDL_LDFLAGS?=$(shell $(SDL_CONFIG) \ $(if $(STATIC),--static-libs,--libs)) + $(eval $(call Propogate_flags,SDL)) endif diff --git a/src/Makefile.d/win32.mk b/src/Makefile.d/win32.mk index 4adcfe6e8..d29e5a883 100644 --- a/src/Makefile.d/win32.mk +++ b/src/Makefile.d/win32.mk @@ -79,14 +79,14 @@ $(eval $(call _set,LIBOPENMPT)) lib:=../libs/SDL2_mixer/$(mingw) ifdef SDL -mixer_opts:=-I$(lib)/include/SDL2 +mixer_opts:=-I$(lib)/include/SDL3 mixer_libs:=-L$(lib)/lib lib:=../libs/SDL2/$(mingw) -SDL_opts:=-I$(lib)/include/SDL2\ +SDL_opts:=-I$(lib)/include/SDL3\ $(mixer_opts) -Dmain=SDL_main SDL_libs:=-L$(lib)/lib $(mixer_libs)\ - -lmingw32 -lSDL2main -lSDL2 -mwindows + -lmingw32 -lSDL3main -lSDL3 -mwindows $(eval $(call _set,SDL)) endif diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 308d69f92..f54b34220 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -27,7 +27,7 @@ extern "C" { #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED -#include "SDL_opengl.h" //Alam_GBC: Simple, yes? +#include //Alam_GBC: Simple, yes? #else #include diff --git a/src/m_menu.c b/src/m_menu.c index d929a6036..8655f69d3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -88,8 +88,8 @@ #include "z_zone.h" #include "mserv.h" -#if defined(HAVE_SDL) -#include "SDL.h" +#if defined (HAVE_SDL) +#include #if SDL_VERSION_ATLEAST(2,0,0) #include "sdl/sdlmain.h" // JOYSTICK_HOTPLUG #endif diff --git a/src/sdl/IMG_xpm.c b/src/sdl/IMG_xpm.c index 7a68185fa..d590e4955 100644 --- a/src/sdl/IMG_xpm.c +++ b/src/sdl/IMG_xpm.c @@ -46,8 +46,8 @@ #include "SDL_image.h" #else // SDLCALL terms removed from original SDL_image declarations -int IMG_isXPM(SDL_RWops *src); -SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src); +int IMG_isXPM(SDL_IOStream *src); +SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src); SDL_Surface *IMG_ReadXPMFromArray(const char **xpm); #define IMG_SetError SDL_SetError #define IMG_GetError SDL_GetError @@ -56,7 +56,7 @@ SDL_Surface *IMG_ReadXPMFromArray(const char **xpm); #ifdef LOAD_XPM /* See if an image is contained in a data source */ -int IMG_isXPM(SDL_RWops *src) +int IMG_isXPM(SDL_IOStream *src) { Sint64 start; int is_XPM; @@ -64,14 +64,14 @@ int IMG_isXPM(SDL_RWops *src) if ( !src ) return 0; - start = SDL_RWtell(src); + start = SDL_TellIO(src); is_XPM = 0; - if ( SDL_RWread(src, magic, sizeof(magic), 1) ) { + if ( SDL_ReadIO(src, magic, sizeof(magic)) ) { if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) { is_XPM = 1; } } - SDL_RWseek(src, start, RW_SEEK_SET); + SDL_SeekIO(src, start, SDL_IO_SEEK_SET); return(is_XPM); } @@ -933,7 +933,7 @@ static const char *error; * If len > 0, it's assumed to be at least len chars (for efficiency). * Return NULL and set error upon EOF or parse error. */ -static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) +static const char *get_next_line(const char ***lines, SDL_IOStream *src, int len) { char *linebufnew; @@ -943,7 +943,7 @@ static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) char c; int n; do { - if (SDL_RWread(src, &c, 1, 1) <= 0) { + if (SDL_ReadIO(src, &c, 1) <= 0) { error = "Premature end of data"; return NULL; } @@ -960,7 +960,7 @@ static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) } linebuf = linebufnew; } - if (SDL_RWread(src, linebuf, len - 1, 1) <= 0) { + if (SDL_ReadIO(src, linebuf, len - 1) <= 0) { error = "Premature end of data"; return NULL; } @@ -980,7 +980,7 @@ static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) } linebuf = linebufnew; } - if (SDL_RWread(src, linebuf + n, 1, 1) <= 0) { + if (SDL_ReadIO(src, linebuf + n, 1) <= 0) { error = "Premature end of data"; return NULL; } @@ -1005,7 +1005,7 @@ do { \ } while (0) /* read XPM from either array or RWops */ -static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) +static SDL_Surface *load_xpm(const char **xpm, SDL_IOStream *src) { Sint64 start = 0; SDL_Surface *image = NULL; @@ -1027,7 +1027,7 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) buflen = 0; if (src) - start = SDL_RWtell(src); + start = SDL_TellIO(src); if (xpm) xpmlines = &xpm; @@ -1065,14 +1065,15 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) /* Create the new surface */ if (ncolors <= 256) { indexed = 1; - image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, - 0, 0, 0, 0); - im_colors = image->format->palette->colors; - image->format->palette->ncolors = ncolors; + image = SDL_CreateSurface(w, h, + SDL_PIXELFORMAT_INDEX8); + SDL_Palette *palette = SDL_CreateSurfacePalette(image); + im_colors = palette->colors; + palette->ncolors = ncolors; } else { indexed = 0; - image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, - 0xff0000, 0x00ff00, 0x0000ff, 0); + image = SDL_CreateSurface(w, h, + SDL_GetPixelFormatForMasks(32, 0xff0000, 0x00ff00, 0x0000ff, 0)); } if (!image) { /* Hmm, some SDL error (out of memory?) */ @@ -1128,7 +1129,7 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) add_colorhash(colors, nextkey, cpp, pixel); nextkey += cpp; if (rgb == 0xffffffff) - SDL_SetColorKey(image, SDL_TRUE, pixel); + SDL_SetSurfaceColorKey(image, true, pixel); break; } } @@ -1164,9 +1165,9 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) done: if (error) { if ( src ) - SDL_RWseek(src, start, RW_SEEK_SET); + SDL_SeekIO(src, start, SDL_IO_SEEK_SET); if ( image ) { - SDL_FreeSurface(image); + SDL_DestroySurface(image); image = NULL; } IMG_SetError("%s", error); @@ -1180,7 +1181,7 @@ done: } /* Load a XPM type image from an RWops datasource */ -SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) +SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src) { if ( !src ) { /* The error message has been set in SDL_RWFromFile */ @@ -1203,14 +1204,14 @@ SDL_Surface *IMG_ReadXPMFromArray(const char **xpm) #else /* not LOAD_XPM */ /* See if an image is contained in a data source */ -int IMG_isXPM(SDL_RWops *src) +int IMG_isXPM(SDL_IOStream *src) { return(0); } /* Load a XPM type image from an SDL datasource */ -SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) +SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src) { return(NULL); } diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index edd685327..4240e0f79 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -27,10 +27,10 @@ #ifdef HAVE_SDL -#include "SDL.h" +#include #ifndef NOLOADSO -#include "SDL_loadso.h" +#include #endif #define _CREATE_DLL_ // necessary for Unix AND Windows diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index cc04dc6a6..f752df353 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -36,7 +36,7 @@ #ifdef HAVE_SDL #ifdef HAVE_TTF -#include "SDL.h" +#include #include "i_ttf.h" #endif diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index a5e8fe2d9..d4337fc2b 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -73,13 +73,15 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED -#include "SDL.h" +#include +#include +#include #ifdef HAVE_TTF #include "i_ttf.h" #endif -#include "SDL_cpuinfo.h" +#include #define HAVE_SDLCPUINFO #if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) @@ -219,13 +221,13 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -SDL_bool consolevent = SDL_FALSE; -SDL_bool framebuffer = SDL_FALSE; +bool consolevent = false; +bool framebuffer = false; UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -SDL_bool stdin_active = SDL_TRUE; +bool stdin_active = true; typedef struct { @@ -288,7 +290,7 @@ static void I_ShutdownConsole(void) if (consolevent) { I_OutputMsg("Shutdown tty console\n"); - consolevent = SDL_FALSE; + consolevent = false; tcsetattr(STDIN_FILENO, TCSADRAIN, &tty_tc); } } @@ -303,11 +305,11 @@ static void I_StartupConsole(void) signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - consolevent = static_cast(!M_CheckParm("-noconsole")); - framebuffer = static_cast( M_CheckParm("-framebuffer")); + consolevent = static_cast(!M_CheckParm("-noconsole")); + framebuffer = static_cast( M_CheckParm("-framebuffer")); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; if (!consolevent) return; @@ -315,7 +317,7 @@ static void I_StartupConsole(void) if (isatty(STDIN_FILENO)!=1) { I_OutputMsg("stdin is not a tty, tty console mode failed\n"); - consolevent = SDL_FALSE; + consolevent = false; return; } @@ -517,7 +519,7 @@ static void I_StartupConsole(void) if (gotConsole) { SetConsoleTitleA("SRB2Kart Console"); - consolevent = SDL_TRUE; + consolevent = true; } //Let get the real console HANDLE, because Mingw's Bash is bad! @@ -550,7 +552,7 @@ static inline void I_StartupConsole(void) framebuffer = M_CheckParm("-framebuffer"); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; } static inline void I_ShutdownConsole(void){} #endif @@ -699,7 +701,7 @@ void I_OutputMsg(const char *fmt, ...) // // I_GetKey // -INT32 I_GetKey (void) +INT32 I_GetKey(void) { // Warning: I_GetKey empties the event queue till next keypress event_t *ev; @@ -729,7 +731,7 @@ static void JoyReset(SDLJoyInfo_t *JoySet) { if (JoySet->dev) { - SDL_GameControllerClose(JoySet->dev); + SDL_CloseGamepad(JoySet->dev); } JoySet->dev = NULL; @@ -771,15 +773,15 @@ void I_JoyScale4(void) } // Cheat to get the device index for a joystick handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) +INT32 I_GetJoystickDeviceIndex(SDL_Gamepad *dev) { SDL_Joystick *joystick = NULL; - joystick = SDL_GameControllerGetJoystick(dev); + joystick = SDL_GetGamepadJoystick(dev); if (joystick) { - return SDL_JoystickInstanceID(joystick); + return SDL_GetJoystickID(joystick); } return -1; @@ -889,7 +891,7 @@ void I_ShutdownJoystick(UINT8 index) */ static int joy_open(int playerIndex, int joyIndex) { - SDL_GameController *newdev = NULL; + SDL_Gamepad *newdev = NULL; int num_joy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) @@ -898,7 +900,7 @@ static int joy_open(int playerIndex, int joyIndex) return -1; } - if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) + if (SDL_WasInit(SDL_INIT_GAMEPAD) == 0) { CONS_Printf(M_GetText("Game Controller subsystem not started\n")); return -1; @@ -907,7 +909,7 @@ static int joy_open(int playerIndex, int joyIndex) if (joyIndex <= 0) return -1; - num_joy = SDL_NumJoysticks(); + SDL_GetJoysticks(&num_joy); if (num_joy == 0) { @@ -915,7 +917,7 @@ static int joy_open(int playerIndex, int joyIndex) return -1; } - newdev = SDL_GameControllerOpen(joyIndex-1); + newdev = SDL_OpenGamepad(joyIndex-1); // Handle the edge case where the device <-> joystick index assignment can change due to hotplugging // This indexing is SDL's responsibility and there's not much we can do about it. @@ -930,8 +932,8 @@ static int joy_open(int playerIndex, int joyIndex) if (JoyInfo[playerIndex].dev) { if (JoyInfo[playerIndex].dev == newdev // same device, nothing to do - || (newdev == NULL && SDL_GameControllerGetAttached(JoyInfo[playerIndex].dev))) // we failed, but already have a working device - return SDL_CONTROLLER_AXIS_MAX; + || (newdev == NULL && SDL_GamepadConnected(JoyInfo[playerIndex].dev))) // we failed, but already have a working device + return SDL_GAMEPAD_AXIS_COUNT; // Else, we're changing devices, so send neutral joy events CONS_Debug(DBG_GAMELOGIC, "Joystick1 device is changing; resetting events...\n"); @@ -948,13 +950,13 @@ static int joy_open(int playerIndex, int joyIndex) } else { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_GameControllerName(JoyInfo[playerIndex].dev)); - JoyInfo[playerIndex].axises = SDL_CONTROLLER_AXIS_MAX; + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_GetGamepadName(JoyInfo[playerIndex].dev)); + JoyInfo[playerIndex].axises = SDL_GAMEPAD_AXIS_COUNT; if (JoyInfo[playerIndex].axises > JOYAXISSET*2) JoyInfo[playerIndex].axises = JOYAXISSET*2; - JoyInfo[playerIndex].buttons = SDL_CONTROLLER_BUTTON_MAX ; // dpad is 4 buttons + JoyInfo[playerIndex].buttons = SDL_GAMEPAD_BUTTON_COUNT; // dpad is 4 buttons if (JoyInfo[playerIndex].buttons > JOYBUTTONS) JoyInfo[playerIndex].buttons = JOYBUTTONS; @@ -974,7 +976,7 @@ static int joy_open(int playerIndex, int joyIndex) void I_InitJoystick(UINT8 index) { UINT8 i; - SDL_GameController *newcontroller = NULL; + SDL_Gamepad *newcontroller = NULL; // not sure if this is the best place to put this SDL_SetHint(SDL_HINT_AUTO_UPDATE_SENSORS, "0"); @@ -992,15 +994,16 @@ void I_InitJoystick(UINT8 index) { CONS_Printf("I_InitJoystick()...\n"); - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + if (!SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); return; } } - if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) + + if (SDL_WasInit(SDL_INIT_GAMEPAD) == 0) { - if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) + if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) { CONS_Printf(M_GetText("Couldn't initialize gamepads: %s\n"), SDL_GetError()); return; @@ -1013,7 +1016,7 @@ void I_InitJoystick(UINT8 index) JoyInfo[index].axises = JoyInfo[index].buttons = JoyInfo[index].hats = JoyInfo[index].balls = 0; if (cv_usejoystick[index].value) - newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); + newcontroller = SDL_OpenGamepad(cv_usejoystick[index].value-1); for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { @@ -1053,7 +1056,7 @@ void I_InitJoystick(UINT8 index) if (i == MAXSPLITSCREENPLAYERS) { // Joystick didn't end up being used - SDL_GameControllerClose(newcontroller); + SDL_CloseGamepad(newcontroller); } } @@ -1088,10 +1091,10 @@ static void I_ShutdownInput(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) I_ShutdownJoystick(i); - if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == SDL_INIT_GAMECONTROLLER) + if (SDL_WasInit(SDL_INIT_GAMEPAD) == SDL_INIT_GAMEPAD) { CONS_Printf("Shutting down gamecontroller system\n"); - SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + SDL_QuitSubSystem(SDL_INIT_GAMEPAD); I_OutputMsg("I_Joystick: SDL's Game Controller system has been shutdown\n"); } @@ -1108,7 +1111,9 @@ INT32 I_NumJoys(void) INT32 numjoy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) - numjoy = SDL_NumJoysticks(); + { + SDL_GetJoysticks(&numjoy); + } return numjoy; } @@ -1123,7 +1128,7 @@ const char *I_GetJoyName(INT32 joyindex) if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { - tempname = SDL_JoystickNameForIndex(joyindex); + tempname = SDL_GetJoystickNameForID(joyindex); if (tempname) { @@ -1143,14 +1148,14 @@ void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, (void)high_strength; (void)duration; #else - SDL_GameController *controller = JoyInfo[playernum].dev; + SDL_Gamepad *controller = JoyInfo[playernum].dev; if (controller == NULL) { return; } - SDL_GameControllerRumble(controller, low_strength, high_strength, duration); + SDL_RumbleGamepad(controller, low_strength, high_strength, duration); #endif } @@ -1162,14 +1167,14 @@ void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 b (void)green; (void)blue; #else - SDL_GameController *controller = JoyInfo[playernum].dev; + SDL_Gamepad *controller = JoyInfo[playernum].dev; if (controller == NULL) { return; } - SDL_GameControllerSetLED(controller, red, green, blue); + SDL_SetGamepadLED(controller, red, green, blue); #endif } @@ -1822,10 +1827,7 @@ static void I_Fork(void) INT32 I_StartupSystem(void) { - SDL_version SDLcompiled; - SDL_version SDLlinked; - SDL_VERSION(&SDLcompiled) - SDL_GetVersion(&SDLlinked); + int SDLlinked = SDL_GetVersion(); I_StartupConsole(); #ifdef NEWSIGNALHANDLER // This is useful when debugging. It lets GDB attach to @@ -1841,15 +1843,15 @@ INT32 I_StartupSystem(void) #endif I_RegisterSignals(); I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", - SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); + SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION); I_OutputMsg("Linked with SDL version: %d.%d.%d\n", - SDLlinked.major, SDLlinked.minor, SDLlinked.patch); + SDL_VERSIONNUM_MAJOR(SDLlinked), SDL_VERSIONNUM_MINOR(SDLlinked), SDL_VERSIONNUM_MICRO(SDLlinked)); #if (SDL_VERSION_ATLEAST(2, 0, 18)) SDL_SetHint(SDL_HINT_APP_NAME, "SRB2Kart Saturn"); #endif - if (SDL_Init(0) < 0) + if (!SDL_Init(0)) I_Error("SRB2: SDL System Error: %s", SDL_GetError()); //Alam: Oh no.... #ifndef NOMUMBLE I_SetupMumble(); @@ -1862,12 +1864,12 @@ INT32 I_StartupSystem(void) // FUNCNORETURN void ATTRNORETURN I_Quit(void) { - static SDL_bool quiting = SDL_FALSE; + static bool quiting = false; /* prevent recursive I_Quit() */ if (quiting) goto death; - SDL_ShowCursor(SDL_TRUE); - quiting = SDL_FALSE; + SDL_ShowCursor(); + quiting = false; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. D_SaveBan(); // save the ban list diff --git a/src/sdl/i_threads.c b/src/sdl/i_threads.c index 078f4e0f4..8755c6e51 100644 --- a/src/sdl/i_threads.c +++ b/src/sdl/i_threads.c @@ -12,7 +12,7 @@ #include "../doomdef.h" #include "../i_threads.h" -#include +#include typedef void * (*Create_fn)(void); @@ -45,7 +45,7 @@ static I_mutex i_thread_pool_mutex; static I_mutex i_mutex_pool_mutex; static I_mutex i_cond_pool_mutex; -static SDL_atomic_t i_threads_running = {1}; +static SDL_AtomicInt i_threads_running = {1}; static Link Insert_link ( @@ -103,13 +103,13 @@ Identity ( ){ void * id; - id = SDL_AtomicGetPtr(anchor); + id = SDL_GetAtomicPointer(anchor); if (! id) { I_lock_mutex(&pool_mutex); { - id = SDL_AtomicGetPtr(anchor); + id = SDL_GetAtomicPointer(anchor); if (! id) { @@ -120,7 +120,7 @@ Identity ( Insert_link(pool_anchor, New_link(id)); - SDL_AtomicSetPtr(anchor, id); + SDL_SetAtomicPointer(anchor, id); } } I_unlock_mutex(pool_mutex); @@ -139,11 +139,11 @@ Worker ( (*th->entry)(th->userdata); - if (SDL_AtomicGet(&i_threads_running)) + if (SDL_GetAtomicInt(&i_threads_running)) { I_lock_mutex(&i_thread_pool_mutex); { - if (SDL_AtomicGet(&i_threads_running)) + if (SDL_GetAtomicInt(&i_threads_running)) { SDL_DetachThread(th->thread); Free_link(&i_thread_pool, link); @@ -176,7 +176,7 @@ I_spawn_thread ( { link = Insert_link(&i_thread_pool, New_link(th)); - if (SDL_AtomicGet(&i_threads_running)) + if (SDL_GetAtomicInt(&i_threads_running)) { th->thread = SDL_CreateThread( (SDL_ThreadFunction)Worker, @@ -194,7 +194,7 @@ I_spawn_thread ( int I_thread_is_stopped (void) { - return ( ! SDL_AtomicGet(&i_threads_running) ); + return ( ! SDL_GetAtomicInt(&i_threads_running) ); } void @@ -220,13 +220,13 @@ I_stop_threads (void) Link next; Thread th; - SDL_mutex * mutex; - SDL_cond * cond; + SDL_Mutex * mutex; + SDL_Condition * cond; if (i_threads_running.value) { /* rely on the good will of thread-san */ - SDL_AtomicSet(&i_threads_running, 0); + SDL_SetAtomicInt(&i_threads_running, 0); I_lock_mutex(&i_thread_pool_mutex); { @@ -267,7 +267,7 @@ I_stop_threads (void) next = link->next; cond = link->data; - SDL_DestroyCond(cond); + SDL_DestroyCondition(cond); free(link); } @@ -282,7 +282,7 @@ void I_lock_mutex ( I_mutex * anchor ){ - SDL_mutex * mutex; + SDL_Mutex * mutex; mutex = Identity( &i_mutex_pool, @@ -291,16 +291,14 @@ I_lock_mutex ( (Create_fn)SDL_CreateMutex ); - if (SDL_LockMutex(mutex) == -1) - abort(); + SDL_LockMutex(mutex); } void I_unlock_mutex ( I_mutex id ){ - if (SDL_UnlockMutex(id) == -1) - abort(); + SDL_UnlockMutex(id); } void @@ -308,49 +306,46 @@ I_hold_cond ( I_cond * cond_anchor, I_mutex mutex_id ){ - SDL_cond * cond; + SDL_Condition * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, cond_anchor, - (Create_fn)SDL_CreateCond + (Create_fn)SDL_CreateCondition ); - if (SDL_CondWait(cond, mutex_id) == -1) - abort(); + SDL_WaitCondition(cond, mutex_id); } void I_wake_one_cond ( I_cond * anchor ){ - SDL_cond * cond; + SDL_Condition * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, anchor, - (Create_fn)SDL_CreateCond + (Create_fn)SDL_CreateCondition ); - if (SDL_CondSignal(cond) == -1) - abort(); + SDL_SignalCondition(cond); } void I_wake_all_cond ( I_cond * anchor ){ - SDL_cond * cond; + SDL_Condition * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, anchor, - (Create_fn)SDL_CreateCond + (Create_fn)SDL_CreateCondition ); - if (SDL_CondBroadcast(cond) == -1) - abort(); + SDL_BroadcastCondition(cond); } diff --git a/src/sdl/i_ttf.c b/src/sdl/i_ttf.c index f2cd497ee..5111d3719 100644 --- a/src/sdl/i_ttf.c +++ b/src/sdl/i_ttf.c @@ -16,7 +16,7 @@ /// \file /// \brief SDL_ttf interface code. Necessary for platforms with no framebuffer console systems. -#if defined(HAVE_SDL) && defined(HAVE_TTF) +#if defined (HAVE_SDL) && defined (HAVE_TTF) #include "SDL.h" #include "SDL_ttf.h" #include "../doomdef.h" @@ -236,14 +236,14 @@ void I_StartupTTF(UINT32 fontpointsize, Uint32 initflags, Uint32 vidmodeflags) // what's the point of trying to display an error? // SDL_ttf is not started, can't display anything to screen (presumably)... - if (SDL_InitSubSystem(initflags) < 0) + if (!SDL_InitSubSystem(initflags)) I_Error("Couldn't initialize SDL: %s\n", SDL_GetError()); TTFSurface = SDL_SetVideoMode(res.width, res.height, bitsperpixel, vidmodeflags); if (!TTFSurface) I_Error("Couldn't set SDL Video resolution: %s\n", SDL_GetError()); - if (TTF_Init() < 0) + if (!TTF_Init()) I_Error("Couldn't start SDL_ttf: %s\n", TTF_GetError()); // look for default font in many directories diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 7d5583b9b..185c8f792 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -26,7 +26,7 @@ #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED -#include "SDL.h" +#include #ifdef HAVE_TTF #include "i_ttf.h" @@ -47,7 +47,7 @@ #include "../doomdef.h" #ifdef _WIN32 -#include "SDL_syswm.h" +#include #endif #include "../doomstat.h" @@ -112,7 +112,7 @@ boolean a2c = false; static void KeyboardLayout_OnChange(void) { if (cv_keyboardlayout.value != 2) - SDL_StopTextInput(); + SDL_StopTextInput(window); HU_Shiftform(); } @@ -139,9 +139,9 @@ UINT8 graphics_started = 0; // Is used in console.c and screen.c // To disable fullscreen at startup; is set in VID_PrepareModeList boolean allow_fullscreen = false; -static SDL_bool disable_fullscreen = SDL_FALSE; +static bool disable_fullscreen = false; #define USE_FULLSCREEN (disable_fullscreen||!allow_fullscreen)? 0: (cv_fullscreen.value == 1) -static SDL_bool disable_mouse = SDL_FALSE; +static bool disable_mouse = false; #define USE_MOUSEINPUT (!disable_mouse && cv_usemouse.value && havefocus) #define MOUSE_MENU false //(!disable_mouse && cv_usemouse.value && menuactive && !USE_FULLSCREEN) #define MOUSEBUTTONS_MAX MOUSEBUTTONS @@ -155,16 +155,16 @@ static UINT32 localPalette[256]; Uint16 realwidth = BASEVIDWIDTH; Uint16 realheight = BASEVIDHEIGHT; #define HalfWarpMouse(x,y) if (wrapmouseok) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) -static SDL_bool usesdl2soft = SDL_FALSE; -static SDL_bool borderlesswindow = SDL_FALSE; +static bool usesdl2soft = false; +static bool borderlesswindow = false; // SDL2 vars SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; -static SDL_bool havefocus = SDL_TRUE; +static bool havefocus = true; -static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); +static bool Impl_CreateWindow(bool fullscreen); static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL @@ -173,8 +173,10 @@ float InvSupersampleFactorX = 0.0; float InvSupersampleFactorY = 0.0; #endif -static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) +static INT32 Impl_SDL_Scancode_To_Keycode(SDL_KeyboardEvent evt) { + SDL_Scancode code = evt.scancode; + if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) { // get lowercase ASCII @@ -266,12 +268,12 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } -static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) +static INT32 Impl_SDL_Keysym_To_Keycode(SDL_KeyboardEvent evt) { - SDL_Keycode keycode = keysym.sym; - SDL_Scancode scancode = keysym.scancode; + SDL_Keycode keycode = evt.key; + SDL_Scancode scancode = evt.scancode; - if (keycode >= SDLK_a && keycode <= SDLK_z) + if (keycode >= SDLK_A && keycode <= SDLK_Z) { // get lowercase ASCII return keycode; @@ -312,7 +314,7 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) case SDLK_AMPERSAND: return '&'; case SDLK_2: return KEY_FR_E_AIGUE; case SDLK_3: - case SDLK_QUOTEDBL: return '"'; + case SDLK_DBLAPOSTROPHE: return '"'; case SDLK_4: return '\''; case SDLK_5: case SDLK_LEFTPAREN: return '('; @@ -341,7 +343,7 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) default: break; } - return Impl_SDL_Scancode_To_Keycode(scancode); + return Impl_SDL_Scancode_To_Keycode(evt); } static boolean native_input_active = false; @@ -356,22 +358,22 @@ void I_SetTextInput(boolean enable) { if (enable && !native_input_active) { - SDL_StartTextInput(); + SDL_StartTextInput(window); native_input_active = true; } else if (!enable && native_input_active) { - SDL_StopTextInput(); + SDL_StopTextInput(window); native_input_active = false; } } // Get the equivalent ASCII (Unicode?) character for a keypress. -static INT32 GetTypedChar(SDL_Keysym keysym) +static INT32 GetTypedChar(SDL_KeyboardEvent evt) { SDL_Event next_event; - SDL_Keycode keycode = keysym.sym; - SDL_Scancode scancode = keysym.scancode; + SDL_Keycode keycode = evt.key; + SDL_Scancode scancode = evt.scancode; // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig) if (native_input_active) @@ -389,7 +391,7 @@ static INT32 GetTypedChar(SDL_Keysym keysym) if (scancode == SDL_SCANCODE_GRAVE) return '`'; - if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT) + if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST) == 1 && next_event.type == SDL_EVENT_TEXT_INPUT) { if (next_event.text.text[1] == '\0') // limit to ASCII { @@ -399,7 +401,7 @@ static INT32 GetTypedChar(SDL_Keysym keysym) } // otherwise fallback to scancodes - return Impl_SDL_Scancode_To_Keycode(scancode); + return Impl_SDL_Scancode_To_Keycode(evt); } static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) @@ -452,37 +454,38 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { #define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) - static SDL_bool firsttimeonmouse = SDL_TRUE; - static SDL_bool mousefocus = SDL_TRUE; - static SDL_bool kbfocus = SDL_TRUE; - static SDL_bool windowmoved = SDL_FALSE; + static bool firsttimeonmouse = true; + static bool mousefocus = true; + static bool kbfocus = true; + static bool windowmoved = false; const unsigned int oldfocus = FOCUSUNION; - switch (evt.event) + switch (evt.type) { - case SDL_WINDOWEVENT_ENTER: - mousefocus = SDL_TRUE; + case SDL_EVENT_WINDOW_MOUSE_ENTER: + mousefocus = true; break; - case SDL_WINDOWEVENT_LEAVE: - mousefocus = SDL_FALSE; + case SDL_EVENT_WINDOW_MOUSE_LEAVE: + mousefocus = false; break; - case SDL_WINDOWEVENT_FOCUS_GAINED: - kbfocus = SDL_TRUE; - mousefocus = SDL_TRUE; + case SDL_EVENT_WINDOW_FOCUS_GAINED: + kbfocus = true; + mousefocus = true; if (!cv_mousevisible.value) - SDL_ShowCursor(SDL_FALSE); + SDL_HideCursor(); break; - case SDL_WINDOWEVENT_FOCUS_LOST: - kbfocus = SDL_FALSE; - mousefocus = SDL_FALSE; - SDL_ShowCursor(SDL_TRUE); + case SDL_EVENT_WINDOW_FOCUS_LOST: + kbfocus = false; + mousefocus = false; + SDL_ShowCursor(); break; - case SDL_WINDOWEVENT_MAXIMIZED: - break; - case SDL_WINDOWEVENT_MOVED: - windowmoved = SDL_TRUE; + //case SDL_EVENT_WINDOW_DISPLAY_CHANGED: + case SDL_EVENT_WINDOW_MOVED: + windowmoved = true; break; + default: + return; } if (FOCUSUNION == oldfocus) // No state change @@ -505,7 +508,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #endif #endif - windowmoved = SDL_FALSE; + windowmoved = false; } if (mousefocus && kbfocus) @@ -545,10 +548,10 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) switch (type) { - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: event.type = ev_keyup; break; - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: event.type = ev_keydown; break; default: @@ -558,13 +561,13 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) switch (cv_keyboardlayout.value) { case 2: // "native" - event.data1 = GetTypedChar(evt.keysym); + event.data1 = GetTypedChar(evt); break; case 3: // AZERTY - event.data1 = Impl_SDL_Keysym_To_Keycode(evt.keysym); + event.data1 = Impl_SDL_Keysym_To_Keycode(evt); break; default: - event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode); + event.data1 = Impl_SDL_Scancode_To_Keycode(evt); break; } @@ -583,28 +586,29 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (!windowinfocus) { - SDL_ShowCursor(SDL_ENABLE); - SDL_SetWindowGrab(window, SDL_FALSE); - SDL_SetRelativeMouseMode(SDL_FALSE); + SDL_ShowCursor(); + SDL_SetWindowMouseGrab(window, false); + SDL_SetWindowRelativeMouseMode(window, false); 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()) + if (SDL_GetWindowRelativeMouseMode(window)) { if (windowinfocus) { mousemovex += evt.xrel; mousemovey += -evt.yrel; - SDL_SetWindowGrab(window, SDL_TRUE); + SDL_SetWindowMouseGrab(window, true); } + return; } // 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)) + if (((int)evt.x == realwidth/2) && ((int)evt.y == realheight/2)) { return; } @@ -615,9 +619,9 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) // -- Monster Iestyn if (windowinfocus) { - SDL_ShowCursor(SDL_DISABLE); - SDL_SetWindowGrab(window, SDL_TRUE); - SDL_SetRelativeMouseMode(SDL_TRUE); + SDL_HideCursor(); + SDL_SetWindowMouseGrab(window, true); + SDL_SetWindowRelativeMouseMode(window, true); } } @@ -638,10 +642,10 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) { switch (type) { - case SDL_MOUSEBUTTONUP: + case SDL_EVENT_MOUSE_BUTTON_UP: event.type = ev_keyup; break; - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_DOWN: event.type = ev_keydown; break; default: @@ -680,19 +684,19 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) if (USE_MOUSEINPUT) { - if (evt.y > 0) + int y = evt.y; + + if (y > 0) { event.data1 = KEY_MOUSEWHEELUP; event.type = ev_keydown; } - - if (evt.y < 0) + else if (y < 0) { event.data1 = KEY_MOUSEWHEELDOWN; event.type = ev_keydown; } - - if (evt.y == 0) + else if (y == 0) { event.data1 = 0; event.type = ev_keyup; @@ -716,12 +720,12 @@ void I_HandleControllerHatRepeat(void) event_t event = {ev_keydown, 0, 0, 0}; - static const SDL_GameControllerButton hatbutt[4] = + static const SDL_GamepadButton hatbutt[4] = { - SDL_CONTROLLER_BUTTON_DPAD_UP, - SDL_CONTROLLER_BUTTON_DPAD_DOWN, - SDL_CONTROLLER_BUTTON_DPAD_LEFT, - SDL_CONTROLLER_BUTTON_DPAD_RIGHT + SDL_GAMEPAD_BUTTON_DPAD_UP, + SDL_GAMEPAD_BUTTON_DPAD_DOWN, + SDL_GAMEPAD_BUTTON_DPAD_LEFT, + SDL_GAMEPAD_BUTTON_DPAD_RIGHT }; for (int i = 0; i < MAXSPLITSCREENPLAYERS; i++) @@ -729,14 +733,14 @@ void I_HandleControllerHatRepeat(void) if (!cv_usejoystick[i].value) continue; - SDL_GameController *controller = JoyInfo[i].dev; + SDL_Gamepad *controller = JoyInfo[i].dev; if (!controller) continue; for (UINT8 h = 0; h < JOYHATS; h++) { - if (SDL_GameControllerGetButton(controller, hatbutt[h])) + if (SDL_GetGamepadButton(controller, hatbutt[h])) { if (hatrepeattimer[i] < HATREPEATDELAY) { @@ -756,7 +760,7 @@ void I_HandleControllerHatRepeat(void) } } -static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) +static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt) { event_t event; INT32 value; @@ -785,27 +789,27 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) value = SDLJoyAxis(evt.value, event.type); switch (evt.axis) { - case SDL_CONTROLLER_AXIS_LEFTX: + case SDL_GAMEPAD_AXIS_LEFTX: event.data1 = 0; event.data2 = value; break; - case SDL_CONTROLLER_AXIS_LEFTY: + case SDL_GAMEPAD_AXIS_LEFTY: event.data1 = 0; event.data3 = value; break; - case SDL_CONTROLLER_AXIS_RIGHTX: + case SDL_GAMEPAD_AXIS_RIGHTX: event.data1 = 1; event.data2 = value; break; - case SDL_CONTROLLER_AXIS_RIGHTY: + case SDL_GAMEPAD_AXIS_RIGHTY: event.data1 = 1; event.data3 = value; break; - case SDL_CONTROLLER_AXIS_TRIGGERLEFT: + case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: event.data1 = 2; event.data2 = value; break; - case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: event.data1 = 2; event.data3 = value; break; @@ -816,7 +820,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) D_PostEvent(&event); } -static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 type) +static void Impl_HandleControllerHatEvent(SDL_GamepadButtonEvent evt, Uint32 type) { event_t event = {0}; UINT8 i; @@ -837,10 +841,10 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 switch (type) { - case SDL_CONTROLLERBUTTONUP: + case SDL_EVENT_GAMEPAD_BUTTON_UP: event.type = ev_keyup; break; - case SDL_CONTROLLERBUTTONDOWN: + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: event.type = ev_keydown; break; default: @@ -849,15 +853,15 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 switch (evt.button) { - case SDL_CONTROLLER_BUTTON_DPAD_UP: + case SDL_GAMEPAD_BUTTON_DPAD_UP: break; - case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + case SDL_GAMEPAD_BUTTON_DPAD_DOWN: event.data1 += 1; break; - case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + case SDL_GAMEPAD_BUTTON_DPAD_LEFT: event.data1 += 2; break; - case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: event.data1 += 3; break; default: @@ -870,15 +874,15 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 } } -static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type) +static void Impl_HandleControllerButtonEvent(SDL_GamepadButtonEvent evt, Uint32 type) { event_t event = {0}; UINT8 i; static const int buttons_base[] = {KEY_JOY1, KEY_2JOY1, KEY_3JOY1, KEY_4JOY1}; // dpad special case handling - if (evt.button >= SDL_CONTROLLER_BUTTON_DPAD_UP && - evt.button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT) + if (evt.button >= SDL_GAMEPAD_BUTTON_DPAD_UP && + evt.button <= SDL_GAMEPAD_BUTTON_DPAD_RIGHT) { Impl_HandleControllerHatEvent(evt, type); return; @@ -899,10 +903,10 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint switch (type) { - case SDL_CONTROLLERBUTTONUP: + case SDL_EVENT_GAMEPAD_BUTTON_UP: event.type = ev_keyup; break; - case SDL_CONTROLLERBUTTONDOWN: + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: event.type = ev_keydown; break; default: @@ -927,7 +931,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) INT32 i; // OH BOY are you in for a good time! #abominationstation - SDL_GameController *newcontroller = SDL_GameControllerOpen(evt.cdevice.which); + SDL_Gamepad *newcontroller = SDL_OpenGamepad(evt.cdevice.which); CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); @@ -944,7 +948,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (newcontroller && (!JoyInfo[i].dev || !SDL_GameControllerGetAttached(JoyInfo[i].dev))) + if (newcontroller && (!JoyInfo[i].dev || !SDL_GamepadConnected(JoyInfo[i].dev))) { UINT8 j; @@ -1011,7 +1015,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) } if (i == MAXSPLITSCREENPLAYERS) - SDL_GameControllerClose(newcontroller); + SDL_CloseGamepad(newcontroller); } static void Impl_HandleControllerRemovedEvent(void) @@ -1020,7 +1024,7 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (JoyInfo[i].dev && !SDL_GameControllerGetAttached(JoyInfo[i].dev)) + if (JoyInfo[i].dev && !SDL_GamepadConnected(JoyInfo[i].dev)) { CONS_Debug(DBG_GAMELOGIC, "Joystick%d removed, device index: %d\n", i+1, JoyInfo[i].oldjoy); I_ShutdownJoystick(i); @@ -1070,7 +1074,7 @@ static void Impl_HandleControllerRemovedEvent(void) void I_GetEvent(void) { SDL_Event evt; - char* dropped_filedir; + const char* dropped_filedir; if (!graphics_started) { @@ -1083,45 +1087,44 @@ void I_GetEvent(void) { switch (evt.type) { - case SDL_WINDOWEVENT: - Impl_HandleWindowEvent(evt.window); - break; - case SDL_KEYUP: - case SDL_KEYDOWN: + case SDL_EVENT_KEY_UP: + case SDL_EVENT_KEY_DOWN: Impl_HandleKeyboardEvent(evt.key, evt.type); break; - case SDL_MOUSEMOTION: + case SDL_EVENT_MOUSE_MOTION: Impl_HandleMouseMotionEvent(evt.motion); break; - case SDL_MOUSEBUTTONUP: - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_UP: + case SDL_EVENT_MOUSE_BUTTON_DOWN: Impl_HandleMouseButtonEvent(evt.button, evt.type); break; - case SDL_MOUSEWHEEL: + case SDL_EVENT_MOUSE_WHEEL: Impl_HandleMouseWheelEvent(evt.wheel); break; - case SDL_CONTROLLERAXISMOTION: - Impl_HandleControllerAxisEvent(evt.caxis); + case SDL_EVENT_GAMEPAD_AXIS_MOTION: + Impl_HandleControllerAxisEvent(evt.gaxis); break; - case SDL_CONTROLLERBUTTONUP: - case SDL_CONTROLLERBUTTONDOWN: - Impl_HandleControllerButtonEvent(evt.cbutton, evt.type); + case SDL_EVENT_GAMEPAD_BUTTON_UP: + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: + Impl_HandleControllerButtonEvent(evt.gbutton, evt.type); break; - case SDL_CONTROLLERDEVICEADDED: + case SDL_EVENT_GAMEPAD_ADDED: Impl_HandleControllerAddedEvent(evt); break; - case SDL_CONTROLLERDEVICEREMOVED: + case SDL_EVENT_GAMEPAD_REMOVED: Impl_HandleControllerRemovedEvent(); break; - case SDL_DROPFILE: - dropped_filedir = evt.drop.file; + case SDL_EVENT_DROP_FILE: + dropped_filedir = evt.drop.data; P_AddWadFile(dropped_filedir, false); - SDL_free(dropped_filedir); // Free dropped_filedir memory break; - case SDL_QUIT: + case SDL_EVENT_QUIT: I_Quit(); M_QuitResponse('y'); break; + default: + Impl_HandleWindowEvent(evt.window); + break; } } @@ -1149,12 +1152,12 @@ void I_StartupMouse(void) return; if (!cv_mousevisible.value) - SDL_ShowCursor(SDL_FALSE); + SDL_HideCursor(); else - SDL_ShowCursor(SDL_TRUE); + SDL_ShowCursor(); - SDL_SetWindowGrab(window, SDL_FALSE); - SDL_SetRelativeMouseMode(SDL_FALSE); + SDL_SetWindowMouseGrab(window, false); + SDL_SetWindowRelativeMouseMode(window, false); } // @@ -1167,9 +1170,9 @@ void I_OsPolling(void) if (consolevent) I_GetConsoleEvents(); - if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER)) + if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMEPAD) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMEPAD)) { - SDL_GameControllerUpdate(); + SDL_UpdateGamepads(); } I_GetEvent(); @@ -1180,18 +1183,18 @@ void I_OsPolling(void) shiftdown = ctrldown = altdown = 0; capslock = false; - if (mod & KMOD_LSHIFT) shiftdown |= 1; - if (mod & KMOD_RSHIFT) shiftdown |= 2; - if (mod & KMOD_LCTRL) ctrldown |= 1; - if (mod & KMOD_RCTRL) ctrldown |= 2; - if (mod & KMOD_LALT) altdown |= 1; - if (mod & KMOD_RALT) altdown |= 2; - if (mod & KMOD_CAPS) capslock = true; + if (mod & SDL_KMOD_LSHIFT) shiftdown |= 1; + if (mod & SDL_KMOD_RSHIFT) shiftdown |= 2; + if (mod & SDL_KMOD_LCTRL) ctrldown |= 1; + if (mod & SDL_KMOD_RCTRL) ctrldown |= 2; + if (mod & SDL_KMOD_LALT) altdown |= 1; + if (mod & SDL_KMOD_RALT) altdown |= 2; + if (mod & SDL_KMOD_CAPS) capslock = true; } static void VID_Command_NumModes_f (void) { - CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes()); + CONS_Printf("%d video mode(s) available(s)\n", VID_NumModes()); } static void VID_Command_ModeList_f(void) @@ -1231,26 +1234,28 @@ static void VID_Command_Mode_f (void) static void I_CheckDesktopRes(void) { int currentDisplayIndex = -1; - SDL_DisplayMode curmode; + const SDL_DisplayMode *curmode; desktopwidth = 0; desktopheight = 0; - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + currentDisplayIndex = SDL_GetDisplayForWindow(window); // No valid index - if (currentDisplayIndex < 0) + if (!currentDisplayIndex) { return; } - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) + curmode = SDL_GetCurrentDisplayMode(currentDisplayIndex); + + if (!curmode) { return; } - desktopwidth = curmode.w; - desktopheight = curmode.h; + desktopwidth = curmode->w; + desktopheight = curmode->h; } // Check if the game resolution matches the desktop resolution @@ -1315,9 +1320,9 @@ static void I_ResetFBOSurface(void) } #endif -static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) +static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) { - static SDL_bool wasfullscreen = SDL_FALSE; + static bool wasfullscreen = false; int sw_texture_format = SDL_PIXELFORMAT_ABGR8888; realwidth = vid.width; @@ -1327,24 +1332,26 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { if (fullscreen) { - wasfullscreen = SDL_TRUE; - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + wasfullscreen = true; + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); I_SetBorderlessWindow(); } else // windowed mode { if (wasfullscreen) { - wasfullscreen = SDL_FALSE; + wasfullscreen = false; SDL_SetWindowFullscreen(window, 0); I_SetBorderlessWindow(); } + SDL_DisplayID displayid = SDL_GetDisplayForWindow(window); + // Reposition window only in windowed mode SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) + SDL_WINDOWPOS_CENTERED_DISPLAY(displayid), + SDL_WINDOWPOS_CENTERED_DISPLAY(displayid) ); } } @@ -1356,7 +1363,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) if (fullscreen) { - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); I_SetBorderlessWindow(); } } @@ -1375,7 +1382,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) if (rendermode == render_soft) { SDL_RenderClear(renderer); - SDL_RenderSetLogicalSize(renderer, width, height); + SDL_SetRenderLogicalPresentation(renderer, width, height, SDL_LOGICAL_PRESENTATION_LETTERBOX); // Set up Texture realwidth = width; @@ -1393,7 +1400,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) // // I_FinishUpdate // -static SDL_Rect src_rect = { 0, 0, 0, 0 }; +static SDL_FRect src_rect = { 0, 0, 0, 0 }; void I_FinishUpdate(void) { @@ -1446,7 +1453,7 @@ void I_FinishUpdate(void) SDL_UnlockTexture(texture); SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, &src_rect, NULL); + SDL_RenderTexture(renderer, texture, &src_rect, NULL); SDL_RenderPresent(renderer); } } @@ -1586,17 +1593,18 @@ static int IsCustomResolutionInList(int list_size) // static void I_FillScreenResolutionsList(boolean force) { - int currentDisplayIndex = -1; - static int oldDisplayIndex = -1; + SDL_DisplayID currentDisplayIndex = -1; + static SDL_DisplayID oldDisplayIndex = -1; SDL_DisplayMode mode; + SDL_DisplayMode **displaymodes = NULL; int i = 0, list_size = 0; int count = 0; char custom_resolution[10]; - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + currentDisplayIndex = SDL_GetDisplayForWindow(window); // No valid index - if (currentDisplayIndex < 0) + if (!currentDisplayIndex) { return; } @@ -1610,7 +1618,12 @@ static void I_FillScreenResolutionsList(boolean force) oldDisplayIndex = currentDisplayIndex; // Don't call SDL_ListModes if SDL has not been initialized - count = SDL_GetNumDisplayModes(currentDisplayIndex); + displaymodes = SDL_GetFullscreenDisplayModes(currentDisplayIndex, &count); + + if (!displaymodes) + { + return; + } list_size = 0; @@ -1627,18 +1640,20 @@ static void I_FillScreenResolutionsList(boolean force) { mode.w = canonicals[i - count].w; mode.h = canonicals[i - count].h; + + I_AppendResolution(&mode, &list_size); } else { - SDL_GetDisplayMode(currentDisplayIndex, i, &mode); + I_AppendResolution(displaymodes[i], &list_size); } - - I_AppendResolution(&mode, &list_size); } windowedModes[list_size].name[0] = '\0'; } + SDL_free(displaymodes); + const int customresinlist = IsCustomResolutionInList(list_size); if (customresinlist == 0) @@ -1748,8 +1763,8 @@ void VID_PrepareModeList(void) static UINT32 refresh_rate; static UINT32 VID_GetRefreshRate(void) { - int index = SDL_GetWindowDisplayIndex(window); - SDL_DisplayMode m; + int index = SDL_GetDisplayForWindow(window); + const SDL_DisplayMode *displaymode = NULL; if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { @@ -1757,13 +1772,15 @@ static UINT32 VID_GetRefreshRate(void) return 0; } - if (SDL_GetDesktopDisplayMode(index, &m) != 0) + displaymode = SDL_GetDesktopDisplayMode(index); + + if (!displaymode) { // Error has occurred. return 0; } - return m.refresh_rate; + return displaymode->refresh_rate; } INT32 VID_SetMode(INT32 modeNum) @@ -1779,18 +1796,18 @@ INT32 VID_SetMode(INT32 modeNum) else { // just set the desktop resolution as a fallback - SDL_DisplayMode mode; - SDL_GetWindowDisplayMode(window, &mode); + const SDL_DisplayMode *mode = NULL; + mode = SDL_GetWindowFullscreenMode(window); - if (mode.w >= 2048) + if (mode->w >= 2048) { vid.width = 1920; vid.height = 1200; } else { - vid.width = mode.w; - vid.height = mode.h; + vid.width = mode->w; + vid.height = mode->h; } vid.modenum = -1; @@ -1803,10 +1820,10 @@ INT32 VID_SetMode(INT32 modeNum) refresh_rate = VID_GetRefreshRate(); - return SDL_TRUE; + return true; } -static SDL_bool Impl_CreateContext(void) +static bool Impl_CreateContext(void) { // Renderer-specific stuff #ifdef HWRENDER @@ -1822,7 +1839,7 @@ static SDL_bool Impl_CreateContext(void) I_Error("Failed to create a GL context: %s\n", SDL_GetError()); } - if (SDL_GL_MakeCurrent(window, sdlglcontext) < 0) + if (!SDL_GL_MakeCurrent(window, sdlglcontext)) { SDL_DestroyWindow(window); I_Error("Failed to set up GL context: %s\n", SDL_GetError()); @@ -1831,68 +1848,60 @@ static SDL_bool Impl_CreateContext(void) // be sure to fill the resolution list the moment we have a window I_FillScreenResolutionsList(false); - return SDL_TRUE; + return true; } #endif if (rendermode == render_soft) { - int flags = 0; // Use this to set SDL_RENDERER_* flags now - - if (usesdl2soft) - { - flags |= SDL_RENDERER_SOFTWARE; - } - else if (cv_vidwait.value) - { -#if SDL_VERSION_ATLEAST(2, 0, 18) - // If SDL is new enough, we can turn off vsync later. - flags |= SDL_RENDERER_PRESENTVSYNC; -#else - // However, if it isn't, we should just silently turn vid_wait off - // This is because the renderer will be created before the config - // is read and vid_wait is set from the user's preferences, and thus - // vid_wait will have no effect. - CV_StealthSetValue(&cv_vidwait, 0); -#endif - } - -#ifdef _WIN32 - SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11"); -#else - SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); -#endif - if (!renderer) - renderer = SDL_CreateRenderer(window, -1, flags); + { + SDL_PropertiesID props = SDL_CreateProperties(); + if (props == 0) + { + I_Error("Couldn't create rendering properties: %s", SDL_GetError()); + return false; + } +#ifdef _WIN32 + SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, "direct3d11"); +#else + SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, "opengles2"); +#endif + if (usesdl2soft) + SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, "SDL_SOFTWARE_RENDERER"); + + SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, cv_vidwait.value); + SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window); + renderer = SDL_CreateRendererWithProperties(props); + } if (renderer == NULL) { I_Error("Couldn't create rendering context: %s\n", SDL_GetError()); } - SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT); + SDL_SetRenderLogicalPresentation(renderer, BASEVIDWIDTH, BASEVIDHEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX); // be sure to fill the resolution list the moment we have a window I_FillScreenResolutionsList(false); - return SDL_TRUE; + return true; } - return SDL_FALSE; + return false; } -static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) +static bool Impl_CreateWindow(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 + return true; // Monster Iestyn -- not sure if it really matters what we return here tbh if (window != NULL) - return SDL_FALSE; + return false; if (fullscreen) - flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + flags |= SDL_WINDOW_FULLSCREEN; if (borderlesswindow) flags |= SDL_WINDOW_BORDERLESS; @@ -1919,7 +1928,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) #endif // Create a window - window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, realwidth, realheight, flags); + window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, realwidth, realheight, flags); if (window == NULL) { @@ -1968,7 +1977,7 @@ void I_StartupGraphics(void) #if !defined(HAVE_TTF) // Previously audio was init here for questionable reasons? - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { CONS_Printf(M_GetText("Couldn't initialize SDL's Video System: %s\n"), SDL_GetError()); return; @@ -1979,7 +1988,7 @@ void I_StartupGraphics(void) //CONS_Printf(M_GetText("Starting up with video driver: %s\n"), vd); if (vd && (strncasecmp(vd, "fbcon", 6) == 0)) - framebuffer = SDL_TRUE; + framebuffer = true; } if (M_CheckParm("-software")) @@ -2156,7 +2165,7 @@ void I_StartupGraphics(void) graphics_started = true; - SDL_StopTextInput(); + SDL_StopTextInput(window); } void I_ShutdownGraphics(void) @@ -2164,7 +2173,7 @@ void I_ShutdownGraphics(void) rendermode = render_none; if (icoSurface) - SDL_FreeSurface(icoSurface); + SDL_DestroySurface(icoSurface); icoSurface = NULL; I_OutputMsg("I_ShutdownGraphics(): "); @@ -2184,7 +2193,7 @@ void I_ShutdownGraphics(void) HWR_Shutdown(); if (sdlglcontext) - SDL_GL_DeleteContext(sdlglcontext); + SDL_GL_DestroyContext(sdlglcontext); sdlglcontext = NULL; #endif @@ -2199,7 +2208,7 @@ void I_ShutdownGraphics(void) window = NULL; SDL_QuitSubSystem(SDL_INIT_VIDEO); - framebuffer = SDL_FALSE; + framebuffer = false; } UINT32 I_GetRefreshRate(void) @@ -2216,7 +2225,7 @@ static void Impl_SetVsync(void) { #if SDL_VERSION_ATLEAST(2,0,18) if (renderer) - SDL_RenderSetVSync(renderer, cv_vidwait.value); + SDL_SetRenderVSync(renderer, cv_vidwait.value); #endif #ifdef HWRENDER if (!renderer && rendermode == render_opengl && @@ -2229,7 +2238,7 @@ static void Impl_SetVsync(void) void I_SetBorderlessWindow(void) { - SDL_bool borderless = (cv_fullscreen.value == 2) ? SDL_FALSE : SDL_TRUE; + bool borderless = (cv_fullscreen.value == 2) ? false : true; SDL_SetWindowBordered(window, borderless); } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index b63166639..b95827131 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -20,7 +20,7 @@ #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED -#include "SDL.h" +#include #include "sdlmain.h" @@ -96,7 +96,7 @@ boolean VID_LoadOGLAPI(void) if (M_CheckParm("-OGLlib") && M_IsNextParm()) OGLLibname = M_GetNextParm(); - if (SDL_GL_LoadLibrary(OGLLibname) != 0) + if (!SDL_GL_LoadLibrary(OGLLibname)) { CONS_Alert(CONS_ERROR, "Could not load OpenGL Library: %s\n", SDL_GetError()); if (!M_CheckParm("-OGLlib")) diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index c711d68d7..67aa72309 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -23,14 +23,16 @@ extern "C" { #endif -extern SDL_bool consolevent; -extern SDL_bool framebuffer; +extern bool consolevent; +extern bool framebuffer; #include "../m_fixed.h" // SDL2 stub macro #define SDL2STUB() CONS_Printf("SDL2: stubbed: %s:%d\n", __func__, __LINE__) +#include + // So m_menu knows whether to store cv_usejoystick value or string #define JOYSTICK_HOTPLUG @@ -41,9 +43,9 @@ extern SDL_bool framebuffer; typedef struct SDLJoyInfo_s { /// Controller handle - SDL_GameController *dev; + SDL_Gamepad *dev; /// Controller index - INT32 id; + SDL_JoystickID id; /// number of old joystick int oldjoy; /// number of axies @@ -71,7 +73,7 @@ extern SDLJoyInfo_t JoyInfo[4]; //MAXSPLITSCREENPLAYERS void I_ShutdownJoystick(UINT8 index); // Cheat to get the device index for a game controller handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev); +INT32 I_GetJoystickDeviceIndex(SDL_Gamepad *dev); // Quick thing to make SDL_JOYDEVICEADDED events less of an abomination void I_UpdateJoystickDeviceIndex(UINT8 player);