diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk index 907642063..36f87fe30 100644 --- a/src/Makefile.d/sdl.mk +++ b/src/Makefile.d/sdl.mk @@ -29,8 +29,6 @@ ifndef NOHW sources+=sdl/ogl_sdl.c endif -NOMIXER=1 - ifdef NOMIXER sources+=sdl/dummy_sound.c else @@ -48,16 +46,12 @@ sources+=sdl/i_threads.c endif ifdef SDL_PKGCONFIG -$(eval $(call Use_pkg_config,SDL3)) +$(eval $(call Use_pkg_config,SDL)) else -#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) \ +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 d29e5a883..4adcfe6e8 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/SDL3 +mixer_opts:=-I$(lib)/include/SDL2 mixer_libs:=-L$(lib)/lib lib:=../libs/SDL2/$(mingw) -SDL_opts:=-I$(lib)/include/SDL3\ +SDL_opts:=-I$(lib)/include/SDL2\ $(mixer_opts) -Dmain=SDL_main SDL_libs:=-L$(lib)/lib $(mixer_libs)\ - -lmingw32 -lSDL3main -lSDL3 -mwindows + -lmingw32 -lSDL2main -lSDL2 -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 f54b34220..308d69f92 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 //Alam_GBC: Simple, yes? +#include "SDL_opengl.h" //Alam_GBC: Simple, yes? #else #include diff --git a/src/m_menu.c b/src/m_menu.c index 4c3b54120..3cdc45169 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 +#if defined(HAVE_SDL) +#include "SDL.h" #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 d590e4955..7a68185fa 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_IOStream *src); -SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src); +int IMG_isXPM(SDL_RWops *src); +SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *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_IOStream *src) +int IMG_isXPM(SDL_RWops *src) { Sint64 start; int is_XPM; @@ -64,14 +64,14 @@ int IMG_isXPM(SDL_IOStream *src) if ( !src ) return 0; - start = SDL_TellIO(src); + start = SDL_RWtell(src); is_XPM = 0; - if ( SDL_ReadIO(src, magic, sizeof(magic)) ) { + if ( SDL_RWread(src, magic, sizeof(magic), 1) ) { if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) { is_XPM = 1; } } - SDL_SeekIO(src, start, SDL_IO_SEEK_SET); + SDL_RWseek(src, start, RW_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_IOStream *src, int len) +static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) { char *linebufnew; @@ -943,7 +943,7 @@ static const char *get_next_line(const char ***lines, SDL_IOStream *src, int len char c; int n; do { - if (SDL_ReadIO(src, &c, 1) <= 0) { + if (SDL_RWread(src, &c, 1, 1) <= 0) { error = "Premature end of data"; return NULL; } @@ -960,7 +960,7 @@ static const char *get_next_line(const char ***lines, SDL_IOStream *src, int len } linebuf = linebufnew; } - if (SDL_ReadIO(src, linebuf, len - 1) <= 0) { + if (SDL_RWread(src, linebuf, len - 1, 1) <= 0) { error = "Premature end of data"; return NULL; } @@ -980,7 +980,7 @@ static const char *get_next_line(const char ***lines, SDL_IOStream *src, int len } linebuf = linebufnew; } - if (SDL_ReadIO(src, linebuf + n, 1) <= 0) { + if (SDL_RWread(src, linebuf + n, 1, 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_IOStream *src) +static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) { Sint64 start = 0; SDL_Surface *image = NULL; @@ -1027,7 +1027,7 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_IOStream *src) buflen = 0; if (src) - start = SDL_TellIO(src); + start = SDL_RWtell(src); if (xpm) xpmlines = &xpm; @@ -1065,15 +1065,14 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_IOStream *src) /* Create the new surface */ if (ncolors <= 256) { indexed = 1; - image = SDL_CreateSurface(w, h, - SDL_PIXELFORMAT_INDEX8); - SDL_Palette *palette = SDL_CreateSurfacePalette(image); - im_colors = palette->colors; - palette->ncolors = ncolors; + image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, + 0, 0, 0, 0); + im_colors = image->format->palette->colors; + image->format->palette->ncolors = ncolors; } else { indexed = 0; - image = SDL_CreateSurface(w, h, - SDL_GetPixelFormatForMasks(32, 0xff0000, 0x00ff00, 0x0000ff, 0)); + image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, + 0xff0000, 0x00ff00, 0x0000ff, 0); } if (!image) { /* Hmm, some SDL error (out of memory?) */ @@ -1129,7 +1128,7 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_IOStream *src) add_colorhash(colors, nextkey, cpp, pixel); nextkey += cpp; if (rgb == 0xffffffff) - SDL_SetSurfaceColorKey(image, true, pixel); + SDL_SetColorKey(image, SDL_TRUE, pixel); break; } } @@ -1165,9 +1164,9 @@ static SDL_Surface *load_xpm(const char **xpm, SDL_IOStream *src) done: if (error) { if ( src ) - SDL_SeekIO(src, start, SDL_IO_SEEK_SET); + SDL_RWseek(src, start, RW_SEEK_SET); if ( image ) { - SDL_DestroySurface(image); + SDL_FreeSurface(image); image = NULL; } IMG_SetError("%s", error); @@ -1181,7 +1180,7 @@ done: } /* Load a XPM type image from an RWops datasource */ -SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src) +SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) { if ( !src ) { /* The error message has been set in SDL_RWFromFile */ @@ -1204,14 +1203,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_IOStream *src) +int IMG_isXPM(SDL_RWops *src) { return(0); } /* Load a XPM type image from an SDL datasource */ -SDL_Surface *IMG_LoadXPM_RW(SDL_IOStream *src) +SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) { return(NULL); } diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 4240e0f79..edd685327 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -27,10 +27,10 @@ #ifdef HAVE_SDL -#include +#include "SDL.h" #ifndef NOLOADSO -#include +#include "SDL_loadso.h" #endif #define _CREATE_DLL_ // necessary for Unix AND Windows diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index f752df353..cc04dc6a6 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -36,7 +36,7 @@ #ifdef HAVE_SDL #ifdef HAVE_TTF -#include +#include "SDL.h" #include "i_ttf.h" #endif diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index d4337fc2b..a5e8fe2d9 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -73,15 +73,13 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #ifdef HAVE_SDL #define _MATH_DEFINES_DEFINED -#include -#include -#include +#include "SDL.h" #ifdef HAVE_TTF #include "i_ttf.h" #endif -#include +#include "SDL_cpuinfo.h" #define HAVE_SDLCPUINFO #if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) @@ -221,13 +219,13 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -bool consolevent = false; -bool framebuffer = false; +SDL_bool consolevent = SDL_FALSE; +SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -bool stdin_active = true; +SDL_bool stdin_active = SDL_TRUE; typedef struct { @@ -290,7 +288,7 @@ static void I_ShutdownConsole(void) if (consolevent) { I_OutputMsg("Shutdown tty console\n"); - consolevent = false; + consolevent = SDL_FALSE; tcsetattr(STDIN_FILENO, TCSADRAIN, &tty_tc); } } @@ -305,11 +303,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 = false; + consolevent = SDL_FALSE; if (!consolevent) return; @@ -317,7 +315,7 @@ static void I_StartupConsole(void) if (isatty(STDIN_FILENO)!=1) { I_OutputMsg("stdin is not a tty, tty console mode failed\n"); - consolevent = false; + consolevent = SDL_FALSE; return; } @@ -519,7 +517,7 @@ static void I_StartupConsole(void) if (gotConsole) { SetConsoleTitleA("SRB2Kart Console"); - consolevent = true; + consolevent = SDL_TRUE; } //Let get the real console HANDLE, because Mingw's Bash is bad! @@ -552,7 +550,7 @@ static inline void I_StartupConsole(void) framebuffer = M_CheckParm("-framebuffer"); if (framebuffer) - consolevent = false; + consolevent = SDL_FALSE; } static inline void I_ShutdownConsole(void){} #endif @@ -701,7 +699,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; @@ -731,7 +729,7 @@ static void JoyReset(SDLJoyInfo_t *JoySet) { if (JoySet->dev) { - SDL_CloseGamepad(JoySet->dev); + SDL_GameControllerClose(JoySet->dev); } JoySet->dev = NULL; @@ -773,15 +771,15 @@ void I_JoyScale4(void) } // Cheat to get the device index for a joystick handle -INT32 I_GetJoystickDeviceIndex(SDL_Gamepad *dev) +INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) { SDL_Joystick *joystick = NULL; - joystick = SDL_GetGamepadJoystick(dev); + joystick = SDL_GameControllerGetJoystick(dev); if (joystick) { - return SDL_GetJoystickID(joystick); + return SDL_JoystickInstanceID(joystick); } return -1; @@ -891,7 +889,7 @@ void I_ShutdownJoystick(UINT8 index) */ static int joy_open(int playerIndex, int joyIndex) { - SDL_Gamepad *newdev = NULL; + SDL_GameController *newdev = NULL; int num_joy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) @@ -900,7 +898,7 @@ static int joy_open(int playerIndex, int joyIndex) return -1; } - if (SDL_WasInit(SDL_INIT_GAMEPAD) == 0) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) { CONS_Printf(M_GetText("Game Controller subsystem not started\n")); return -1; @@ -909,7 +907,7 @@ static int joy_open(int playerIndex, int joyIndex) if (joyIndex <= 0) return -1; - SDL_GetJoysticks(&num_joy); + num_joy = SDL_NumJoysticks(); if (num_joy == 0) { @@ -917,7 +915,7 @@ static int joy_open(int playerIndex, int joyIndex) return -1; } - newdev = SDL_OpenGamepad(joyIndex-1); + newdev = SDL_GameControllerOpen(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. @@ -932,8 +930,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_GamepadConnected(JoyInfo[playerIndex].dev))) // we failed, but already have a working device - return SDL_GAMEPAD_AXIS_COUNT; + || (newdev == NULL && SDL_GameControllerGetAttached(JoyInfo[playerIndex].dev))) // we failed, but already have a working device + return SDL_CONTROLLER_AXIS_MAX; // Else, we're changing devices, so send neutral joy events CONS_Debug(DBG_GAMELOGIC, "Joystick1 device is changing; resetting events...\n"); @@ -950,13 +948,13 @@ static int joy_open(int playerIndex, int joyIndex) } else { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_GetGamepadName(JoyInfo[playerIndex].dev)); - JoyInfo[playerIndex].axises = SDL_GAMEPAD_AXIS_COUNT; + CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_GameControllerName(JoyInfo[playerIndex].dev)); + JoyInfo[playerIndex].axises = SDL_CONTROLLER_AXIS_MAX; if (JoyInfo[playerIndex].axises > JOYAXISSET*2) JoyInfo[playerIndex].axises = JOYAXISSET*2; - JoyInfo[playerIndex].buttons = SDL_GAMEPAD_BUTTON_COUNT; // dpad is 4 buttons + JoyInfo[playerIndex].buttons = SDL_CONTROLLER_BUTTON_MAX ; // dpad is 4 buttons if (JoyInfo[playerIndex].buttons > JOYBUTTONS) JoyInfo[playerIndex].buttons = JOYBUTTONS; @@ -976,7 +974,7 @@ static int joy_open(int playerIndex, int joyIndex) void I_InitJoystick(UINT8 index) { UINT8 i; - SDL_Gamepad *newcontroller = NULL; + SDL_GameController *newcontroller = NULL; // not sure if this is the best place to put this SDL_SetHint(SDL_HINT_AUTO_UPDATE_SENSORS, "0"); @@ -994,16 +992,15 @@ void I_InitJoystick(UINT8 index) { CONS_Printf("I_InitJoystick()...\n"); - if (!SDL_InitSubSystem(SDL_INIT_JOYSTICK)) + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) { CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); return; } } - - if (SDL_WasInit(SDL_INIT_GAMEPAD) == 0) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) { - if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) + if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) { CONS_Printf(M_GetText("Couldn't initialize gamepads: %s\n"), SDL_GetError()); return; @@ -1016,7 +1013,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_OpenGamepad(cv_usejoystick[index].value-1); + newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { @@ -1056,7 +1053,7 @@ void I_InitJoystick(UINT8 index) if (i == MAXSPLITSCREENPLAYERS) { // Joystick didn't end up being used - SDL_CloseGamepad(newcontroller); + SDL_GameControllerClose(newcontroller); } } @@ -1091,10 +1088,10 @@ static void I_ShutdownInput(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) I_ShutdownJoystick(i); - if (SDL_WasInit(SDL_INIT_GAMEPAD) == SDL_INIT_GAMEPAD) + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == SDL_INIT_GAMECONTROLLER) { CONS_Printf("Shutting down gamecontroller system\n"); - SDL_QuitSubSystem(SDL_INIT_GAMEPAD); + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); I_OutputMsg("I_Joystick: SDL's Game Controller system has been shutdown\n"); } @@ -1111,9 +1108,7 @@ INT32 I_NumJoys(void) INT32 numjoy = 0; if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) - { - SDL_GetJoysticks(&numjoy); - } + numjoy = SDL_NumJoysticks(); return numjoy; } @@ -1128,7 +1123,7 @@ const char *I_GetJoyName(INT32 joyindex) if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { - tempname = SDL_GetJoystickNameForID(joyindex); + tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) { @@ -1148,14 +1143,14 @@ void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, (void)high_strength; (void)duration; #else - SDL_Gamepad *controller = JoyInfo[playernum].dev; + SDL_GameController *controller = JoyInfo[playernum].dev; if (controller == NULL) { return; } - SDL_RumbleGamepad(controller, low_strength, high_strength, duration); + SDL_GameControllerRumble(controller, low_strength, high_strength, duration); #endif } @@ -1167,14 +1162,14 @@ void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 b (void)green; (void)blue; #else - SDL_Gamepad *controller = JoyInfo[playernum].dev; + SDL_GameController *controller = JoyInfo[playernum].dev; if (controller == NULL) { return; } - SDL_SetGamepadLED(controller, red, green, blue); + SDL_GameControllerSetLED(controller, red, green, blue); #endif } @@ -1827,7 +1822,10 @@ static void I_Fork(void) INT32 I_StartupSystem(void) { - int SDLlinked = SDL_GetVersion(); + SDL_version SDLcompiled; + SDL_version SDLlinked; + SDL_VERSION(&SDLcompiled) + SDL_GetVersion(&SDLlinked); I_StartupConsole(); #ifdef NEWSIGNALHANDLER // This is useful when debugging. It lets GDB attach to @@ -1843,15 +1841,15 @@ INT32 I_StartupSystem(void) #endif I_RegisterSignals(); I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION); + SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); I_OutputMsg("Linked with SDL version: %d.%d.%d\n", - SDL_VERSIONNUM_MAJOR(SDLlinked), SDL_VERSIONNUM_MINOR(SDLlinked), SDL_VERSIONNUM_MICRO(SDLlinked)); + SDLlinked.major, SDLlinked.minor, SDLlinked.patch); #if (SDL_VERSION_ATLEAST(2, 0, 18)) SDL_SetHint(SDL_HINT_APP_NAME, "SRB2Kart Saturn"); #endif - if (!SDL_Init(0)) + if (SDL_Init(0) < 0) I_Error("SRB2: SDL System Error: %s", SDL_GetError()); //Alam: Oh no.... #ifndef NOMUMBLE I_SetupMumble(); @@ -1864,12 +1862,12 @@ INT32 I_StartupSystem(void) // FUNCNORETURN void ATTRNORETURN I_Quit(void) { - static bool quiting = false; + static SDL_bool quiting = SDL_FALSE; /* prevent recursive I_Quit() */ if (quiting) goto death; - SDL_ShowCursor(); - quiting = false; + SDL_ShowCursor(SDL_TRUE); + quiting = SDL_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 8755c6e51..078f4e0f4 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_AtomicInt i_threads_running = {1}; +static SDL_atomic_t i_threads_running = {1}; static Link Insert_link ( @@ -103,13 +103,13 @@ Identity ( ){ void * id; - id = SDL_GetAtomicPointer(anchor); + id = SDL_AtomicGetPtr(anchor); if (! id) { I_lock_mutex(&pool_mutex); { - id = SDL_GetAtomicPointer(anchor); + id = SDL_AtomicGetPtr(anchor); if (! id) { @@ -120,7 +120,7 @@ Identity ( Insert_link(pool_anchor, New_link(id)); - SDL_SetAtomicPointer(anchor, id); + SDL_AtomicSetPtr(anchor, id); } } I_unlock_mutex(pool_mutex); @@ -139,11 +139,11 @@ Worker ( (*th->entry)(th->userdata); - if (SDL_GetAtomicInt(&i_threads_running)) + if (SDL_AtomicGet(&i_threads_running)) { I_lock_mutex(&i_thread_pool_mutex); { - if (SDL_GetAtomicInt(&i_threads_running)) + if (SDL_AtomicGet(&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_GetAtomicInt(&i_threads_running)) + if (SDL_AtomicGet(&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_GetAtomicInt(&i_threads_running) ); + return ( ! SDL_AtomicGet(&i_threads_running) ); } void @@ -220,13 +220,13 @@ I_stop_threads (void) Link next; Thread th; - SDL_Mutex * mutex; - SDL_Condition * cond; + SDL_mutex * mutex; + SDL_cond * cond; if (i_threads_running.value) { /* rely on the good will of thread-san */ - SDL_SetAtomicInt(&i_threads_running, 0); + SDL_AtomicSet(&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_DestroyCondition(cond); + SDL_DestroyCond(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,14 +291,16 @@ I_lock_mutex ( (Create_fn)SDL_CreateMutex ); - SDL_LockMutex(mutex); + if (SDL_LockMutex(mutex) == -1) + abort(); } void I_unlock_mutex ( I_mutex id ){ - SDL_UnlockMutex(id); + if (SDL_UnlockMutex(id) == -1) + abort(); } void @@ -306,46 +308,49 @@ I_hold_cond ( I_cond * cond_anchor, I_mutex mutex_id ){ - SDL_Condition * cond; + SDL_cond * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, cond_anchor, - (Create_fn)SDL_CreateCondition + (Create_fn)SDL_CreateCond ); - SDL_WaitCondition(cond, mutex_id); + if (SDL_CondWait(cond, mutex_id) == -1) + abort(); } void I_wake_one_cond ( I_cond * anchor ){ - SDL_Condition * cond; + SDL_cond * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, anchor, - (Create_fn)SDL_CreateCondition + (Create_fn)SDL_CreateCond ); - SDL_SignalCondition(cond); + if (SDL_CondSignal(cond) == -1) + abort(); } void I_wake_all_cond ( I_cond * anchor ){ - SDL_Condition * cond; + SDL_cond * cond; cond = Identity( &i_cond_pool, i_cond_pool_mutex, anchor, - (Create_fn)SDL_CreateCondition + (Create_fn)SDL_CreateCond ); - SDL_BroadcastCondition(cond); + if (SDL_CondBroadcast(cond) == -1) + abort(); } diff --git a/src/sdl/i_ttf.c b/src/sdl/i_ttf.c index 5111d3719..f2cd497ee 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)) + if (SDL_InitSubSystem(initflags) < 0) 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()) + if (TTF_Init() < 0) 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 984715549..a8b634f42 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 +#include "SDL.h" #ifdef HAVE_TTF #include "i_ttf.h" @@ -47,7 +47,7 @@ #include "../doomdef.h" #ifdef _WIN32 -#include +#include "SDL_syswm.h" #endif #include "../doomstat.h" @@ -112,7 +112,7 @@ boolean a2c = false; static void KeyboardLayout_OnChange(void) { if (cv_keyboardlayout.value != 2) - SDL_StopTextInput(window); + SDL_StopTextInput(); 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 bool disable_fullscreen = false; +static SDL_bool disable_fullscreen = SDL_FALSE; #define USE_FULLSCREEN (disable_fullscreen||!allow_fullscreen)? 0: (cv_fullscreen.value == 1) -static bool disable_mouse = false; +static SDL_bool disable_mouse = SDL_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 bool usesdl2soft = false; -static bool borderlesswindow = false; +static SDL_bool usesdl2soft = SDL_FALSE; +static SDL_bool borderlesswindow = SDL_FALSE; // SDL2 vars SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; -static bool havefocus = true; +static SDL_bool havefocus = SDL_TRUE; -static bool Impl_CreateWindow(bool fullscreen); +static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL @@ -173,10 +173,8 @@ float InvSupersampleFactorX = 0.0; float InvSupersampleFactorY = 0.0; #endif -static INT32 Impl_SDL_Scancode_To_Keycode(SDL_KeyboardEvent evt) +static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) { - SDL_Scancode code = evt.scancode; - if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) { // get lowercase ASCII @@ -268,12 +266,12 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_KeyboardEvent evt) return 0; } -static INT32 Impl_SDL_Keysym_To_Keycode(SDL_KeyboardEvent evt) +static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) { - SDL_Keycode keycode = evt.key; - SDL_Scancode scancode = evt.scancode; + SDL_Keycode keycode = keysym.sym; + SDL_Scancode scancode = keysym.scancode; - if (keycode >= SDLK_A && keycode <= SDLK_Z) + if (keycode >= SDLK_a && keycode <= SDLK_z) { // get lowercase ASCII return keycode; @@ -314,7 +312,7 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_KeyboardEvent evt) case SDLK_AMPERSAND: return '&'; case SDLK_2: return KEY_FR_E_AIGUE; case SDLK_3: - case SDLK_DBLAPOSTROPHE: return '"'; + case SDLK_QUOTEDBL: return '"'; case SDLK_4: return '\''; case SDLK_5: case SDLK_LEFTPAREN: return '('; @@ -343,7 +341,7 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_KeyboardEvent evt) default: break; } - return Impl_SDL_Scancode_To_Keycode(evt); + return Impl_SDL_Scancode_To_Keycode(scancode); } static boolean native_input_active = false; @@ -358,22 +356,22 @@ void I_SetTextInput(boolean enable) { if (enable && !native_input_active) { - SDL_StartTextInput(window); + SDL_StartTextInput(); native_input_active = true; } else if (!enable && native_input_active) { - SDL_StopTextInput(window); + SDL_StopTextInput(); native_input_active = false; } } // Get the equivalent ASCII (Unicode?) character for a keypress. -static INT32 GetTypedChar(SDL_KeyboardEvent evt) +static INT32 GetTypedChar(SDL_Keysym keysym) { SDL_Event next_event; - SDL_Keycode keycode = evt.key; - SDL_Scancode scancode = evt.scancode; + SDL_Keycode keycode = keysym.sym; + SDL_Scancode scancode = keysym.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) @@ -391,7 +389,7 @@ static INT32 GetTypedChar(SDL_KeyboardEvent evt) if (scancode == SDL_SCANCODE_GRAVE) return '`'; - if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST) == 1 && next_event.type == SDL_EVENT_TEXT_INPUT) + if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT) { if (next_event.text.text[1] == '\0') // limit to ASCII { @@ -401,7 +399,7 @@ static INT32 GetTypedChar(SDL_KeyboardEvent evt) } // otherwise fallback to scancodes - return Impl_SDL_Scancode_To_Keycode(evt); + return Impl_SDL_Scancode_To_Keycode(scancode); } static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) @@ -454,38 +452,37 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { #define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) - static bool firsttimeonmouse = true; - static bool mousefocus = true; - static bool kbfocus = true; - static bool windowmoved = false; + static SDL_bool firsttimeonmouse = SDL_TRUE; + static SDL_bool mousefocus = SDL_TRUE; + static SDL_bool kbfocus = SDL_TRUE; + static SDL_bool windowmoved = SDL_FALSE; const unsigned int oldfocus = FOCUSUNION; - switch (evt.type) + switch (evt.event) { - case SDL_EVENT_WINDOW_MOUSE_ENTER: - mousefocus = true; + case SDL_WINDOWEVENT_ENTER: + mousefocus = SDL_TRUE; break; - case SDL_EVENT_WINDOW_MOUSE_LEAVE: - mousefocus = false; + case SDL_WINDOWEVENT_LEAVE: + mousefocus = SDL_FALSE; break; - case SDL_EVENT_WINDOW_FOCUS_GAINED: - kbfocus = true; - mousefocus = true; + case SDL_WINDOWEVENT_FOCUS_GAINED: + kbfocus = SDL_TRUE; + mousefocus = SDL_TRUE; if (!cv_mousevisible.value) - SDL_HideCursor(); + SDL_ShowCursor(SDL_FALSE); break; - case SDL_EVENT_WINDOW_FOCUS_LOST: - kbfocus = false; - mousefocus = false; - SDL_ShowCursor(); + case SDL_WINDOWEVENT_FOCUS_LOST: + kbfocus = SDL_FALSE; + mousefocus = SDL_FALSE; + SDL_ShowCursor(SDL_TRUE); break; - //case SDL_EVENT_WINDOW_DISPLAY_CHANGED: - case SDL_EVENT_WINDOW_MOVED: - windowmoved = true; + case SDL_WINDOWEVENT_MAXIMIZED: + break; + case SDL_WINDOWEVENT_MOVED: + windowmoved = SDL_TRUE; break; - default: - return; } if (FOCUSUNION == oldfocus) // No state change @@ -508,7 +505,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #endif #endif - windowmoved = false; + windowmoved = SDL_FALSE; } if (mousefocus && kbfocus) @@ -548,10 +545,10 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) switch (type) { - case SDL_EVENT_KEY_UP: + case SDL_KEYUP: event.type = ev_keyup; break; - case SDL_EVENT_KEY_DOWN: + case SDL_KEYDOWN: event.type = ev_keydown; break; default: @@ -561,13 +558,13 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) switch (cv_keyboardlayout.value) { case 2: // "native" - event.data1 = GetTypedChar(evt); + event.data1 = GetTypedChar(evt.keysym); break; case 3: // AZERTY - event.data1 = Impl_SDL_Keysym_To_Keycode(evt); + event.data1 = Impl_SDL_Keysym_To_Keycode(evt.keysym); break; default: - event.data1 = Impl_SDL_Scancode_To_Keycode(evt); + event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode); break; } @@ -586,29 +583,28 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (!windowinfocus) { - SDL_ShowCursor(); - SDL_SetWindowMouseGrab(window, false); - SDL_SetWindowRelativeMouseMode(window, false); + SDL_ShowCursor(SDL_ENABLE); + SDL_SetWindowGrab(window, SDL_FALSE); + SDL_SetRelativeMouseMode(SDL_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_GetWindowRelativeMouseMode(window)) + if (SDL_GetRelativeMouseMode()) { if (windowinfocus) { mousemovex += evt.xrel; mousemovey += -evt.yrel; - SDL_SetWindowMouseGrab(window, true); + SDL_SetWindowGrab(window, SDL_TRUE); } - return; } // If the event is from warping the pointer to middle // of the screen then ignore it. - if (((int)evt.x == realwidth/2) && ((int)evt.y == realheight/2)) + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } @@ -619,9 +615,9 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) // -- Monster Iestyn if (windowinfocus) { - SDL_HideCursor(); - SDL_SetWindowMouseGrab(window, true); - SDL_SetWindowRelativeMouseMode(window, true); + SDL_ShowCursor(SDL_DISABLE); + SDL_SetWindowGrab(window, SDL_TRUE); + SDL_SetRelativeMouseMode(SDL_TRUE); } } @@ -642,10 +638,10 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) { switch (type) { - case SDL_EVENT_MOUSE_BUTTON_UP: + case SDL_MOUSEBUTTONUP: event.type = ev_keyup; break; - case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_MOUSEBUTTONDOWN: event.type = ev_keydown; break; default: @@ -684,19 +680,19 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) if (USE_MOUSEINPUT) { - int y = evt.y; - - if (y > 0) + if (evt.y > 0) { event.data1 = KEY_MOUSEWHEELUP; event.type = ev_keydown; } - else if (y < 0) + + if (evt.y < 0) { event.data1 = KEY_MOUSEWHEELDOWN; event.type = ev_keydown; } - else if (y == 0) + + if (evt.y == 0) { event.data1 = 0; event.type = ev_keyup; @@ -720,12 +716,12 @@ void I_HandleControllerHatRepeat(void) event_t event = {ev_keydown, 0, 0, 0}; - static const SDL_GamepadButton hatbutt[4] = + static const SDL_GameControllerButton hatbutt[4] = { - SDL_GAMEPAD_BUTTON_DPAD_UP, - SDL_GAMEPAD_BUTTON_DPAD_DOWN, - SDL_GAMEPAD_BUTTON_DPAD_LEFT, - SDL_GAMEPAD_BUTTON_DPAD_RIGHT + SDL_CONTROLLER_BUTTON_DPAD_UP, + SDL_CONTROLLER_BUTTON_DPAD_DOWN, + SDL_CONTROLLER_BUTTON_DPAD_LEFT, + SDL_CONTROLLER_BUTTON_DPAD_RIGHT }; for (int i = 0; i < MAXSPLITSCREENPLAYERS; i++) @@ -733,14 +729,14 @@ void I_HandleControllerHatRepeat(void) if (!cv_usejoystick[i].value) continue; - SDL_Gamepad *controller = JoyInfo[i].dev; + SDL_GameController *controller = JoyInfo[i].dev; if (!controller) continue; for (UINT8 h = 0; h < JOYHATS; h++) { - if (SDL_GetGamepadButton(controller, hatbutt[h])) + if (SDL_GameControllerGetButton(controller, hatbutt[h])) { if (hatrepeattimer[i] < HATREPEATDELAY) { @@ -760,7 +756,7 @@ void I_HandleControllerHatRepeat(void) } } -static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt) +static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) { event_t event; INT32 value; @@ -789,27 +785,27 @@ static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt) value = SDLJoyAxis(evt.value, event.type); switch (evt.axis) { - case SDL_GAMEPAD_AXIS_LEFTX: + case SDL_CONTROLLER_AXIS_LEFTX: event.data1 = 0; event.data2 = value; break; - case SDL_GAMEPAD_AXIS_LEFTY: + case SDL_CONTROLLER_AXIS_LEFTY: event.data1 = 0; event.data3 = value; break; - case SDL_GAMEPAD_AXIS_RIGHTX: + case SDL_CONTROLLER_AXIS_RIGHTX: event.data1 = 1; event.data2 = value; break; - case SDL_GAMEPAD_AXIS_RIGHTY: + case SDL_CONTROLLER_AXIS_RIGHTY: event.data1 = 1; event.data3 = value; break; - case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: + case SDL_CONTROLLER_AXIS_TRIGGERLEFT: event.data1 = 2; event.data2 = value; break; - case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: + case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: event.data1 = 2; event.data3 = value; break; @@ -820,7 +816,7 @@ static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt) D_PostEvent(&event); } -static void Impl_HandleControllerHatEvent(SDL_GamepadButtonEvent evt, Uint32 type) +static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 type) { event_t event = {0}; UINT8 i; @@ -841,10 +837,10 @@ static void Impl_HandleControllerHatEvent(SDL_GamepadButtonEvent evt, Uint32 typ switch (type) { - case SDL_EVENT_GAMEPAD_BUTTON_UP: + case SDL_CONTROLLERBUTTONUP: event.type = ev_keyup; break; - case SDL_EVENT_GAMEPAD_BUTTON_DOWN: + case SDL_CONTROLLERBUTTONDOWN: event.type = ev_keydown; break; default: @@ -853,15 +849,15 @@ static void Impl_HandleControllerHatEvent(SDL_GamepadButtonEvent evt, Uint32 typ switch (evt.button) { - case SDL_GAMEPAD_BUTTON_DPAD_UP: + case SDL_CONTROLLER_BUTTON_DPAD_UP: break; - case SDL_GAMEPAD_BUTTON_DPAD_DOWN: + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: event.data1 += 1; break; - case SDL_GAMEPAD_BUTTON_DPAD_LEFT: + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: event.data1 += 2; break; - case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: event.data1 += 3; break; default: @@ -874,15 +870,15 @@ static void Impl_HandleControllerHatEvent(SDL_GamepadButtonEvent evt, Uint32 typ } } -static void Impl_HandleControllerButtonEvent(SDL_GamepadButtonEvent evt, Uint32 type) +static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent 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_GAMEPAD_BUTTON_DPAD_UP && - evt.button <= SDL_GAMEPAD_BUTTON_DPAD_RIGHT) + if (evt.button >= SDL_CONTROLLER_BUTTON_DPAD_UP && + evt.button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT) { Impl_HandleControllerHatEvent(evt, type); return; @@ -903,10 +899,10 @@ static void Impl_HandleControllerButtonEvent(SDL_GamepadButtonEvent evt, Uint32 switch (type) { - case SDL_EVENT_GAMEPAD_BUTTON_UP: + case SDL_CONTROLLERBUTTONUP: event.type = ev_keyup; break; - case SDL_EVENT_GAMEPAD_BUTTON_DOWN: + case SDL_CONTROLLERBUTTONDOWN: event.type = ev_keydown; break; default: @@ -931,7 +927,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) INT32 i; // OH BOY are you in for a good time! #abominationstation - SDL_Gamepad *newcontroller = SDL_OpenGamepad(evt.cdevice.which); + SDL_GameController *newcontroller = SDL_GameControllerOpen(evt.cdevice.which); CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); @@ -948,7 +944,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (newcontroller && (!JoyInfo[i].dev || !SDL_GamepadConnected(JoyInfo[i].dev))) + if (newcontroller && (!JoyInfo[i].dev || !SDL_GameControllerGetAttached(JoyInfo[i].dev))) { UINT8 j; @@ -1015,7 +1011,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) } if (i == MAXSPLITSCREENPLAYERS) - SDL_CloseGamepad(newcontroller); + SDL_GameControllerClose(newcontroller); } static void Impl_HandleControllerRemovedEvent(void) @@ -1024,7 +1020,7 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (JoyInfo[i].dev && !SDL_GamepadConnected(JoyInfo[i].dev)) + if (JoyInfo[i].dev && !SDL_GameControllerGetAttached(JoyInfo[i].dev)) { CONS_Debug(DBG_GAMELOGIC, "Joystick%d removed, device index: %d\n", i+1, JoyInfo[i].oldjoy); I_ShutdownJoystick(i); @@ -1074,7 +1070,7 @@ static void Impl_HandleControllerRemovedEvent(void) void I_GetEvent(void) { SDL_Event evt; - const char* dropped_filedir; + char* dropped_filedir; if (!graphics_started) { @@ -1087,44 +1083,45 @@ void I_GetEvent(void) { switch (evt.type) { - case SDL_EVENT_KEY_UP: - case SDL_EVENT_KEY_DOWN: + case SDL_WINDOWEVENT: + Impl_HandleWindowEvent(evt.window); + break; + case SDL_KEYUP: + case SDL_KEYDOWN: Impl_HandleKeyboardEvent(evt.key, evt.type); break; - case SDL_EVENT_MOUSE_MOTION: + case SDL_MOUSEMOTION: Impl_HandleMouseMotionEvent(evt.motion); break; - case SDL_EVENT_MOUSE_BUTTON_UP: - case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_MOUSEBUTTONUP: + case SDL_MOUSEBUTTONDOWN: Impl_HandleMouseButtonEvent(evt.button, evt.type); break; - case SDL_EVENT_MOUSE_WHEEL: + case SDL_MOUSEWHEEL: Impl_HandleMouseWheelEvent(evt.wheel); break; - case SDL_EVENT_GAMEPAD_AXIS_MOTION: - Impl_HandleControllerAxisEvent(evt.gaxis); + case SDL_CONTROLLERAXISMOTION: + Impl_HandleControllerAxisEvent(evt.caxis); break; - case SDL_EVENT_GAMEPAD_BUTTON_UP: - case SDL_EVENT_GAMEPAD_BUTTON_DOWN: - Impl_HandleControllerButtonEvent(evt.gbutton, evt.type); + case SDL_CONTROLLERBUTTONUP: + case SDL_CONTROLLERBUTTONDOWN: + Impl_HandleControllerButtonEvent(evt.cbutton, evt.type); break; - case SDL_EVENT_GAMEPAD_ADDED: + case SDL_CONTROLLERDEVICEADDED: Impl_HandleControllerAddedEvent(evt); break; - case SDL_EVENT_GAMEPAD_REMOVED: + case SDL_CONTROLLERDEVICEREMOVED: Impl_HandleControllerRemovedEvent(); break; - case SDL_EVENT_DROP_FILE: - dropped_filedir = evt.drop.data; + case SDL_DROPFILE: + dropped_filedir = evt.drop.file; P_AddWadFile(dropped_filedir, false); + SDL_free(dropped_filedir); // Free dropped_filedir memory break; - case SDL_EVENT_QUIT: + case SDL_QUIT: I_Quit(); M_QuitResponse('y'); break; - default: - Impl_HandleWindowEvent(evt.window); - break; } } @@ -1152,12 +1149,12 @@ void I_StartupMouse(void) return; if (!cv_mousevisible.value) - SDL_HideCursor(); + SDL_ShowCursor(SDL_FALSE); else - SDL_ShowCursor(); + SDL_ShowCursor(SDL_TRUE); - SDL_SetWindowMouseGrab(window, false); - SDL_SetWindowRelativeMouseMode(window, false); + SDL_SetWindowGrab(window, SDL_FALSE); + SDL_SetRelativeMouseMode(SDL_FALSE); } // @@ -1170,9 +1167,9 @@ void I_OsPolling(void) if (consolevent) I_GetConsoleEvents(); - if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMEPAD) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMEPAD)) + if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER)) { - SDL_UpdateGamepads(); + SDL_GameControllerUpdate(); } I_GetEvent(); @@ -1183,18 +1180,18 @@ void I_OsPolling(void) shiftdown = ctrldown = altdown = 0; capslock = false; - 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; + 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; } static void VID_Command_NumModes_f (void) { - CONS_Printf("%d video mode(s) available(s)\n", VID_NumModes()); + CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes()); } static void VID_Command_ModeList_f(void) @@ -1234,28 +1231,26 @@ static void VID_Command_Mode_f (void) static void I_CheckDesktopRes(void) { int currentDisplayIndex = -1; - const SDL_DisplayMode *curmode; + SDL_DisplayMode curmode; desktopwidth = 0; desktopheight = 0; - currentDisplayIndex = SDL_GetDisplayForWindow(window); + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // No valid index - if (!currentDisplayIndex) + if (currentDisplayIndex < 0) { return; } - curmode = SDL_GetCurrentDisplayMode(currentDisplayIndex); - - if (!curmode) + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) { return; } - desktopwidth = curmode->w; - desktopheight = curmode->h; + desktopwidth = curmode.w; + desktopheight = curmode.h; } // Check if the game resolution matches the desktop resolution @@ -1320,9 +1315,9 @@ static void I_ResetFBOSurface(void) } #endif -static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) +static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { - static bool wasfullscreen = false; + static SDL_bool wasfullscreen = SDL_FALSE; int sw_texture_format = SDL_PIXELFORMAT_ABGR8888; realwidth = vid.width; @@ -1332,26 +1327,24 @@ static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) { if (fullscreen) { - wasfullscreen = true; - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); + wasfullscreen = SDL_TRUE; + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); I_SetBorderlessWindow(); } else // windowed mode { if (wasfullscreen) { - wasfullscreen = false; + wasfullscreen = SDL_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(displayid), - SDL_WINDOWPOS_CENTERED_DISPLAY(displayid) + SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), + SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) ); } } @@ -1363,7 +1356,7 @@ static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) if (fullscreen) { - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); I_SetBorderlessWindow(); } } @@ -1382,7 +1375,7 @@ static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) if (rendermode == render_soft) { SDL_RenderClear(renderer); - SDL_SetRenderLogicalPresentation(renderer, width, height, SDL_LOGICAL_PRESENTATION_LETTERBOX); + SDL_RenderSetLogicalSize(renderer, width, height); // Set up Texture realwidth = width; @@ -1400,7 +1393,7 @@ static void SDLSetMode(INT32 width, INT32 height, bool fullscreen) // // I_FinishUpdate // -static SDL_FRect src_rect = { 0, 0, 0, 0 }; +static SDL_Rect src_rect = { 0, 0, 0, 0 }; void I_FinishUpdate(void) { @@ -1453,7 +1446,7 @@ void I_FinishUpdate(void) SDL_UnlockTexture(texture); SDL_RenderClear(renderer); - SDL_RenderTexture(renderer, texture, &src_rect, NULL); + SDL_RenderCopy(renderer, texture, &src_rect, NULL); SDL_RenderPresent(renderer); } } @@ -1593,18 +1586,17 @@ static int IsCustomResolutionInList(int list_size) // static void I_FillScreenResolutionsList(boolean force) { - SDL_DisplayID currentDisplayIndex = -1; - static SDL_DisplayID oldDisplayIndex = -1; + int currentDisplayIndex = -1; + static int oldDisplayIndex = -1; SDL_DisplayMode mode; - SDL_DisplayMode **displaymodes = NULL; int i = 0, list_size = 0; int count = 0; char custom_resolution[10]; - currentDisplayIndex = SDL_GetDisplayForWindow(window); + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); // No valid index - if (!currentDisplayIndex) + if (currentDisplayIndex < 0) { return; } @@ -1618,12 +1610,7 @@ static void I_FillScreenResolutionsList(boolean force) oldDisplayIndex = currentDisplayIndex; // Don't call SDL_ListModes if SDL has not been initialized - displaymodes = SDL_GetFullscreenDisplayModes(currentDisplayIndex, &count); - - if (!displaymodes) - { - return; - } + count = SDL_GetNumDisplayModes(currentDisplayIndex); list_size = 0; @@ -1640,20 +1627,18 @@ static void I_FillScreenResolutionsList(boolean force) { mode.w = canonicals[i - count].w; mode.h = canonicals[i - count].h; - - I_AppendResolution(&mode, &list_size); } else { - I_AppendResolution(displaymodes[i], &list_size); + SDL_GetDisplayMode(currentDisplayIndex, i, &mode); } + + I_AppendResolution(&mode, &list_size); } windowedModes[list_size].name[0] = '\0'; } - SDL_free(displaymodes); - const int customresinlist = IsCustomResolutionInList(list_size); if (customresinlist == 0) @@ -1763,8 +1748,8 @@ void VID_PrepareModeList(void) static UINT32 refresh_rate; static UINT32 VID_GetRefreshRate(void) { - int index = SDL_GetDisplayForWindow(window); - const SDL_DisplayMode *displaymode = NULL; + int index = SDL_GetWindowDisplayIndex(window); + SDL_DisplayMode m; if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { @@ -1772,15 +1757,13 @@ static UINT32 VID_GetRefreshRate(void) return 0; } - displaymode = SDL_GetDesktopDisplayMode(index); - - if (!displaymode) + if (SDL_GetDesktopDisplayMode(index, &m) != 0) { // Error has occurred. return 0; } - return displaymode->refresh_rate; + return m.refresh_rate; } INT32 VID_SetMode(INT32 modeNum) @@ -1796,18 +1779,18 @@ INT32 VID_SetMode(INT32 modeNum) else { // just set the desktop resolution as a fallback - const SDL_DisplayMode *mode = NULL; - mode = SDL_GetWindowFullscreenMode(window); + SDL_DisplayMode mode; + SDL_GetWindowDisplayMode(window, &mode); - 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; @@ -1820,10 +1803,10 @@ INT32 VID_SetMode(INT32 modeNum) refresh_rate = VID_GetRefreshRate(); - return true; + return SDL_TRUE; } -static bool Impl_CreateContext(void) +static SDL_bool Impl_CreateContext(void) { // Renderer-specific stuff #ifdef HWRENDER @@ -1839,7 +1822,7 @@ static bool Impl_CreateContext(void) I_Error("Failed to create a GL context: %s\n", SDL_GetError()); } - if (!SDL_GL_MakeCurrent(window, sdlglcontext)) + if (SDL_GL_MakeCurrent(window, sdlglcontext) < 0) { SDL_DestroyWindow(window); I_Error("Failed to set up GL context: %s\n", SDL_GetError()); @@ -1848,60 +1831,68 @@ static bool Impl_CreateContext(void) // be sure to fill the resolution list the moment we have a window I_FillScreenResolutionsList(false); - return true; + return SDL_TRUE; } #endif if (rendermode == render_soft) { - if (!renderer) - { - 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"); + int flags = 0; // Use this to set SDL_RENDERER_* flags now - 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 (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); if (renderer == NULL) { I_Error("Couldn't create rendering context: %s\n", SDL_GetError()); } - SDL_SetRenderLogicalPresentation(renderer, BASEVIDWIDTH, BASEVIDHEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX); + SDL_RenderSetLogicalSize(renderer, BASEVIDWIDTH, BASEVIDHEIGHT); // be sure to fill the resolution list the moment we have a window I_FillScreenResolutionsList(false); - return true; + return SDL_TRUE; } - return false; + return SDL_FALSE; } -static bool Impl_CreateWindow(bool fullscreen) +static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) { int flags = 0; if (rendermode == render_none) // dedicated - return true; // Monster Iestyn -- not sure if it really matters what we return here tbh + return SDL_TRUE; // Monster Iestyn -- not sure if it really matters what we return here tbh if (window != NULL) - return false; + return SDL_FALSE; if (fullscreen) - flags |= SDL_WINDOW_FULLSCREEN; + flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; if (borderlesswindow) flags |= SDL_WINDOW_BORDERLESS; @@ -1928,7 +1919,7 @@ static bool Impl_CreateWindow(bool fullscreen) #endif // Create a window - window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, realwidth, realheight, flags); + window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, realwidth, realheight, flags); if (window == NULL) { @@ -1977,7 +1968,7 @@ void I_StartupGraphics(void) #if !defined(HAVE_TTF) // Previously audio was init here for questionable reasons? - if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { CONS_Printf(M_GetText("Couldn't initialize SDL's Video System: %s\n"), SDL_GetError()); return; @@ -1988,7 +1979,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 = true; + framebuffer = SDL_TRUE; } if (M_CheckParm("-software")) @@ -2165,7 +2156,7 @@ void I_StartupGraphics(void) graphics_started = true; - SDL_StopTextInput(window); + SDL_StopTextInput(); } void I_ShutdownGraphics(void) @@ -2173,7 +2164,7 @@ void I_ShutdownGraphics(void) rendermode = render_none; if (icoSurface) - SDL_DestroySurface(icoSurface); + SDL_FreeSurface(icoSurface); icoSurface = NULL; I_OutputMsg("I_ShutdownGraphics(): "); @@ -2189,7 +2180,7 @@ void I_ShutdownGraphics(void) I_OutputMsg("shut down\n"); #ifdef HWRENDER if (sdlglcontext) - SDL_GL_DestroyContext(sdlglcontext); + SDL_GL_DeleteContext(sdlglcontext); sdlglcontext = NULL; #endif if (texture) @@ -2203,7 +2194,7 @@ void I_ShutdownGraphics(void) window = NULL; SDL_QuitSubSystem(SDL_INIT_VIDEO); - framebuffer = false; + framebuffer = SDL_FALSE; } UINT32 I_GetRefreshRate(void) @@ -2220,7 +2211,7 @@ static void Impl_SetVsync(void) { #if SDL_VERSION_ATLEAST(2,0,18) if (renderer) - SDL_SetRenderVSync(renderer, cv_vidwait.value); + SDL_RenderSetVSync(renderer, cv_vidwait.value); #endif #ifdef HWRENDER if (!renderer && rendermode == render_opengl && @@ -2233,7 +2224,7 @@ static void Impl_SetVsync(void) void I_SetBorderlessWindow(void) { - bool borderless = (cv_fullscreen.value == 2) ? false : true; + SDL_bool borderless = (cv_fullscreen.value == 2) ? SDL_FALSE : SDL_TRUE; SDL_SetWindowBordered(window, borderless); } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index b95827131..b63166639 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 +#include "SDL.h" #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)) + if (SDL_GL_LoadLibrary(OGLLibname) != 0) { 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 67aa72309..c711d68d7 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -23,16 +23,14 @@ extern "C" { #endif -extern bool consolevent; -extern bool framebuffer; +extern SDL_bool consolevent; +extern SDL_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 @@ -43,9 +41,9 @@ extern bool framebuffer; typedef struct SDLJoyInfo_s { /// Controller handle - SDL_Gamepad *dev; + SDL_GameController *dev; /// Controller index - SDL_JoystickID id; + INT32 id; /// number of old joystick int oldjoy; /// number of axies @@ -73,7 +71,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_Gamepad *dev); +INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev); // Quick thing to make SDL_JOYDEVICEADDED events less of an abomination void I_UpdateJoystickDeviceIndex(UINT8 player);