From a5f0ca38f166330dd4607e8d44a1d04561b884db Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 28 Feb 2025 13:14:47 +0300 Subject: [PATCH] engine: remove inclusion of SDL headers globally, helps to cleanup code before SDL3 migration --- common/port.h | 4 ---- engine/client/cl_game.c | 4 ++++ engine/client/in_touch.c | 8 -------- engine/client/input.c | 18 +++++++++--------- engine/client/input.h | 3 +++ engine/common/filesystem_engine.c | 4 ++++ engine/platform/platform.h | 14 +------------- engine/platform/posix/crash_glibc.c | 7 ++++--- engine/platform/posix/crash_libbacktrace.c | 6 +++--- engine/platform/posix/crash_posix.c | 5 +++-- engine/platform/posix/sys_posix.c | 5 +++++ engine/platform/sdl/sys_sdl.c | 12 ++++++++++-- engine/platform/win32/crash_win.c | 16 ++++++++-------- engine/platform/win32/sys_win.c | 5 +++++ 14 files changed, 59 insertions(+), 52 deletions(-) diff --git a/common/port.h b/common/port.h index bb5fae12..cf0e90ed 100644 --- a/common/port.h +++ b/common/port.h @@ -86,8 +86,4 @@ GNU General Public License for more details. #include #include -#if defined XASH_SDL && !defined REF_DLL -#include -#endif - #endif // PORT_H diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 667a15fe..a2109de8 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -13,6 +13,10 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#if XASH_SDL +#include // SDL_GetWindowPosition +#endif // XASH_SDL + #include "common.h" #include "client.h" #include "const.h" diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index e389e636..363e583e 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -1180,14 +1180,6 @@ void Touch_Init( void ) Cvar_RegisterVariable( &touch_enable ); Cvar_RegisterVariable( &touch_emulate ); - // TODO: touch platform -#if SDL_VERSION_ATLEAST( 2, 0, 10 ) - SDL_SetHint( SDL_HINT_MOUSE_TOUCH_EVENTS, "0" ); - SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" ); -#elif defined( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH ) - SDL_SetHint( SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, "1" ); -#endif - touch.initialized = true; } diff --git a/engine/client/input.c b/engine/client/input.c index be4abc36..98886052 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -205,9 +205,10 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) } } -static void IN_SetRelativeMouseMode( qboolean set, qboolean verbose ) +void IN_SetRelativeMouseMode( qboolean set ) { static qboolean s_bRawInput; + qboolean verbose = m_grab_debug.value ? true : false; if( set && !s_bRawInput ) { @@ -231,9 +232,10 @@ static void IN_SetRelativeMouseMode( qboolean set, qboolean verbose ) } } -static void IN_SetMouseGrab( qboolean set, qboolean verbose ) +void IN_SetMouseGrab( qboolean set ) { static qboolean s_bMouseGrab; + qboolean verbose = m_grab_debug.value ? true : false; if( set && !s_bMouseGrab ) { @@ -258,7 +260,7 @@ static void IN_SetMouseGrab( qboolean set, qboolean verbose ) static void IN_CheckMouseState( qboolean active ) { - qboolean use_raw_input, verbose; + qboolean use_raw_input; #if XASH_WIN32 use_raw_input = ( m_rawinput.value && clgame.client_dll_uses_sdl ) || clgame.dllFuncs.pfnLookEvent != NULL; @@ -266,20 +268,18 @@ static void IN_CheckMouseState( qboolean active ) use_raw_input = true; // always use SDL code #endif - verbose = m_grab_debug.value ? true : false; - if( m_ignore.value ) active = false; if( active && use_raw_input && !host.mouse_visible && cls.state == ca_active ) - IN_SetRelativeMouseMode( true, verbose ); + IN_SetRelativeMouseMode( true ); else - IN_SetRelativeMouseMode( false, verbose ); + IN_SetRelativeMouseMode( false ); if( active && !host.mouse_visible && cls.state == ca_active ) - IN_SetMouseGrab( true, verbose ); + IN_SetMouseGrab( true ); else - IN_SetMouseGrab( false, verbose ); + IN_SetMouseGrab( false ); } /* diff --git a/engine/client/input.h b/engine/client/input.h index 4fb4fe7d..138cbc68 100644 --- a/engine/client/input.h +++ b/engine/client/input.h @@ -46,6 +46,9 @@ uint IN_CollectInputDevices( void ); void IN_LockInputDevices( qboolean lock ); void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ); +void IN_SetRelativeMouseMode( qboolean set ); +void IN_SetMouseGrab( qboolean set ); + extern convar_t m_yaw; extern convar_t m_pitch; // diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index f10744c2..ef776199 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -16,6 +16,10 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +#if XASH_SDL +#include // SDL_GetBasePath +#endif + #include #include "common.h" #include "library.h" diff --git a/engine/platform/platform.h b/engine/platform/platform.h index da3e219f..d08d7a38 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -31,6 +31,7 @@ GNU General Public License for more details. ============================================================================== */ double Platform_DoubleTime( void ); +void Platform_Sleep( int msec ); void Platform_ShellExecute( const char *path, const char *parms ); void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow ); void Platform_SetStatus( const char *status ); @@ -168,19 +169,6 @@ static inline void Platform_SetupSigtermHandling( void ) #endif } -static inline void Platform_Sleep( int msec ) -{ -#if XASH_TIMER == TIMER_SDL - SDL_Delay( msec ); -#elif XASH_TIMER == TIMER_POSIX - usleep( msec * 1000 ); -#elif XASH_TIMER == TIMER_WIN32 - Sleep( msec ); -#else - // stub -#endif -} - static inline qboolean Platform_NanoSleep( int nsec ) { // SDL2 doesn't have nanosleep, so use low-level functions here diff --git a/engine/platform/posix/crash_glibc.c b/engine/platform/posix/crash_glibc.c index 9380d5d5..a8cdd939 100644 --- a/engine/platform/posix/crash_glibc.c +++ b/engine/platform/posix/crash_glibc.c @@ -17,9 +17,10 @@ GNU General Public License for more details. // have backtrace() and backtrace_symbols() calls, which replace for us // platform-specific code #if HAVE_EXECINFO -#include "common.h" #include #include +#include "common.h" +#include "input.h" void Sys_Crash( int signal, siginfo_t *si, void *context ) { @@ -70,8 +71,8 @@ void Sys_Crash( int signal, siginfo_t *si, void *context ) // put MessageBox as Sys_Error Msg( "%s\n", message ); -#ifdef XASH_SDL - SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#if !XASH_DEDICATED + IN_SetMouseGrab( false ); #endif host.crashed = true; Platform_MessageBox( "Xash Error", message, false ); diff --git a/engine/platform/posix/crash_libbacktrace.c b/engine/platform/posix/crash_libbacktrace.c index c4db096c..1c082435 100644 --- a/engine/platform/posix/crash_libbacktrace.c +++ b/engine/platform/posix/crash_libbacktrace.c @@ -17,7 +17,7 @@ GNU General Public License for more details. #include #include "common.h" #include "backtrace.h" - +#include "input.h" static struct backtrace_state *g_bt_state; static qboolean enable_libbacktrace; @@ -164,8 +164,8 @@ void Sys_CrashLibbacktrace( int signal, siginfo_t *si, void *context ) // put MessageBox as Sys_Error Msg( "%s\n", message ); -#ifdef XASH_SDL - SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#if !XASH_DEDICATED + IN_SetMouseGrab( false ); #endif host.crashed = true; Platform_MessageBox( "Xash Error", message, false ); diff --git a/engine/platform/posix/crash_posix.c b/engine/platform/posix/crash_posix.c index bb64d673..a72c8ea0 100644 --- a/engine/platform/posix/crash_posix.c +++ b/engine/platform/posix/crash_posix.c @@ -26,6 +26,7 @@ GNU General Public License for more details. #include #include #include "library.h" +#include "input.h" void Sys_Crash( int signal, siginfo_t *si, void *context ); void Sys_CrashLibbacktrace( int signal, siginfo_t *si, void *context ); @@ -192,8 +193,8 @@ void Sys_Crash( int signal, siginfo_t *si, void *context ) // put MessageBox as Sys_Error Msg( "%s\n", message ); -#ifdef XASH_SDL - SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#if !XASH_DEDICATED + IN_SetMouseGrab( false ); #endif host.crashed = true; Platform_MessageBox( "Xash Error", message, false ); diff --git a/engine/platform/posix/sys_posix.c b/engine/platform/posix/sys_posix.c index 1244b27c..487e815b 100644 --- a/engine/platform/posix/sys_posix.c +++ b/engine/platform/posix/sys_posix.c @@ -174,5 +174,10 @@ double Platform_DoubleTime( void ) #endif return (double) ts.tv_sec + (double) ts.tv_nsec/1000000000.0; } + +void Platform_Sleep( int msec ) +{ + usleep( msec * 1000 ); +} #endif // XASH_TIMER == TIMER_POSIX diff --git a/engine/platform/sdl/sys_sdl.c b/engine/platform/sdl/sys_sdl.c index 31c0c65f..8461b676 100644 --- a/engine/platform/sdl/sys_sdl.c +++ b/engine/platform/sdl/sys_sdl.c @@ -32,6 +32,11 @@ double Platform_DoubleTime( void ) CurrentTime = SDL_GetPerformanceCounter(); return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency ); } + +void Platform_Sleep( int msec ) +{ + SDL_Delay( msec ); +} #endif // XASH_TIMER == TIMER_SDL #if XASH_MESSAGEBOX == MSGBOX_SDL @@ -109,8 +114,11 @@ void SDLash_Init( const char *basedir ) host.type = HOST_DEDICATED; } -#if XASH_SDL == 2 - SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); +#if SDL_MAJOR_VERSION >= 2 + SDL_SetHint( SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0" ); + SDL_SetHint( SDL_HINT_MOUSE_TOUCH_EVENTS, "0" ); + SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" ); + SDL_StopTextInput(); #endif // XASH_SDL == 2 diff --git a/engine/platform/win32/crash_win.c b/engine/platform/win32/crash_win.c index 284f9e88..d33deb8f 100644 --- a/engine/platform/win32/crash_win.c +++ b/engine/platform/win32/crash_win.c @@ -13,17 +13,17 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#include "platform/platform.h" - -#define DBGHELP 1 // we always enable dbghelp.dll on Windows targets - -#if DBGHELP - #include #include #include #include +#include "platform/platform.h" +#include "input.h" + +#define DBGHELP 1 // we always enable dbghelp.dll on Windows targets + +#if DBGHELP #ifndef XASH_SDL typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; #endif @@ -268,8 +268,8 @@ static long _stdcall Sys_Crash( PEXCEPTION_POINTERS pInfo ) // check to avoid recursive call host.crashed = true; -#ifdef XASH_SDL - SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); +#if !XASH_DEDICATED + IN_SetMouseGrab( false ); #endif // XASH_SDL #if DBGHELP diff --git a/engine/platform/win32/sys_win.c b/engine/platform/win32/sys_win.c index 60349d64..fe5723fd 100644 --- a/engine/platform/win32/sys_win.c +++ b/engine/platform/win32/sys_win.c @@ -36,6 +36,11 @@ double Platform_DoubleTime( void ) return (double)( CurrentTime.QuadPart - g_ClockStart.QuadPart ) / (double)( g_PerformanceFrequency.QuadPart ); } + +void Platform_Sleep( int msec ) +{ + Sleep( msec ); +} #endif // XASH_TIMER == TIMER_WIN32 void Win32_Init( qboolean con_showalways )