From 9e99a2bc37e3100b2a008cc6b5513524cdd5818d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 24 Oct 2019 12:44:18 +0300 Subject: [PATCH] engine: dirty sdl1.2 port --- common/defaults.h | 15 ++++++++++----- engine/client/cl_game.c | 4 ++-- engine/client/cl_main.c | 2 +- engine/client/input.c | 8 ++++---- engine/client/vgui/vgui_draw.c | 4 ++-- engine/common/host.c | 14 ++++++++++---- engine/common/system.c | 2 +- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/common/defaults.h b/common/defaults.h index d2d58a4b..2848d879 100644 --- a/common/defaults.h +++ b/common/defaults.h @@ -27,17 +27,22 @@ SETUP BACKENDS DEFINITIONS */ #ifndef XASH_DEDICATED - #ifdef XASH_SDL + #if XASH_SDL == 2 + #ifndef XASH_TIMER + #define XASH_TIMER TIMER_SDL + #endif + #else + #ifndef XASH_TIMER + #define XASH_TIMER TIMER_LINUX + #endif + #endif + #ifdef XASH_SDL // by default, use SDL subsystems #ifndef XASH_VIDEO #define XASH_VIDEO VIDEO_SDL #endif // XASH_VIDEO - #ifndef XASH_TIMER - #define XASH_TIMER TIMER_SDL - #endif - #ifndef XASH_INPUT #define XASH_INPUT INPUT_SDL #endif diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 8ffa78e0..fb49bc6c 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1988,7 +1988,7 @@ static int pfnGetWindowCenterX( void ) } #endif -#ifdef XASH_SDL +#if XASH_SDL == 2 SDL_GetWindowPosition( host.hWnd, &x, NULL ); #endif @@ -2013,7 +2013,7 @@ static int pfnGetWindowCenterY( void ) } #endif -#ifdef XASH_SDL +#if XASH_SDL == 2 SDL_GetWindowPosition( host.hWnd, NULL, &y ); #endif diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 667d0b90..c97ee1f9 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1938,7 +1938,7 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg ) return; } -#ifdef XASH_SDL +#if XASH_SDL == 2 SDL_ShowWindow( host.hWnd ); #endif args = MSG_ReadString( msg ); diff --git a/engine/client/input.c b/engine/client/input.c index 01c7fd8a..1e0c87d9 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -194,7 +194,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) else if( newstate == key_game ) { // reset mouse pos, so cancel effect in game -#ifdef XASH_SDL +#if XASH_SDL == 2 if( CVAR_TO_BOOL(touch_enable) ) { SDL_SetRelativeMouseMode( SDL_FALSE ); @@ -214,7 +214,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) if( ( newstate == key_menu || newstate == key_console || newstate == key_message ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo( ))) { -#ifdef XASH_SDL +#if XASH_SDL == 2 SDL_SetWindowGrab(host.hWnd, SDL_FALSE); if( clgame.dllFuncs.pfnLookEvent ) SDL_SetRelativeMouseMode( SDL_FALSE ); @@ -316,7 +316,7 @@ void IN_DeactivateMouse( void ) } in_mouseactive = false; -#ifdef XASH_SDL +#if XASH_SDL == 2 SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); #endif } @@ -416,7 +416,7 @@ void IN_MouseEvent( void ) } else { -#if defined(XASH_SDL) && !defined(_WIN32) +#if XASH_SDL == 2 && !defined(_WIN32) SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_ShowCursor( SDL_TRUE ); #endif diff --git a/engine/client/vgui/vgui_draw.c b/engine/client/vgui/vgui_draw.c index c8e25a56..79cc0bab 100644 --- a/engine/client/vgui/vgui_draw.c +++ b/engine/client/vgui/vgui_draw.c @@ -72,7 +72,7 @@ void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y ) void VGUI_InitCursors( void ) { // load up all default cursors -#ifdef XASH_SDL +#if XASH_SDL == 2 s_pDefaultCursor[dc_none] = NULL; s_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); s_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); @@ -108,7 +108,7 @@ void GAME_EXPORT VGUI_CursorSelect(enum VGUI_DefaultCursor cursor ) break; } -#ifdef XASH_SDL +#if XASH_SDL == 2 /// TODO: platform cursors if( CVAR_TO_BOOL( touch_emulate ) ) diff --git a/engine/common/host.c b/engine/common/host.c index e9a437b4..b7449670 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -323,7 +323,7 @@ void Host_MemStats_f( void ) void Host_Minimize_f( void ) { -#ifdef XASH_SDL +#if XASH_SDL == 2 if( host.hWnd ) SDL_MinimizeWindow( host.hWnd ); #endif } @@ -733,7 +733,7 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha #if TARGET_OS_IOS const char *IOS_GetDocsDir(); Q_strncpy( host.rootdir, IOS_GetDocsDir(), sizeof(host.rootdir) ); -#elif defined(XASH_SDL) +#elif XASH_SDL == 2 char *szBasePath; if( !( szBasePath = SDL_GetBasePath() ) ) @@ -817,15 +817,21 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha // should work even if it failed SDL_Init( SDL_INIT_TIMER ); +#ifndef SDL_INIT_EVENTS +#define SDL_INIT_EVENTS 0 +#endif + if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) { Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); host.type = HOST_DEDICATED; } - SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); +#if XASH_SDL == 2 + SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); SDL_StopTextInput(); -#endif +#endif // XASH_SDL == 2 +#endif // XASH_SDL if ( !host.rootdir[0] || SetCurrentDirectory( host.rootdir ) != 0) Con_Reportf( "%s is working directory now\n", host.rootdir ); diff --git a/engine/common/system.c b/engine/common/system.c index 1b1a3bd8..d3fe3572 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -426,7 +426,7 @@ void Sys_Error( const char *error, ... ) if( !Host_IsDedicated() ) { -#ifdef XASH_SDL +#if XASH_SDL == 2 if( host.hWnd ) SDL_HideWindow( host.hWnd ); #endif }