Port to SDL3

This commit is contained in:
Eidolon 2026-06-19 16:36:57 -05:00
parent daa6140601
commit 8a68b7fcab
28 changed files with 431 additions and 3713 deletions

View file

@ -94,7 +94,7 @@ endif()
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL3 CONFIG REQUIRED)
find_package(CURL REQUIRED)
find_package(Opus REQUIRED)
if(WIN32 AND NOT MINGW)

View file

@ -1,43 +0,0 @@
# Find SDL2
# Once done, this will define
#
# SDL2_FOUND - system has SDL2
# SDL2_INCLUDE_DIRS - SDL2 include directories
# SDL2_LIBRARIES - link libraries
include(LibFindMacros)
libfind_pkg_check_modules(SDL2_PKGCONF SDL2)
# includes
find_path(SDL2_INCLUDE_DIR
NAMES SDL.h
PATHS
${SDL2_PKGCONF_INCLUDE_DIRS}
"/usr/include/SDL2"
"/usr/local/include/SDL2"
)
# library
find_library(SDL2_LIBRARY
NAMES SDL2
PATHS
${SDL2_PKGCONF_LIBRARY_DIRS}
"/usr/lib"
"/usr/local/lib"
)
# set include dir variables
set(SDL2_PROCESS_INCLUDES SDL2_INCLUDE_DIR)
set(SDL2_PROCESS_LIBS SDL2_LIBRARY)
libfind_process(SDL2)
if(SDL2_FOUND AND NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
set_target_properties(
SDL2::SDL2
PROPERTIES
IMPORTED_LOCATION "${SDL2_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
)
endif()

View file

@ -1,34 +0,0 @@
# Find SDL2
# Once done, this will define
#
# SDL2_MAIN_FOUND - system has SDL2
# SDL2_MAIN_INCLUDE_DIRS - SDL2 include directories
# SDL2_MAIN_LIBRARIES - link libraries
include(LibFindMacros)
libfind_pkg_check_modules(SDL2_MAIN_PKGCONF SDL2)
# includes
find_path(SDL2_MAIN_INCLUDE_DIR
NAMES SDL.h
PATHS
${SDL2_MAIN_PKGCONF_INCLUDE_DIRS}
"/usr/include/SDL2"
"/usr/local/include/SDL2"
)
# library
find_library(SDL2_MAIN_LIBRARY
NAMES SDL2_main
PATHS
${SDL2_MAIN_PKGCONF_LIBRARY_DIRS}
"/usr/lib"
"/usr/local/lib"
)
# set include dir variables
set(SDL2_MAIN_PROCESS_INCLUDES SDL2_MAIN_INCLUDE_DIR)
set(SDL2_MAIN_PROCESS_LIBS SDL2_MAIN_LIBRARY)
libfind_process(SDL2_MAIN)

View file

@ -50,7 +50,6 @@ extern "C" {
#define SINT8 int8_t
#ifdef __APPLE_CC__
#define DIRECTFULLSCREEN 1
#define DEBUG_LOG
#define NOIPX
#endif
@ -138,12 +137,16 @@ typedef int32_t boolean;
#ifndef __cplusplus
#ifndef _WIN32
#ifndef false // SDL3 workaround
enum {false = 0, true = 1};
#endif
#else
#ifndef false // SDL3 workaround
#define false FALSE
#define true TRUE
#endif
#endif
#endif
/* 7.18.2.1 Limits of exact-width integer types */

View file

@ -500,6 +500,11 @@ void F_RunWipe(UINT8 wipemode, UINT8 wipetype, boolean drawMenu, const char *col
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
if (!rhi)
{
break;
}
if (reverse)
{
hw_state->wipe->set_start(hw_state->wipe_frames.end);

View file

@ -21,7 +21,7 @@
#pragma warning(disable : 4214 4244)
#endif
#include "SDL_opengl.h" //Alam_GBC: Simple, yes?
#include <SDL3/SDL_opengl.h> //Alam_GBC: Simple, yes?
#ifdef _MSC_VER
#pragma warning(default : 4214 4244)

View file

@ -429,7 +429,6 @@ void SCR_SetDefaultMode(void)
void SCR_ChangeFullscreen(void);
void SCR_ChangeFullscreen(void)
{
#ifdef DIRECTFULLSCREEN
// allow_fullscreen is set by VID_PrepareModeList
// it is used to prevent switching to fullscreen during startup
if (!allow_fullscreen)
@ -441,7 +440,6 @@ void SCR_ChangeFullscreen(void)
setmodeneeded = VID_GetModeForSize(vid.width, vid.height) + 1;
}
return;
#endif
}
void SCR_ChangeRenderer(void)

View file

@ -1,4 +1,4 @@
# Declare SDL2 interface sources
# Declare SDL3 interface sources
target_sources(SRB2SDL2 PRIVATE
new_sound.cpp
@ -15,11 +15,6 @@ target_sources(SRB2SDL2 PRIVATE
hwsym_sdl.c
)
if(${SRB2_USEASM})
set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES LANGUAGE C)
set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
target_sources(SRB2SDL2 PRIVATE
../win32/win_dbg.c
@ -60,25 +55,13 @@ endif()
target_link_libraries(SRB2SDL2
PRIVATE
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
$<IF:$<TARGET_EXISTS:SDL3::SDL3>,SDL3::SDL3,SDL3::SDL3-static>
)
if("${CMAKE_SYSTEM_NAME}" MATCHES Linux)
target_link_libraries(SRB2SDL2 PRIVATE m rt)
endif()
if(${SRB2_USEASM})
if(${SRB2_CONFIG_YASM})
set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_YASM_COMPILER})
set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_YASM_OBJECT_FORMAT})
set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_YASM)
else()
set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_NASM_COMPILER})
set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_NASM_OBJECT_FORMAT})
set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_NASM)
endif()
endif()
if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
target_link_libraries(SRB2SDL2 PRIVATE
ws2_32
@ -88,8 +71,7 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
# )
endif()
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER)
target_compile_definitions(SRB2SDL2 PRIVATE -DDIRECTFULLSCREEN -DHAVE_SDL)
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_SDL -DHAVE_SDL3)
#### Installation ####
if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
@ -131,5 +113,3 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
)"
)
endif()
set(SRB2_SDL2_AVAILABLE YES PARENT_SCOPE)

View file

@ -42,21 +42,15 @@
* requires about 13K in binary form.
*/
#if 0
#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_IO(SDL_IOStream *src);
SDL_Surface *IMG_ReadXPMFromArray(const char **xpm);
#define IMG_SetError SDL_SetError
#define IMG_GetError SDL_GetError
#endif
#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 +58,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 +927,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 +937,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 +954,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 +974,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 +999,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 +1021,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 +1059,13 @@ 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;
SDL_GetSurfacePalette(image)->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 +1121,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 +1157,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 +1173,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 */
@ -1197,24 +1190,3 @@ SDL_Surface *IMG_ReadXPMFromArray(const char **xpm)
}
return load_xpm(xpm, NULL);
}
#else /* not LOAD_XPM */
/* See if an image is contained in a data source */
int IMG_isXPM(SDL_RWops *src)
{
return(0);
}
/* Load a XPM type image from an SDL datasource */
SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src)
{
return(NULL);
}
SDL_Surface *IMG_ReadXPMFromArray(const char **xpm)
{
return NULL;
}
#endif /* not LOAD_XPM */

View file

@ -26,14 +26,14 @@
#ifdef HAVE_SDL
#include "SDL.h"
#include <SDL3/SDL.h>
#ifdef _MSC_VER
#pragma warning(default : 4214 4244)
#endif
#ifndef NOLOADSO
#include "SDL_loadso.h"
#include <SDL3/SDL_loadso.h>
#endif
#define _CREATE_DLL_ // necessary for Unix AND Windows
@ -138,7 +138,7 @@ void *hwSym(const char *funcName,void *handle)
funcPointer = handle;
#else
else if (handle)
funcPointer = SDL_LoadFunction(handle,funcName);
funcPointer = (void*)SDL_LoadFunction(handle,funcName);
#endif
if (!funcPointer)
I_OutputMsg("hwSym for %s: %s\n", funcName, SDL_GetError());

View file

@ -1,6 +1,6 @@
// DR. ROBOTNIK'S RING RACERS
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by Kart Krew.
// Copyright (C) 2026 by Kart Krew.
// Copyright (C) 2020 by Sonic Team Junior.
// Copyright (C) 2000 by DooM Legacy Team.
// Copyright (C) 1996 by id Software, Inc.
@ -12,6 +12,9 @@
/// \file
/// \brief Main program, simply calls D_SRB2Main and D_SRB2Loop, the high level loop.
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include "../doomdef.h"
#include "../m_argv.h"
#include "../d_main.h"
@ -31,22 +34,7 @@
#include <errno.h>
#endif
#include "time.h" // For log timestamps
#ifdef HAVE_TTF
#include "SDL.h"
#include "i_ttf.h"
#endif
#if defined (_WIN32) && !defined (main)
//#define SDLMAIN
#endif
#ifdef SDLMAIN
#include "SDL_main.h"
#elif defined(FORCESDLMAIN)
extern int SDL_main(int argc, char *argv[]);
#endif
#include <time.h> // For log timestamps
#ifdef LOGMESSAGES
FILE *logstream = NULL;
@ -221,11 +209,7 @@ static void walk_exception_stack(srb2::String& accum, const std::exception& ex,
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#endif
#ifdef FORCESDLMAIN
int SDL_main(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
myargc = argc;
myargv = argv; /// \todo pull out path to exe from this string
@ -234,9 +218,9 @@ int main(int argc, char **argv)
#ifdef HAVE_TTF
#ifdef _WIN32
I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO|SDL_INIT_AUDIO, SDL_SWSURFACE);
I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO|SDL_INIT_AUDIO, 0);
#else
I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO, SDL_SWSURFACE);
I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO, 0);
#endif
#endif
@ -291,13 +275,6 @@ int main(int argc, char **argv)
return 0;
}
#ifdef _MSC_VER
int WINAPI WinMain(HINSTANCE pInstance, HINSTANCE pPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return main(__argc, __argv);
}
#endif
void* operator new(size_t count)
{
auto p = malloc(count);

View file

@ -31,7 +31,7 @@
#ifdef HAVE_SDLNET
#include "SDL_net.h"
#include <SDL3_net/SDL_net.h>
#define MAXBANS 20

View file

@ -69,7 +69,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#ifdef HAVE_SDL
#define _MATH_DEFINES_DEFINED
#include "SDL.h"
#include <SDL3/SDL.h>
#ifdef HAVE_TTF
#include "i_ttf.h"
@ -79,7 +79,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#pragma warning(default : 4214 4244)
#endif
#include "SDL_cpuinfo.h"
#include <SDL3/SDL_cpuinfo.h>
#define HAVE_SDLCPUINFO
#if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__))
@ -216,8 +216,8 @@ static std::thread::id g_main_thread_id;
*/
SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS];
SDL_bool consolevent = SDL_FALSE;
SDL_bool framebuffer = SDL_FALSE;
bool consolevent = false;
bool framebuffer = false;
UINT8 keyboard_started = false;
boolean g_in_exiting_signal_handler = false;
@ -649,7 +649,7 @@ FUNCNORETURN static ATTRNORETURN void quit_handler(int num)
#ifdef HAVE_TERMIOS
// TERMIOS console code from Quake3: thank you!
SDL_bool stdin_active = SDL_TRUE;
bool stdin_active = true;
typedef struct
{
@ -755,7 +755,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);
}
}
@ -770,18 +770,18 @@ static void I_StartupConsole(void)
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
consolevent = static_cast<SDL_bool>(!M_CheckParm("-noconsole"));
framebuffer = static_cast<SDL_bool>(M_CheckParm("-framebuffer"));
consolevent = static_cast<bool>(!M_CheckParm("-noconsole"));
framebuffer = static_cast<bool>(M_CheckParm("-framebuffer"));
if (framebuffer)
consolevent = SDL_FALSE;
consolevent = false;
if (!consolevent) return;
if (isatty(STDIN_FILENO)!=1)
{
I_OutputMsg("stdin is not a tty, tty console mode failed\n");
consolevent = SDL_FALSE;
consolevent = false;
return;
}
memset(&tty_con, 0x00, sizeof(tty_con));
@ -959,7 +959,7 @@ static void I_StartupConsole(void)
if (gotConsole)
{
SetConsoleTitleA("Dr. Robotnik's Ring Racers Console");
consolevent = SDL_TRUE;
consolevent = true;
}
//Let get the real console HANDLE, because Mingw's Bash is bad!
@ -984,15 +984,15 @@ void I_GetConsoleEvents(void){}
static inline void I_StartupConsole(void)
{
#ifdef _DEBUG
consolevent = M_CheckParm("-noconsole") > 0 ? SDL_FALSE : SDL_TRUE;
consolevent = M_CheckParm("-noconsole") > 0 ? false : true;
#else
consolevent = M_CheckParm("-console") > 0 ? SDL_TRUE : SDL_FALSE;
consolevent = M_CheckParm("-console") > 0 ? true : false;
#endif
framebuffer = M_CheckParm("-framebuffer") > 0 ? SDL_TRUE : SDL_FALSE;
framebuffer = M_CheckParm("-framebuffer") > 0 ? true : false;
if (framebuffer)
consolevent = SDL_FALSE;
consolevent = false;
}
static inline void I_ShutdownConsole(void){}
#endif
@ -1208,21 +1208,12 @@ I_CursedWindowMovement (int xd, int yd)
boolean I_HasOpenURL()
{
#if (SDL_VERSION_ATLEAST(2, 0, 14))
return true;
#else
return false;
#endif
return true;
}
void I_OpenURL(const char *data)
{
#if (SDL_VERSION_ATLEAST(2, 0, 14))
SDL_OpenURL(data);
#else
(void)data;
return;
#endif
SDL_OpenURL(data);
}
//
@ -1254,48 +1245,36 @@ void I_JoyScale4(void)
void I_SetGamepadPlayerIndex(INT32 device_id, INT32 player)
{
#if !(SDL_VERSION_ATLEAST(2,0,12))
(void)device_id;
(void)player;
#else
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
I_Assert(player >= 0 && player < MAXSPLITSCREENPLAYERS);
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_Gamepad *controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
return;
}
SDL_GameControllerSetPlayerIndex(controller, player);
#endif
SDL_SetGamepadPlayerIndex(controller, player);
}
void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue)
{
#if !(SDL_VERSION_ATLEAST(2,0,14))
(void)device_id;
(void)red;
(void)green;
(void)blue;
#else
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_Gamepad *controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
return;
}
SDL_GameControllerSetLED(controller, red, green, blue);
#endif
SDL_SetGamepadLED(controller, red, green, blue);
}
void I_GetGamepadGuid(INT32 device_id, char *out, int out_len)
{
SDL_GameController *controller;
SDL_Gamepad *controller;
SDL_Joystick *joystick;
SDL_JoystickGUID guid;
SDL_GUID guid;
I_Assert(device_id > 0);
I_Assert(out != NULL);
@ -1307,26 +1286,26 @@ void I_GetGamepadGuid(INT32 device_id, char *out, int out_len)
return;
}
controller = SDL_GameControllerFromInstanceID(device_id - 1);
controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
out[0] = 0;
return;
}
joystick = SDL_GameControllerGetJoystick(controller);
joystick = SDL_GetGamepadJoystick(controller);
if (joystick == NULL)
{
out[0] = 0;
return;
}
guid = SDL_JoystickGetGUID(joystick);
SDL_JoystickGetGUIDString(guid, out, out_len);
guid = SDL_GetJoystickGUID(joystick);
SDL_GUIDToString(guid, out, out_len);
}
void I_GetGamepadName(INT32 device_id, char *out, int out_len)
{
SDL_GameController *controller;
SDL_Gamepad *controller;
const char *name;
int name_len;
@ -1334,14 +1313,14 @@ void I_GetGamepadName(INT32 device_id, char *out, int out_len)
I_Assert(out != NULL);
I_Assert(out_len > 0);
controller = SDL_GameControllerFromInstanceID(device_id - 1);
controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
out[0] = 0;
return;
}
name = SDL_GameControllerName(controller);
name = SDL_GetGamepadName(controller);
name_len = strlen(name) + 1;
memcpy(out, name, out_len < name_len ? out_len : name_len);
out[out_len - 1] = 0;
@ -1349,40 +1328,28 @@ void I_GetGamepadName(INT32 device_id, char *out, int out_len)
void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength)
{
#if !(SDL_VERSION_ATLEAST(2,0,9))
(void)device_id;
(void)low_strength;
(void)high_strength;
#else
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_Gamepad *controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
return;
}
SDL_GameControllerRumble(controller, low_strength, high_strength, 0);
#endif
SDL_RumbleGamepad(controller, low_strength, high_strength, 0);
}
void I_GamepadRumbleTriggers(INT32 device_id, UINT16 left_strength, UINT16 right_strength)
{
#if !(SDL_VERSION_ATLEAST(2,0,14))
(void)device_id;
(void)left_strength;
(void)right_strength;
#else
I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher
SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1);
SDL_Gamepad *controller = SDL_GetGamepadFromID(device_id - 1);
if (controller == NULL)
{
return;
}
SDL_GameControllerRumbleTriggers(controller, left_strength, right_strength, 0);
#endif
SDL_RumbleGamepadTriggers(controller, left_strength, right_strength, 0);
}
//
@ -1396,16 +1363,16 @@ void I_StartupInput(void)
{
char dbpath[1024];
sprintf(dbpath, "%s" PATHSEP "gamecontrollerdb.txt", srb2path);
SDL_GameControllerAddMappingsFromFile(dbpath);
SDL_AddGamepadMappingsFromFile(dbpath);
}
{
char dbpath[1024];
sprintf(dbpath, "%s" PATHSEP "gamecontrollerdb_user.txt", srb2home);
SDL_GameControllerAddMappingsFromFile(dbpath);
SDL_AddGamepadMappingsFromFile(dbpath);
}
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER))
if (SDL_WasInit(SDL_INIT_GAMEPAD))
{
return;
}
@ -1418,7 +1385,7 @@ void I_StartupInput(void)
CONS_Printf("I_StartupInput()...\n");
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1)
if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD))
{
CONS_Printf(M_GetText("Couldn't initialize game controllers: %s\n"), SDL_GetError());
return;
@ -1433,10 +1400,10 @@ static void I_ShutdownInput(void)
// The game code is now responsible for resetting its internal state based on ev_gamepad_device_removed events.
// In practice, Input should never be shutdown and restarted during runtime.
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");
}
@ -1452,7 +1419,12 @@ INT32 I_NumJoys(void)
{
INT32 numjoy = 0;
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
numjoy = SDL_NumJoysticks();
{
int count = 0;
SDL_JoystickID *joysticks = SDL_GetJoysticks(&count);
numjoy = count;
if (joysticks) SDL_free(joysticks);
}
return numjoy;
}
@ -1471,13 +1443,13 @@ const char *I_GetJoyName(INT32 joyindex)
}
// joyindex corresponds to the open joystick *instance* ID, not the joystick number
joystick = SDL_JoystickFromInstanceID(joyindex);
joystick = SDL_GetJoystickFromID(joyindex);
if (joystick == NULL)
{
return joyname;
}
tempname = SDL_JoystickNameForIndex(joyindex);
tempname = SDL_GetJoystickName(joystick);
if (tempname)
{
strncpy(joyname, tempname, 254);
@ -1810,10 +1782,8 @@ static void I_Fork(void)
INT32 I_StartupSystem(void)
{
SDL_version SDLcompiled;
SDL_version SDLlinked;
SDL_VERSION(&SDLcompiled)
SDL_GetVersion(&SDLlinked);
Uint32 SDLcompiled = SDL_VERSION;
Uint32 SDLlinked = SDL_GetVersion();
I_StartupConsole();
#ifdef NEWSIGNALHANDLER
// This is useful when debugging. It lets GDB attach to
@ -1829,15 +1799,13 @@ INT32 I_StartupSystem(void)
#endif
I_RegisterSignals();
I_OutputMsg("Compiled for SDL version: %d.%d.%d\n",
SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch);
SDL_VERSIONNUM_MAJOR(SDLcompiled), SDL_VERSIONNUM_MINOR(SDLcompiled), SDL_VERSIONNUM_MICRO(SDLcompiled));
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, "Dr. Robotnik's Ring Racers");
#endif
SDL_SetHint(SDL_HINT_APP_NAME, "Dr. Robotnik's Ring Racers");
if (SDL_Init(0) < 0)
if (!SDL_Init(0))
I_Error("Dr. Robotnik's Ring Racers: SDL System Error: %s", SDL_GetError()); //Alam: Oh no....
#ifndef NOMUMBLE
I_SetupMumble();
@ -1850,12 +1818,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;
M_SaveConfig(NULL); //save game config, cvars..
M_SaveJoinedIPs();

View file

@ -13,7 +13,7 @@
#include "../doomdef.h"
#include "../i_threads.h"
#include <SDL.h>
#include <SDL3/SDL.h>
typedef void * (*Create_fn)(void);
@ -46,7 +46,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 (
@ -104,13 +104,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)
{
@ -121,7 +121,7 @@ Identity (
Insert_link(pool_anchor, New_link(id));
SDL_AtomicSetPtr(anchor, id);
SDL_SetAtomicPointer(anchor, id);
}
}
I_unlock_mutex(pool_mutex);
@ -140,11 +140,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);
@ -177,7 +177,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,
@ -195,7 +195,7 @@ I_spawn_thread (
int
I_thread_is_stopped (void)
{
return ( ! SDL_AtomicGet(&i_threads_running) );
return ( ! SDL_GetAtomicInt(&i_threads_running) );
}
void
@ -221,13 +221,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);
{
@ -268,7 +268,7 @@ I_stop_threads (void)
next = link->next;
cond = link->data;
SDL_DestroyCond(cond);
SDL_DestroyCondition(cond);
free(link);
}
@ -283,7 +283,7 @@ void
I_lock_mutex (
I_mutex * anchor
){
SDL_mutex * mutex;
SDL_Mutex * mutex;
mutex = Identity(
&i_mutex_pool,
@ -292,16 +292,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
@ -309,49 +307,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);
}

View file

@ -12,8 +12,8 @@
/// \brief SDL_ttf interface code. Necessary for platforms with no framebuffer console systems.
#if defined(HAVE_SDL) && defined(HAVE_TTF)
#include "SDL.h"
#include "SDL_ttf.h"
#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
#include "../doomdef.h"
#include "../doomstat.h"
#include "../d_netfil.h"

View file

@ -15,7 +15,7 @@
#define __I_TTF__
#include "../doomdef.h"
#include <SDL_ttf.h>
#include <SDL3_ttf/SDL_ttf.h>
#ifdef __cplusplus
extern "C" {

View file

@ -12,7 +12,9 @@
/// \file
/// \brief SRB2 graphics stuff for SDL
#include <SDL_video.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_pixels.h>
#include <SDL3/SDL_video.h>
#include <stdlib.h>
#include <errno.h>
#include <memory>
@ -31,7 +33,7 @@
#ifdef HAVE_SDL
#define _MATH_DEFINES_DEFINED
#include "SDL.h"
#include <SDL3/SDL.h>
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
@ -44,13 +46,8 @@
#include "i_ttf.h"
#endif
#ifdef HAVE_IMAGE
#include "SDL_image.h"
#elif defined (__unix__) || (!defined(__APPLE__) && defined (UNIXCOMMON)) // Windows & Mac don't need this, as SDL will do it for us.
#define LOAD_XPM //I want XPM!
#include "IMG_xpm.c" //Alam: I don't want to add SDL_Image.dll/so
#define HAVE_IMAGE //I have SDL_Image, sortof
#endif
#ifdef HAVE_IMAGE
#include "SDL_icon.xpm"
@ -58,10 +55,6 @@
#include "../doomdef.h"
#ifdef _WIN32
#include "SDL_syswm.h"
#endif
#include "../doomstat.h"
#include "../i_system.h"
#include "../v_video.h"
@ -113,9 +106,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
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
@ -133,13 +126,13 @@ static SDL_Surface *icoSurface = NULL;
static SDL_Color localPalette[256];
Uint16 realwidth = BASEVIDWIDTH;
Uint16 realheight = BASEVIDHEIGHT;
static SDL_bool mousegrabok = SDL_TRUE;
static SDL_bool exposevideo = SDL_FALSE;
static SDL_bool borderlesswindow = SDL_FALSE;
static bool mousegrabok = true;
static bool exposevideo = false;
static bool borderlesswindow = false;
// SDL2 vars
// SDL vars
SDL_Window *window;
static SDL_bool havefocus = SDL_TRUE;
static bool havefocus = true;
static const char *fallback_resolution_name = "Fallback";
static std::unique_ptr<rhi::Rhi> g_rhi;
@ -170,16 +163,16 @@ static INT32 windowedModes[MAXWINMODES][2] =
};
static void Impl_VideoSetupBuffer(void);
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen);
static bool Impl_CreateWindow(bool fullscreen);
//static void Impl_SetWindowName(const char *title);
static void Impl_SetWindowIcon(void);
static void ValidateDisplay(void)
{
// Validate display index, otherwise use main display
if (cv_display.value >= SDL_GetNumVideoDisplays())
// Validate display ID, otherwise use main display
if (cv_display.value == 0)
{
CV_SetValue(&cv_display, 0);
CV_SetValue(&cv_display, static_cast<INT32>(SDL_GetPrimaryDisplay()));
}
}
@ -191,9 +184,9 @@ static void CenterWindow(void)
);
}
static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool reposition)
static void SDLSetMode(int width, int height, bool fullscreen, bool reposition)
{
static SDL_bool wasfullscreen = SDL_FALSE;
static bool wasfullscreen = false;
realwidth = vid.width;
realheight = vid.height;
@ -205,20 +198,21 @@ static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool repo
if (reposition)
{
ValidateDisplay();
if (SDL_GetWindowDisplayIndex(window) != cv_display.value)
if (SDL_GetDisplayForWindow(window) != cv_display.value)
{
CenterWindow();
}
}
wasfullscreen = SDL_TRUE;
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
wasfullscreen = true;
SDL_SetWindowFullscreenMode(window, NULL);
SDL_SetWindowFullscreen(window, true);
}
else // windowed mode
{
if (wasfullscreen)
{
wasfullscreen = SDL_FALSE;
SDL_SetWindowFullscreen(window, 0);
wasfullscreen = false;
SDL_SetWindowFullscreen(window, false);
}
// Reposition window only in windowed mode
SDL_SetWindowSize(window, width, height);
@ -231,12 +225,16 @@ static void SDLSetMode(int width, int height, SDL_bool fullscreen, SDL_bool repo
}
else
{
Impl_CreateWindow(fullscreen);
if (!Impl_CreateWindow(fullscreen))
{
return;
}
wasfullscreen = fullscreen;
SDL_SetWindowSize(window, width, height);
if (fullscreen)
{
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowFullscreenMode(window, NULL);
SDL_SetWindowFullscreen(window, true);
}
}
@ -375,28 +373,16 @@ static void VID_Command_NumModes_f (void)
CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes());
}
// SDL2 doesn't have SDL_GetVideoSurface or a lot of the SDL_Surface flags that SDL 1.2 had
static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText)
{
INT32 vfBPP;
if (!infoSurface)
return;
if (!SurfaceText)
SurfaceText = M_GetText("Unknown Surface");
vfBPP = infoSurface->format?infoSurface->format->BitsPerPixel:0;
CONS_Printf("\x82" "%s\n", SurfaceText);
CONS_Printf(M_GetText(" %ix%i at %i bit color\n"), infoSurface->w, infoSurface->h, vfBPP);
if (infoSurface->flags&SDL_PREALLOC)
CONS_Printf("%s", M_GetText(" Uses preallocated memory\n"));
else
CONS_Printf("%s", M_GetText(" Stored in system memory\n"));
if (infoSurface->flags&SDL_RLEACCEL)
CONS_Printf("%s", M_GetText(" Colorkey RLE acceleration blit\n"));
CONS_Printf(M_GetText(" %ix%i, %s\n"), infoSurface->w, infoSurface->h, SDL_GetPixelFormatName(infoSurface->format));
}
static void VID_Command_Info_f (void)
@ -409,9 +395,6 @@ static void VID_Command_ModeList_f(void)
{
// List windowed modes
INT32 i = 0;
CONS_Printf("NOTE: Under SDL2, all modes are supported on all platforms.\n");
CONS_Printf("Under opengl, fullscreen only supports native desktop resolution.\n");
CONS_Printf("Under software, the mode is stretched up to desktop resolution.\n");
for (i = 0; i < MAXWINMODES; i++)
{
CONS_Printf("%2d: %dx%d\n", i, windowedModes[i][0], windowedModes[i][1]);
@ -473,43 +456,45 @@ static INT32 SDLJoyAxis(const Sint16 axis, UINT8 pid)
static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{
#define FOCUSUNION static_cast<unsigned int>(mousefocus | (kbfocus << 1))
static SDL_bool firsttimeonmouse = SDL_TRUE;
static SDL_bool mousefocus = SDL_TRUE;
static SDL_bool kbfocus = SDL_TRUE;
static bool firsttimeonmouse = true;
static bool mousefocus = true;
static bool kbfocus = true;
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;
SDL_ShowCursor(SDL_FALSE);
case SDL_EVENT_WINDOW_FOCUS_GAINED:
kbfocus = true;
mousefocus = true;
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:
case SDL_EVENT_WINDOW_MAXIMIZED:
break;
case SDL_WINDOWEVENT_MOVED:
case SDL_EVENT_WINDOW_MOVED:
window_x = evt.data1;
window_y = evt.data2;
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_EVENT_WINDOW_RESIZED:
vid.realwidth = evt.data1;
vid.realheight = evt.data2;
break;
case SDL_WINDOWEVENT_DISPLAY_CHANGED:
case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
CV_SetValue(&cv_display, evt.data1);
break;
default:
break;
}
if (FOCUSUNION == oldfocus) // No state change
@ -553,11 +538,11 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
event.device = 0;
if (type == SDL_KEYUP)
if (type == SDL_EVENT_KEY_UP)
{
event.type = ev_keyup;
}
else if (type == SDL_KEYDOWN)
else if (type == SDL_EVENT_KEY_DOWN)
{
event.type = ev_keydown;
}
@ -565,7 +550,7 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
{
return;
}
event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode);
event.data1 = Impl_SDL_Scancode_To_Keycode(evt.scancode);
event.data2 = evt.repeat;
if (event.data1) D_PostEvent(&event);
}
@ -593,11 +578,11 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
{
event.device = 0;
if (type == SDL_MOUSEBUTTONUP)
if (type == SDL_EVENT_MOUSE_BUTTON_UP)
{
event.type = ev_keyup;
}
else if (type == SDL_MOUSEBUTTONDOWN)
else if (type == SDL_EVENT_MOUSE_BUTTON_DOWN)
{
event.type = ev_keydown;
}
@ -648,7 +633,7 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
}
}
static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt)
{
event_t event;
INT32 value;
@ -686,7 +671,7 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
D_PostEvent(&event);
}
static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type)
static void Impl_HandleControllerButtonEvent(SDL_GamepadButtonEvent evt, Uint32 type)
{
event_t event;
@ -700,11 +685,11 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint
event.data1 = KEY_JOY1;
event.data2 = 0;
if (type == SDL_CONTROLLERBUTTONUP)
if (type == SDL_EVENT_GAMEPAD_BUTTON_UP)
{
event.type = ev_keyup;
}
else if (type == SDL_CONTROLLERBUTTONDOWN)
else if (type == SDL_EVENT_GAMEPAD_BUTTON_DOWN)
{
event.type = ev_keydown;
}
@ -730,19 +715,19 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint
}
}
static void Impl_HandleControllerDeviceAddedEvent(SDL_ControllerDeviceEvent event)
static void Impl_HandleControllerDeviceAddedEvent(SDL_GamepadDeviceEvent event)
{
// The game is always interested in controller events, even if they aren't internally assigned to a player.
// Thus, we *always* open SDL controllers as they become available, to begin receiving their events.
SDL_GameController* controller = SDL_GameControllerOpen(event.which);
SDL_Gamepad* controller = SDL_OpenGamepad(event.which);
if (controller == NULL)
{
return;
}
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
SDL_JoystickID joystick_instance_id = SDL_JoystickInstanceID(joystick);
SDL_Joystick* joystick = SDL_GetGamepadJoystick(controller);
SDL_JoystickID joystick_instance_id = SDL_GetJoystickID(joystick);
event_t engine_event {};
@ -752,7 +737,7 @@ static void Impl_HandleControllerDeviceAddedEvent(SDL_ControllerDeviceEvent even
D_PostEvent(&engine_event);
}
static void Impl_HandleControllerDeviceRemovedEvent(SDL_ControllerDeviceEvent event)
static void Impl_HandleControllerDeviceRemovedEvent(SDL_GamepadDeviceEvent event)
{
// SDL only posts Device Removed events for controllers that have actually been opened.
// Thus, we don't need to filter out controllers that may not have opened successfully prior to this event.
@ -764,7 +749,7 @@ static void Impl_HandleControllerDeviceRemovedEvent(SDL_ControllerDeviceEvent ev
D_PostEvent(&engine_event);
}
static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
{
switch (keycode)
{
@ -783,7 +768,7 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
case SDLK_SPACE: return ImGuiKey_Space;
case SDLK_RETURN: return ImGuiKey_Enter;
case SDLK_ESCAPE: return ImGuiKey_Escape;
case SDLK_QUOTE: return ImGuiKey_Apostrophe;
case SDLK_APOSTROPHE: return ImGuiKey_Apostrophe;
case SDLK_COMMA: return ImGuiKey_Comma;
case SDLK_MINUS: return ImGuiKey_Minus;
case SDLK_PERIOD: return ImGuiKey_Period;
@ -793,7 +778,7 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
case SDLK_BACKSLASH: return ImGuiKey_Backslash;
case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
case SDLK_BACKQUOTE: return ImGuiKey_GraveAccent;
case SDLK_GRAVE: return ImGuiKey_GraveAccent;
case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
@ -835,32 +820,32 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
case SDLK_7: return ImGuiKey_7;
case SDLK_8: return ImGuiKey_8;
case SDLK_9: return ImGuiKey_9;
case SDLK_a: return ImGuiKey_A;
case SDLK_b: return ImGuiKey_B;
case SDLK_c: return ImGuiKey_C;
case SDLK_d: return ImGuiKey_D;
case SDLK_e: return ImGuiKey_E;
case SDLK_f: return ImGuiKey_F;
case SDLK_g: return ImGuiKey_G;
case SDLK_h: return ImGuiKey_H;
case SDLK_i: return ImGuiKey_I;
case SDLK_j: return ImGuiKey_J;
case SDLK_k: return ImGuiKey_K;
case SDLK_l: return ImGuiKey_L;
case SDLK_m: return ImGuiKey_M;
case SDLK_n: return ImGuiKey_N;
case SDLK_o: return ImGuiKey_O;
case SDLK_p: return ImGuiKey_P;
case SDLK_q: return ImGuiKey_Q;
case SDLK_r: return ImGuiKey_R;
case SDLK_s: return ImGuiKey_S;
case SDLK_t: return ImGuiKey_T;
case SDLK_u: return ImGuiKey_U;
case SDLK_v: return ImGuiKey_V;
case SDLK_w: return ImGuiKey_W;
case SDLK_x: return ImGuiKey_X;
case SDLK_y: return ImGuiKey_Y;
case SDLK_z: return ImGuiKey_Z;
case SDLK_A: return ImGuiKey_A;
case SDLK_B: return ImGuiKey_B;
case SDLK_C: return ImGuiKey_C;
case SDLK_D: return ImGuiKey_D;
case SDLK_E: return ImGuiKey_E;
case SDLK_F: return ImGuiKey_F;
case SDLK_G: return ImGuiKey_G;
case SDLK_H: return ImGuiKey_H;
case SDLK_I: return ImGuiKey_I;
case SDLK_J: return ImGuiKey_J;
case SDLK_K: return ImGuiKey_K;
case SDLK_L: return ImGuiKey_L;
case SDLK_M: return ImGuiKey_M;
case SDLK_N: return ImGuiKey_N;
case SDLK_O: return ImGuiKey_O;
case SDLK_P: return ImGuiKey_P;
case SDLK_Q: return ImGuiKey_Q;
case SDLK_R: return ImGuiKey_R;
case SDLK_S: return ImGuiKey_S;
case SDLK_T: return ImGuiKey_T;
case SDLK_U: return ImGuiKey_U;
case SDLK_V: return ImGuiKey_V;
case SDLK_W: return ImGuiKey_W;
case SDLK_X: return ImGuiKey_X;
case SDLK_Y: return ImGuiKey_Y;
case SDLK_Z: return ImGuiKey_Z;
case SDLK_F1: return ImGuiKey_F1;
case SDLK_F2: return ImGuiKey_F2;
case SDLK_F3: return ImGuiKey_F3;
@ -877,13 +862,13 @@ static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
return ImGuiKey_None;
}
static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
static void ImGui_ImplSDL3_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
{
ImGuiIO& io = ImGui::GetIO();
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & KMOD_CTRL) != 0);
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & KMOD_SHIFT) != 0);
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & KMOD_ALT) != 0);
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0);
io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & SDL_KMOD_CTRL) != 0);
io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & SDL_KMOD_SHIFT) != 0);
io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & SDL_KMOD_ALT) != 0);
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & SDL_KMOD_GUI) != 0);
}
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
@ -891,26 +876,26 @@ static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
{
ImGuiIO& io = ImGui::GetIO();
switch (event->type)
{
case SDL_MOUSEMOTION:
case SDL_EVENT_MOUSE_MOTION:
{
io.AddMousePosEvent((float)event->motion.x, (float)event->motion.y);
return true;
}
case SDL_MOUSEWHEEL:
case SDL_EVENT_MOUSE_WHEEL:
{
float wheel_x = (event->wheel.x > 0) ? 1.0f : (event->wheel.x < 0) ? -1.0f : 0.0f;
float wheel_y = (event->wheel.y > 0) ? 1.0f : (event->wheel.y < 0) ? -1.0f : 0.0f;
io.AddMouseWheelEvent(wheel_x, wheel_y);
return true;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
{
int mouse_button = -1;
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
@ -920,42 +905,39 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
if (mouse_button == -1)
break;
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN));
// bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
io.AddMouseButtonEvent(mouse_button, (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN));
return true;
}
case SDL_TEXTINPUT:
case SDL_EVENT_TEXT_INPUT:
{
io.AddInputCharactersUTF8(event->text.text);
return true;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
{
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.mod);
ImGuiKey key = ImGui_ImplSDL3_KeycodeToImGuiKey(event->key.key);
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
io.SetKeyEventNativeData(key, event->key.key, event->key.scancode, event->key.scancode);
return true;
}
case SDL_WINDOWEVENT:
case SDL_EVENT_WINDOW_MOUSE_ENTER:
{
// - When capturing mouse, SDL will send a bunch of conflicting LEAVE/ENTER event on every mouse move, but the final ENTER tends to be right.
// - However we won't get a correct LEAVE event for a captured window.
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
// causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
// we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
Uint8 window_event = event->window.event;
if (window_event == SDL_WINDOWEVENT_ENTER)
(void)0;
// bd->PendingMouseLeaveFrame = 0;
if (window_event == SDL_WINDOWEVENT_LEAVE)
(void)0;
// bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1;
if (window_event == SDL_WINDOWEVENT_FOCUS_GAINED)
io.AddFocusEvent(true);
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
io.AddFocusEvent(false);
return true;
}
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
{
return true;
}
case SDL_EVENT_WINDOW_FOCUS_GAINED:
{
io.AddFocusEvent(true);
return true;
}
case SDL_EVENT_WINDOW_FOCUS_LOST:
{
io.AddFocusEvent(false);
return true;
}
}
@ -981,7 +963,7 @@ void I_GetEvent(void)
while (SDL_PollEvent(&evt))
{
ImGui_ImplSDL2_ProcessEvent(&evt);
ImGui_ImplSDL3_ProcessEvent(&evt);
if (io.WantCaptureMouse || io.WantCaptureKeyboard)
{
continue;
@ -989,45 +971,55 @@ void I_GetEvent(void)
switch (evt.type)
{
case SDL_WINDOWEVENT:
case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_WINDOW_FOCUS_GAINED:
case SDL_EVENT_WINDOW_FOCUS_LOST:
case SDL_EVENT_WINDOW_MAXIMIZED:
case SDL_EVENT_WINDOW_MOVED:
case SDL_EVENT_WINDOW_RESIZED:
case SDL_EVENT_WINDOW_DISPLAY_CHANGED:
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:
//if (!mouseMotionOnce)
Impl_HandleMouseMotionEvent(evt.motion);
//mouseMotionOnce = 1;
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:
Impl_HandleControllerDeviceAddedEvent(evt.cdevice);
case SDL_EVENT_GAMEPAD_ADDED:
Impl_HandleControllerDeviceAddedEvent(evt.gdevice);
break;
case SDL_CONTROLLERDEVICEREMOVED:
Impl_HandleControllerDeviceRemovedEvent(evt.cdevice);
case SDL_EVENT_GAMEPAD_REMOVED:
Impl_HandleControllerDeviceRemovedEvent(evt.gdevice);
break;
case SDL_QUIT:
case SDL_EVENT_QUIT:
LUA_HookBool(true, HOOK(GameQuit));
I_Quit();
break;
default:
break;
}
}
@ -1055,7 +1047,7 @@ void I_StartupMouse(void)
if (disable_mouse)
return;
SDL_ShowCursor(SDL_FALSE);
SDL_HideCursor();
}
//
@ -1068,8 +1060,8 @@ void I_OsPolling(void)
if (consolevent)
I_GetConsoleEvents();
if (SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER))
SDL_GameControllerUpdate();
if (SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD) == (SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD))
SDL_UpdateGamepads();
I_GetEvent();
@ -1077,13 +1069,13 @@ void I_OsPolling(void)
/* Handle here so that our state is always synched with the system. */
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;
}
//
@ -1102,7 +1094,7 @@ void I_UpdateNoBlit(void)
}
#endif
}
exposevideo = SDL_FALSE;
exposevideo = false;
}
//
@ -1264,7 +1256,7 @@ INT32 VID_GetModeForSize(INT32 w, INT32 h)
void VID_PrepareModeList(void)
{
// Under SDL2, we just use the windowed modes list, and scale in windowed fullscreen.
// Under SDL3, we just use the windowed modes list, and scale in windowed fullscreen.
allow_fullscreen = true;
#if 0
INT32 i;
@ -1319,7 +1311,7 @@ static void init_imgui()
ImGui::StyleColorsDark();
}
static SDL_bool Impl_CreateContext(void)
static bool Impl_CreateContext(void)
{
if (!sdlglcontext)
{
@ -1351,7 +1343,7 @@ static SDL_bool Impl_CreateContext(void)
g_rhi_generation += 1;
}
return SDL_TRUE;
return true;
}
void VID_CheckGLLoaded(rendermode_t oldrender)
@ -1389,7 +1381,7 @@ boolean VID_CheckRenderer(void)
setrenderneeded = 0;
}
SDLSetMode(vid.width, vid.height, static_cast<SDL_bool>(USE_FULLSCREEN), (setmodeneeded ? SDL_TRUE : SDL_FALSE));
SDLSetMode(vid.width, vid.height, static_cast<bool>(USE_FULLSCREEN), (setmodeneeded ? true : false));
Impl_VideoSetupBuffer();
if (rendermode == render_soft)
@ -1412,22 +1404,22 @@ boolean VID_CheckRenderer(void)
static UINT32 refresh_rate;
static UINT32 VID_GetRefreshRate(void)
{
int index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayMode m;
if (SDL_WasInit(SDL_INIT_VIDEO) == 0)
{
// Video not init yet.
return 0;
}
if (SDL_GetCurrentDisplayMode(index, &m) != 0)
SDL_DisplayID display_id = SDL_GetDisplayForWindow(window);
const SDL_DisplayMode *m = SDL_GetCurrentDisplayMode(display_id);
if (m == nullptr)
{
// Error has occurred.
return 0;
}
return m.refresh_rate;
return static_cast<UINT32>(m->refresh_rate);
}
INT32 VID_SetMode(INT32 modeNum)
@ -1452,21 +1444,21 @@ INT32 VID_SetMode(INT32 modeNum)
refresh_rate = VID_GetRefreshRate();
VID_CheckRenderer();
return SDL_TRUE;
return true;
}
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
static bool Impl_CreateWindow(bool fullscreen)
{
uint32_t flags = SDL_WINDOW_RESIZABLE;
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;
@ -1475,13 +1467,18 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen)
flags |= SDL_WINDOW_OPENGL;
// Create a window
window = SDL_CreateWindow("Dr. Robotnik's Ring Racers " VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
window = SDL_CreateWindow("Dr. Robotnik's Ring Racers " VERSIONSTRING,
realwidth, realheight, flags);
if (window == NULL)
{
CONS_Printf(M_GetText("Couldn't create window: %s\n"), SDL_GetError());
return SDL_FALSE;
return false;
}
if (!fullscreen)
{
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
Impl_SetWindowIcon();
@ -1526,14 +1523,14 @@ void I_StartupGraphics(void)
COM_AddCommand ("vid_modelist", VID_Command_ModeList_f);
COM_AddCommand ("vid_mode", VID_Command_Mode_f);
CV_RegisterList(cvlist_graphics_driver);
disable_mouse = static_cast<SDL_bool>(M_CheckParm("-nomouse"));
disable_fullscreen = M_CheckParm("-win") ? SDL_TRUE : SDL_FALSE;
disable_mouse = static_cast<bool>(M_CheckParm("-nomouse"));
disable_fullscreen = M_CheckParm("-win") ? true : false;
keyboard_started = true;
#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;
@ -1579,7 +1576,7 @@ void I_StartupGraphics(void)
if (chosenrendermode != render_none)
rendermode = chosenrendermode;
borderlesswindow = M_CheckParm("-borderless") ? SDL_TRUE : SDL_FALSE;
borderlesswindow = M_CheckParm("-borderless") ? true : false;
VID_Command_ModeList_f();
@ -1589,7 +1586,7 @@ void I_StartupGraphics(void)
#endif
// Window icon
#ifdef HAVE_IMAGE
#if defined(HAVE_IMAGE) && (defined (__unix__) || (!defined(__APPLE__) && defined (UNIXCOMMON)))
icoSurface = IMG_ReadXPMFromArray(SDL_icon_xpm);
#endif
@ -1605,7 +1602,7 @@ void I_StartupGraphics(void)
VID_SetMode(VID_GetModeForSize(BASEVIDWIDTH, BASEVIDHEIGHT));
if (M_CheckParm("-nomousegrab"))
mousegrabok = SDL_FALSE;
mousegrabok = false;
realwidth = (Uint16)vid.width;
realheight = (Uint16)vid.height;
@ -1683,7 +1680,7 @@ void VID_StartupOpenGL(void)
void I_ShutdownGraphics(void)
{
rendermode = render_none;
if (icoSurface) SDL_FreeSurface(icoSurface);
if (icoSurface) SDL_DestroySurface(icoSurface);
icoSurface = NULL;
I_OutputMsg("I_ShutdownGraphics(): ");
@ -1695,16 +1692,21 @@ void I_ShutdownGraphics(void)
}
graphics_started = false;
g_rhi.reset();
g_rhi_generation = 0;
#ifdef HWRENDER
if (GLUhandle)
hwClose(GLUhandle);
if (sdlglcontext)
{
SDL_GL_DeleteContext(sdlglcontext);
SDL_GL_DestroyContext(sdlglcontext);
sdlglcontext = nullptr;
}
#endif
window = NULL;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
framebuffer = SDL_FALSE;
framebuffer = false;
}
rhi::Rhi* srb2::sys::get_rhi(rhi::Handle<rhi::Rhi> handle)

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,12 @@
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
#include <SDL3/SDL_audio.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <SDL.h>
#include <SDL3/SDL.h>
#include <tracy/tracy/Tracy.hpp>
#include "../audio/chunk_load.hpp"
@ -23,7 +24,6 @@
#include "../audio/sound_chunk.hpp"
#include "../audio/sound_effect_player.hpp"
#include "../cxxutil.hpp"
#include "../io/streams.hpp"
#ifdef SRB2_CONFIG_ENABLE_WEBM_MOVIES
#include "../m_avrecorder.hpp"
@ -52,7 +52,6 @@ using srb2::audio::SoundChunk;
using srb2::audio::SoundEffectPlayer;
using srb2::audio::Source;
using namespace srb2;
using namespace srb2::io;
namespace
{
@ -62,7 +61,15 @@ class SdlAudioStream final
public:
SdlAudioStream(const SDL_AudioFormat format, const Uint8 channels, const int src_rate, const SDL_AudioFormat dst_format, const Uint8 dst_channels, const int dst_rate) noexcept
{
stream_ = SDL_NewAudioStream(format, channels, src_rate, dst_format, dst_channels, dst_rate);
SDL_AudioSpec src {};
src.channels = channels;
src.freq = src_rate;
src.format = format;
SDL_AudioSpec dst {};
dst.channels = dst_channels;
dst.freq = dst_rate;
dst.format = dst_format;
stream_ = SDL_CreateAudioStream(&src, &dst);
}
SdlAudioStream(const SdlAudioStream&) = delete;
SdlAudioStream(SdlAudioStream&&) = default;
@ -70,27 +77,28 @@ public:
SdlAudioStream& operator=(SdlAudioStream&&) = default;
~SdlAudioStream()
{
SDL_FreeAudioStream(stream_);
SDL_DestroyAudioStream(stream_);
}
void put(tcb::span<const std::byte> buf)
{
int result = SDL_AudioStreamPut(stream_, buf.data(), buf.size_bytes());
if (result < 0)
if (!SDL_PutAudioStreamData(stream_, buf.data(), buf.size_bytes()))
{
char errbuf[512];
SDL_GetErrorMsg(errbuf, sizeof(errbuf));
SDL_strlcpy(errbuf, SDL_GetError(), sizeof(errbuf) - 1);
errbuf[sizeof(errbuf) - 1] = '\0';
throw std::runtime_error(errbuf);
}
}
size_t available() const
{
int result = SDL_AudioStreamAvailable(stream_);
int result = SDL_GetAudioStreamAvailable(stream_);
if (result < 0)
{
char errbuf[512];
SDL_GetErrorMsg(errbuf, sizeof(errbuf));
SDL_strlcpy(errbuf, SDL_GetError(), sizeof(errbuf) - 1);
errbuf[sizeof(errbuf) - 1] = '\0';
throw std::runtime_error(errbuf);
}
return result;
@ -98,11 +106,12 @@ public:
size_t get(tcb::span<std::byte> out)
{
int result = SDL_AudioStreamGet(stream_, out.data(), out.size_bytes());
int result = SDL_GetAudioStreamData(stream_, out.data(), out.size_bytes());
if (result < 0)
{
char errbuf[512];
SDL_GetErrorMsg(errbuf, sizeof(errbuf));
SDL_strlcpy(errbuf, SDL_GetError(), sizeof(errbuf) - 1);
errbuf[sizeof(errbuf) - 1] = '\0';
throw std::runtime_error(errbuf);
}
return result;
@ -110,7 +119,7 @@ public:
void clear() noexcept
{
SDL_AudioStreamClear(stream_);
SDL_ClearAudioStream(stream_);
}
};
@ -122,7 +131,7 @@ class SdlVoiceStreamPlayer : public Source<2>
bool terminal_ = true;
public:
SdlVoiceStreamPlayer() : stream_(AUDIO_F32SYS, 1, 48000, AUDIO_F32SYS, 2, 44100) {}
SdlVoiceStreamPlayer() : stream_(SDL_AUDIO_F32, 1, 48000, SDL_AUDIO_F32, 2, 44100) {}
virtual ~SdlVoiceStreamPlayer() = default;
virtual std::size_t generate(tcb::span<Sample<2>> buffer) override
@ -197,9 +206,9 @@ static shared_ptr<srb2::media::AVRecorder> av_recorder;
static void (*music_fade_callback)();
static SDL_AudioDeviceID g_device_id;
static SDL_AudioDeviceID g_input_device_id;
static SDL_mutex* microphone_mutex = nullptr;
static SDL_AudioStream* g_output_stream;
static SDL_AudioStream* g_input_stream;
static SDL_Mutex* microphone_mutex = nullptr;
static SDL_Thread* microphone_thread = nullptr;
void* I_GetSfx(sfxinfo_t* sfx)
@ -248,39 +257,42 @@ namespace
class SdlAudioLockHandle
{
public:
SdlAudioLockHandle() { SDL_LockAudioDevice(g_device_id); }
~SdlAudioLockHandle() { SDL_UnlockAudioDevice(g_device_id); }
SdlAudioLockHandle() { SDL_LockAudioStream(g_output_stream); }
~SdlAudioLockHandle() { SDL_UnlockAudioStream(g_output_stream); }
};
#ifdef TRACY_ENABLE
static const char* kAudio = "Audio";
#endif
void audio_callback(void* userdata, Uint8* buffer, int len)
void audio_callback(void* userdata, SDL_AudioStream* stream, int add, int total)
{
tracy::SetThreadName("SDL Audio Thread");
FrameMarkStart(kAudio);
ZoneScoped;
if (add <= 0)
return;
floatdenormalstate_t dtzstate = M_EnterFloatDenormalToZero();
auto dtzrestore = srb2::finally([dtzstate] { M_ExitFloatDenormalToZero(dtzstate); });
// The SDL Audio lock is implied to be held during callback.
if (!master_gain)
{
FrameMarkEnd(kAudio);
return;
}
static std::array<Sample<2>, 2048> float_buffer = {};
SDL_LockAudioStream(stream);
try
{
Sample<2>* float_buffer = reinterpret_cast<Sample<2>*>(buffer);
size_t float_len = len / 8;
size_t float_len = std::min(float_buffer.size(), add / sizeof(Sample<2>));
for (size_t i = 0; i < float_len; i++)
{
float_buffer[i] = Sample<2> {0.f, 0.f};
}
if (!master_gain)
return;
master_gain->generate(tcb::span {float_buffer, float_len});
master_gain->generate(tcb::span {float_buffer.data(), float_len});
for (size_t i = 0; i < float_len; i++)
{
float_buffer[i] = {
@ -290,13 +302,16 @@ void audio_callback(void* userdata, Uint8* buffer, int len)
}
#ifdef SRB2_CONFIG_ENABLE_WEBM_MOVIES
if (av_recorder)
av_recorder->push_audio_samples(tcb::span {float_buffer, float_len});
av_recorder->push_audio_samples(tcb::span {float_buffer.data(), float_len});
#endif
SDL_PutAudioStreamData(stream, float_buffer.data(), float_len * sizeof(Sample<2>));
}
catch (...)
{
}
SDL_UnlockAudioStream(stream);
FrameMarkEnd(kAudio);
return;
@ -304,27 +319,25 @@ void audio_callback(void* userdata, Uint8* buffer, int len)
void initialize_sound()
{
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
if (!SDL_InitSubSystem(SDL_INIT_AUDIO))
{
CONS_Alert(CONS_ERROR, "Error initializing SDL Audio: %s\n", SDL_GetError());
return;
}
SDL_AudioSpec desired {};
desired.format = AUDIO_F32SYS;
desired.format = SDL_AUDIO_F32;
desired.channels = 2;
desired.samples = cv_soundmixingbuffersize.value;
// desired.samples = cv_soundmixingbuffersize.value;
desired.freq = 44100;
desired.callback = audio_callback;
if ((g_device_id = SDL_OpenAudioDevice(NULL, SDL_FALSE, &desired, NULL, 0)) == 0)
if ((g_output_stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired, audio_callback, nullptr)) == 0)
{
CONS_Alert(CONS_ERROR, "Failed to open SDL Audio device: %s\n", SDL_GetError());
SDL_QuitSubSystem(SDL_INIT_AUDIO);
return;
}
SDL_PauseAudioDevice(g_device_id, SDL_FALSE);
SDL_ResumeAudioStreamDevice(g_output_stream);
{
SdlAudioLockHandle _;
@ -380,16 +393,16 @@ void I_StartupSound(void)
void I_ShutdownSound(void)
{
if (g_device_id)
if (g_output_stream)
{
SDL_CloseAudioDevice(g_device_id);
g_device_id = 0;
SDL_DestroyAudioStream(g_output_stream);
g_output_stream = nullptr;
}
SDL_LockMutex(microphone_mutex);
if (g_input_device_id)
if (g_input_stream)
{
SDL_CloseAudioDevice(g_input_device_id);
g_input_device_id = 0;
SDL_DestroyAudioStream(g_input_stream);
g_input_stream = nullptr;
}
SDL_UnlockMutex(microphone_mutex);
@ -1008,7 +1021,7 @@ void I_UpdateAudioRecorder(void)
boolean I_SoundInputIsEnabled(void)
{
SDL_LockMutex(microphone_mutex);
boolean ret = g_input_device_id != 0;
boolean ret = g_input_stream != nullptr;
SDL_UnlockMutex(microphone_mutex);
return ret;
}
@ -1016,25 +1029,17 @@ boolean I_SoundInputIsEnabled(void)
static int microphone_opener(void* data)
{
SDL_AudioSpec input_desired {};
input_desired.format = AUDIO_F32SYS;
input_desired.format = SDL_AUDIO_F32;
input_desired.channels = 1;
input_desired.samples = 1024;
input_desired.freq = 48000;
SDL_AudioSpec input_obtained {};
SDL_AudioDeviceID device_id = SDL_OpenAudioDevice(nullptr, SDL_TRUE, &input_desired, &input_obtained, 0);
if (!device_id)
SDL_AudioStream* stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &input_desired, nullptr, nullptr);
if (!stream)
{
// CONS_Alert(CONS_WARNING, "Failed to open input audio device: %s\n", SDL_GetError());
return 0;
}
if (input_obtained.freq != 48000 || input_obtained.format != AUDIO_F32SYS || input_obtained.channels != 1)
{
// CONS_Alert(CONS_WARNING, "Input audio device has unexpected unusable format: %s\n", SDL_GetError());
return 0;
}
SDL_PauseAudioDevice(device_id, SDL_FALSE);
SDL_ResumeAudioStreamDevice(stream);
SDL_LockMutex(microphone_mutex);
g_input_device_id = device_id;
g_input_stream = stream;
SDL_UnlockMutex(microphone_mutex);
return 0;
}
@ -1043,9 +1048,13 @@ boolean I_SoundInputSetEnabled(boolean enabled)
{
SDL_LockMutex(microphone_mutex);
if (g_input_device_id == 0 && enabled)
if (g_input_stream == nullptr && enabled)
{
if (!sound_started || SDL_GetNumAudioDevices(true) == 0)
int recording_devices = 0;
SDL_AudioDeviceID* device_ids;
device_ids = SDL_GetAudioRecordingDevices(&recording_devices);
SDL_free(device_ids);
if (!sound_started || recording_devices == 0)
{
SDL_UnlockMutex(microphone_mutex);
return false;
@ -1053,13 +1062,13 @@ boolean I_SoundInputSetEnabled(boolean enabled)
SDL_CreateThread(microphone_opener, "Microphone Opener", nullptr);
}
else if (g_input_device_id != 0 && !enabled)
else if (g_input_stream != nullptr && !enabled)
{
microphone_thread = nullptr;
SDL_PauseAudioDevice(g_input_device_id, SDL_TRUE);
SDL_ClearQueuedAudio(g_input_device_id);
SDL_CloseAudioDevice(g_input_device_id);
g_input_device_id = 0;
SDL_PauseAudioStreamDevice(g_input_stream);
SDL_ClearAudioStream(g_input_stream);
SDL_DestroyAudioStream(g_input_stream);
g_input_stream = nullptr;
}
SDL_UnlockMutex(microphone_mutex);
@ -1070,13 +1079,13 @@ boolean I_SoundInputSetEnabled(boolean enabled)
UINT32 I_SoundInputDequeueSamples(void *data, UINT32 len)
{
SDL_LockMutex(microphone_mutex);
if (!g_input_device_id)
if (!g_input_stream)
{
SDL_UnlockMutex(microphone_mutex);
return 0;
}
UINT32 ret = SDL_DequeueAudio(g_input_device_id, data, len);
UINT32 ret = SDL_GetAudioStreamData(g_input_stream, data, len);
SDL_UnlockMutex(microphone_mutex);
return ret;
}
@ -1084,12 +1093,12 @@ UINT32 I_SoundInputDequeueSamples(void *data, UINT32 len)
UINT32 I_SoundInputRemainingSamples(void)
{
SDL_LockMutex(microphone_mutex);
if (!g_input_device_id)
if (!g_input_stream)
{
SDL_UnlockMutex(microphone_mutex);
return 0;
}
UINT32 avail = SDL_GetQueuedAudioSize(g_input_device_id);
UINT32 avail = SDL_GetAudioStreamAvailable(g_input_stream);
SDL_UnlockMutex(microphone_mutex);
return avail / sizeof(float);
}

View file

@ -18,7 +18,13 @@
#ifdef HAVE_SDL
#define _MATH_DEFINES_DEFINED
#include "SDL.h"
/*
* TODO ISO C forbids converting object pointers to function pointers and vice versa.
* The existing legacy GL code still uses void pointers though, so to clear the warning we need
* to tell SDL3 to declare SDL_FunctionPointer as void*.
*/
#define SDL_FUNCTION_POINTER_IS_VOID_POINTER
#include <SDL3/SDL.h>
#include "sdlmain.h"
@ -76,7 +82,7 @@ void *GetGLFunc(const char *proc)
else
return NULL;
}
return SDL_GL_GetProcAddress(proc);
return (void*)SDL_GL_GetProcAddress(proc);
}
boolean LoadGL(void)
@ -94,7 +100,7 @@ boolean LoadGL(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"
"Falling back to Software mode.\n", SDL_GetError());

View file

@ -15,7 +15,7 @@
#ifndef __SDL_OGL_SDL_H__
#define __SDL_OGL_SDL_H__
#include <SDL.h>
#include <SDL3/SDL.h>
#include "../v_video.h"

View file

@ -14,7 +14,7 @@
#include <string>
#include <sstream>
#include <SDL.h>
#include <SDL3/SDL.h>
#include "../core/string.h"
#include "../core/vector.hpp"
@ -118,6 +118,6 @@ rhi::Rect SdlGl2Platform::get_default_framebuffer_dimensions()
SRB2_ASSERT(window != nullptr);
int w;
int h;
SDL_GL_GetDrawableSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
return {0, 0, static_cast<uint32_t>(w), static_cast<uint32_t>(h)};
}

View file

@ -18,7 +18,7 @@
#include "../rhi/gl2/gl2_rhi.hpp"
#include "../rhi/rhi.hpp"
#include <SDL.h>
#include <SDL3/SDL.h>
namespace srb2::rhi
{

View file

@ -10,7 +10,7 @@
#include "rhi_gles2_platform.hpp"
#include <SDL.h>
#include <SDL3/SDL.h>
#include "../cxxutil.hpp"
#include "../w_wad.h"
@ -65,6 +65,6 @@ rhi::Rect SdlGles2Platform::get_default_framebuffer_dimensions()
SRB2_ASSERT(window != nullptr);
int w;
int h;
SDL_GL_GetDrawableSize(window, &w, &h);
SDL_GetWindowSizeInPixels(window, &w, &h);
return {0, 0, static_cast<uint32_t>(w), static_cast<uint32_t>(h)};
}

View file

@ -14,7 +14,7 @@
#include "../rhi/gles2/gles2_rhi.hpp"
#include "../rhi/rhi.hpp"
#include <SDL.h>
#include <SDL3/SDL.h>
namespace srb2::rhi
{

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,8 @@
#ifndef __sdlmain__
#define __sdlmain__
extern SDL_bool consolevent;
extern SDL_bool framebuffer;
extern bool consolevent;
extern bool framebuffer;
#include "../m_fixed.h"
#include "../doomdef.h"
@ -37,7 +37,7 @@ extern "C" {
typedef struct SDLJoyInfo_s
{
/// Controller handle
SDL_GameController *dev;
SDL_Gamepad *dev;
/// number of old joystick
int oldjoy;
/// number of axies
@ -60,7 +60,6 @@ extern SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS];
/** \brief joystick axis deadzone
*/
#define SDL_JDEADZONE 153
#undef SDL_JDEADZONE
void I_GetConsoleEvents(void);

View file

@ -16,7 +16,7 @@
"libyuv",
"opus",
{
"name": "sdl2",
"name": "sdl3",
"features": ["vulkan"]
},
"zlib"