engine: remove inclusion of SDL headers globally, helps to cleanup code before SDL3 migration

This commit is contained in:
Alibek Omarov 2025-02-28 13:14:47 +03:00
parent bbbd7711c1
commit a5f0ca38f1
14 changed files with 59 additions and 52 deletions

View file

@ -86,8 +86,4 @@ GNU General Public License for more details.
#include <string.h>
#include <limits.h>
#if defined XASH_SDL && !defined REF_DLL
#include <SDL.h>
#endif
#endif // PORT_H

View file

@ -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.h> // SDL_GetWindowPosition
#endif // XASH_SDL
#include "common.h"
#include "client.h"
#include "const.h"

View file

@ -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;
}

View file

@ -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 );
}
/*

View file

@ -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;
//

View file

@ -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.h> // SDL_GetBasePath
#endif
#include <errno.h>
#include "common.h"
#include "library.h"

View file

@ -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

View file

@ -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 <execinfo.h>
#include <signal.h>
#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 );

View file

@ -17,7 +17,7 @@ GNU General Public License for more details.
#include <signal.h>
#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 );

View file

@ -26,6 +26,7 @@ GNU General Public License for more details.
#include <signal.h>
#include <sys/mman.h>
#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 );

View file

@ -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

View file

@ -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

View file

@ -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 <winnt.h>
#include <dbghelp.h>
#include <psapi.h>
#include <time.h>
#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

View file

@ -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 )