Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3: Add port #2069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions engine/client/cl_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/

#if XASH_SDL
#include <SDL.h> // SDL_GetWindowPosition
#if XASH_SDL // SDL_GetWindowPosition
#if XASH_SDL == 3
// Officially recommended method of using SDL3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
#endif // XASH_SDL

#include "common.h"
Expand Down Expand Up @@ -2092,7 +2097,7 @@ static int GAME_EXPORT pfnGetWindowCenterX( void )
}
#endif

#if XASH_SDL == 2
#if XASH_SDL == 2 || XASH_SDL == 3
SDL_GetWindowPosition( host.hWnd, &x, NULL );
#endif

Expand All @@ -2117,7 +2122,7 @@ static int GAME_EXPORT pfnGetWindowCenterY( void )
}
#endif

#if XASH_SDL == 2
#if XASH_SDL == 2 || XASH_SDL == 3
SDL_GetWindowPosition( host.hWnd, NULL, &y );
#endif

Expand Down Expand Up @@ -3970,7 +3975,13 @@ qboolean CL_LoadProgs( const char *name )
// and if so, disable relative mouse mode
#if XASH_WIN32 && !XASH_64BIT
clgame.client_dll_uses_sdl = COM_CheckLibraryDirectDependency( name, OS_LIB_PREFIX "SDL2." OS_LIB_EXT, false );
Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, clgame.client_dll_uses_sdl ? "SDL2" : "Windows API" );
if (clgame.client_dll_uses_sdl)
Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, "SDL2" );
else
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. We check whether client.dll is linked directly to SDL2.dll because it might use SDL2 API for mouse input, and therefore need relative mouse mode enabled.

With SDL3, it's the same, we can ship sdl2-compat for GoldSrc mods, just in case they want SDL2 API for mouse input.

Checking whether client.dll wants SDL3 or not would be viable only if Valve migrate GoldSrc to SDL3, which for now (?) doesn't seem very likely to me.

clgame.client_dll_uses_sdl = COM_CheckLibraryDirectDependency( name, OS_LIB_PREFIX "SDL3." OS_LIB_EXT, false );
Con_Printf( S_NOTE "%s uses %s for mouse input\n", name, clgame.client_dll_uses_sdl ? "SDL3" : "Windows API" );
}
#endif

// NOTE: important stuff!
Expand Down
23 changes: 21 additions & 2 deletions engine/client/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ GNU General Public License for more details.
#include "cursor_type.h"

#if XASH_SDL
#if XASH_SDL == 3
// Officially recommended method of using SDL3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
#endif

#include "platform/platform.h"

Expand Down Expand Up @@ -212,7 +217,10 @@ void IN_SetRelativeMouseMode( qboolean set )

if( set && !s_bRawInput )
{
#if XASH_SDL == 2
#if XASH_SDL == 3
SDL_GetRelativeMouseState(NULL, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces in parentheses, please.

If you're not sure what to do, we have uncrustify config, some editors allow only to reformat by selection.

I can also do this myself later, if you don't want to bother.

SDL_SetWindowRelativeMouseMode(host.hWnd, true);
#elif XASH_SDL == 2
SDL_GetRelativeMouseState( NULL, NULL );
SDL_SetRelativeMouseMode( SDL_TRUE );
#endif
Expand All @@ -222,7 +230,10 @@ void IN_SetRelativeMouseMode( qboolean set )
}
else if( !set && s_bRawInput )
{
#if XASH_SDL == 2
#if XASH_SDL == 3
SDL_GetRelativeMouseState(NULL, NULL);
SDL_SetWindowRelativeMouseMode(host.hWnd, false);
#elif XASH_SDL == 2
SDL_GetRelativeMouseState( NULL, NULL );
SDL_SetRelativeMouseMode( SDL_FALSE );
#endif
Expand All @@ -240,7 +251,11 @@ void IN_SetMouseGrab( qboolean set )
if( set && !s_bMouseGrab )
{
#if XASH_SDL
#if XASH_SDL == 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do

#if XASH_SDL == 3
#elif XASH_SDL
#endif     

here.

SDL_SetWindowMouseGrab( host.hWnd, true );
#else
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
#endif
#endif
s_bMouseGrab = true;
if( verbose )
Expand All @@ -249,7 +264,11 @@ void IN_SetMouseGrab( qboolean set )
else if( !set && s_bMouseGrab )
{
#if XASH_SDL
#if XASH_SDL == 3
SDL_SetWindowMouseGrab( host.hWnd, false );
#else
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
#endif
#endif

s_bMouseGrab = false;
Expand Down
9 changes: 7 additions & 2 deletions engine/common/filesystem_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ GNU General Public License for more details.
*/

#if XASH_SDL
#include <SDL.h> // SDL_GetBasePath
// SDL_GetBasePath
#if XASH_SDL == 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I told you in chat, you can just include <SDL.h>, as we always add include/SDL3 to the include path.

#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
#endif

#include <errno.h>
Expand Down Expand Up @@ -209,7 +214,7 @@ static qboolean FS_DetermineRootDirectory( char *out, size_t size )
return true;
Sys_Error( "couldn't find %s data directory", XASH_ENGINE_NAME );
return false;
#elif ( XASH_SDL == 2 ) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2
#elif ( XASH_SDL == 2 || XASH_SDL == 3 ) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2
path = SDL_GetBasePath();

#if XASH_APPLE
Expand Down
6 changes: 5 additions & 1 deletion engine/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ GNU General Public License for more details.

#include "build.h"
#ifdef XASH_SDL
#if XASH_SDL == 3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
#endif // XASH_SDL
#include <stdarg.h> // va_args
#if !XASH_WIN32
Expand Down Expand Up @@ -201,7 +205,7 @@ static void Sys_PrintUsage( const char *exename )
#if !XASH_MOBILE_PLATFORM
O("-daemonize ", "run engine as a daemon")
#endif
#if XASH_SDL == 2
#if XASH_SDL == 2 || XASH_SDL == 3
O("-sdl_renderer <n> ","use alternative SDL_Renderer for software")
#endif // XASH_SDL
#if XASH_ANDROID && !XASH_SDL
Expand Down
4 changes: 3 additions & 1 deletion engine/common/soundlib/snd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ GNU General Public License for more details.
*/

#include "soundlib.h"
#if XASH_SDL
#if XASH_SDL == 3
#include <SDL3/SDL.h>
#elif XASH_SDL
#include <SDL_audio.h>
#endif // XASH_SDL

Expand Down
22 changes: 20 additions & 2 deletions engine/common/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ GNU General Public License for more details.
#endif

#ifdef XASH_SDL
#if XASH_SDL == 3
#include <SDL3/SDL.h>
#else
#include <SDL.h>
#endif
#endif

#if XASH_POSIX
#include <unistd.h>
Expand Down Expand Up @@ -72,7 +76,9 @@ Sys_DebugBreak
*/
void Sys_DebugBreak( void )
{
#if XASH_SDL
#if XASH_SDL == 3
int was_grabbed = host.hWnd != NULL && SDL_GetWindowMouseGrab( host.hWnd );
#elif XASH_SDL
int was_grabbed = host.hWnd != NULL && SDL_GetWindowGrab( host.hWnd );
#endif

Expand All @@ -81,7 +87,13 @@ void Sys_DebugBreak( void )

#if XASH_SDL
if( was_grabbed ) // so annoying...
{
#if XASH_SDL == 3
SDL_SetWindowMouseGrab( host.hWnd, false );
#else
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
#endif
}
#endif // XASH_SDL

#if _MSC_VER
Expand All @@ -93,7 +105,13 @@ void Sys_DebugBreak( void )

#if XASH_SDL
if( was_grabbed )
{
#if XASH_SDL == 3
SDL_SetWindowMouseGrab( host.hWnd, true );
#else
SDL_SetWindowGrab( host.hWnd, SDL_TRUE );
#endif
}
#endif
}

Expand Down Expand Up @@ -393,7 +411,7 @@ void Sys_Error( const char *error, ... )

if( !Host_IsDedicated() )
{
#if XASH_SDL == 2
#if XASH_SDL == 2 || XASH_SDL == 3
if( host.hWnd ) SDL_HideWindow( host.hWnd );
#endif
#if XASH_WIN32
Expand Down
Loading
Loading