Remove USE_SDL2. Always use SDL2 on Windows when available

This commit is contained in:
FreeSlave 2024-03-12 01:29:28 +03:00 committed by Andrey Akhmichin
parent de1e971fc5
commit 31b66244e5
5 changed files with 73 additions and 85 deletions

View File

@ -84,10 +84,6 @@ else()
option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF) option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF)
endif() endif()
if (WIN32)
option(WIN32_USE_SDL2 "Force building client with SDL2 on Windows" ON)
endif()
#----------------- #-----------------
# MAIN BUILD CODE \ # MAIN BUILD CODE \
###################\ ###################\

View File

@ -52,10 +52,6 @@ if (GOLDSOURCE_SUPPORT)
add_definitions(-DGOLDSOURCE_SUPPORT) add_definitions(-DGOLDSOURCE_SUPPORT)
endif() endif()
if (WIN32_USE_SDL2)
add_definitions(-DWIN32_USE_SDL2)
endif()
if (USE_VGUI) if (USE_VGUI)
add_definitions(-DUSE_VGUI) add_definitions(-DUSE_VGUI)
if (USE_NOVGUI_MOTD) if (USE_NOVGUI_MOTD)
@ -168,7 +164,7 @@ endif()
include_directories (. hl/ ../dlls ../dlls/wpn_shared ../common ../engine ../pm_shared ../game_shared ../public) include_directories (. hl/ ../dlls ../dlls/wpn_shared ../common ../engine ../pm_shared ../game_shared ../public)
if (WIN32_USE_SDL2) if (WIN32)
include_directories (../external/) include_directories (../external/)
endif() endif()

View File

@ -23,12 +23,7 @@
#include "keydefs.h" #include "keydefs.h"
#include "view.h" #include "view.h"
#if !XASH_WIN32 || WIN32_USE_SDL2 #if !XASH_WIN32
#define USE_SDL2 1
#endif
#if USE_SDL2
#if !_WIN32
#define ARRAYSIZE(p) ( sizeof(p) /sizeof(p[0]) ) #define ARRAYSIZE(p) ( sizeof(p) /sizeof(p[0]) )
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
@ -114,7 +109,6 @@ static SDLFunction sdlFunctions[] = {
{(void**)&pfnSDL_JoystickUpdate, "SDL_JoystickUpdate"}, {(void**)&pfnSDL_JoystickUpdate, "SDL_JoystickUpdate"},
{(void**)&pfnSDL_GameControllerName, "SDL_GameControllerName"} {(void**)&pfnSDL_GameControllerName, "SDL_GameControllerName"}
}; };
#endif
#if XASH_WIN32 #if XASH_WIN32
#include <process.h> #include <process.h>
@ -159,6 +153,14 @@ static bool m_bMouseThread = false;
bool isMouseRelative = false; bool isMouseRelative = false;
#endif #endif
static void IN_SetMouseRelative(bool enable)
{
safe_pfnSDL_SetRelativeMouseMode(enable ? SDL_TRUE : SDL_FALSE);
#if XASH_WIN32
isMouseRelative = enable;
#endif
}
#if XASH_WIN32 #if XASH_WIN32
#include "progdefs.h" #include "progdefs.h"
#endif #endif
@ -220,7 +222,7 @@ enum _ControlList
AxisTurn AxisTurn
}; };
#if !USE_SDL2 && XASH_WIN32 #if XASH_WIN32
DWORD dwAxisFlags[JOY_MAX_AXES] = DWORD dwAxisFlags[JOY_MAX_AXES] =
{ {
JOY_RETURNX, JOY_RETURNX,
@ -234,22 +236,21 @@ DWORD dwAxisFlags[JOY_MAX_AXES] =
DWORD dwAxisMap[ JOY_MAX_AXES ]; DWORD dwAxisMap[ JOY_MAX_AXES ];
DWORD dwControlMap[ JOY_MAX_AXES ]; DWORD dwControlMap[ JOY_MAX_AXES ];
#if USE_SDL2 #if !XASH_WIN32
int pdwRawValue[ JOY_MAX_AXES ]; int pdwRawValue[ JOY_MAX_AXES ];
#elif XASH_WIN32 #else
PDWORD pdwRawValue[ JOY_MAX_AXES ]; PDWORD pdwRawValue[ JOY_MAX_AXES ];
#endif #endif
DWORD joy_oldbuttonstate, joy_oldpovstate; DWORD joy_oldbuttonstate, joy_oldpovstate;
int joy_id; int joy_id;
DWORD joy_numbuttons; DWORD joy_numbuttons;
#if USE_SDL2
SDL_GameController *s_pJoystick = NULL; SDL_GameController *s_pJoystick = NULL;
#elif XASH_WIN32
DWORD joy_flags; DWORD joy_flags;
static JOYINFOEX ji; static JOYINFOEX ji;
#endif
// none of these cvars are saved over a session // none of these cvars are saved over a session
// this means that advanced controller configuration needs to be executed // this means that advanced controller configuration needs to be executed
@ -391,13 +392,10 @@ void IN_SetMouseMode(bool enable)
m_bRawInput = m_rawinput && m_rawinput->value != 0; m_bRawInput = m_rawinput && m_rawinput->value != 0;
if(m_bRawInput) if(m_bRawInput)
{ {
#if USE_SDL2 IN_SetMouseRelative(true);
safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE);
#endif
isMouseRelative = true;
} }
#else #else
safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE); IN_SetMouseRelative(true);
#endif #endif
currentMouseMode = true; currentMouseMode = true;
@ -407,16 +405,13 @@ void IN_SetMouseMode(bool enable)
#if XASH_WIN32 #if XASH_WIN32
if(isMouseRelative) if(isMouseRelative)
{ {
#if USE_SDL2 IN_SetMouseRelative(false);
safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE);
#endif
isMouseRelative = false;
} }
if (restore_spi) if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
#else #else
safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE); IN_SetMouseRelative(false);
#endif #endif
currentMouseMode = false; currentMouseMode = false;
@ -439,8 +434,6 @@ void IN_SetVisibleMouse(bool visible)
#endif #endif
} }
void IN_ResetMouse( void );
/* /*
=========== ===========
IN_ActivateMouse IN_ActivateMouse
@ -568,17 +561,15 @@ void GoldSourceInput::IN_Shutdown (void)
} }
#endif #endif
#if USE_SDL2
for (int j=0; j<ARRAYSIZE(sdlFunctions); ++j) { for (int j=0; j<ARRAYSIZE(sdlFunctions); ++j) {
*(sdlFunctions[j].ppfnFunc) = NULL; *(sdlFunctions[j].ppfnFunc) = NULL;
} }
#if _WIN32 #if XASH_WIN32
FreeLibrary((HMODULE)sdl2Lib); FreeLibrary((HMODULE)sdl2Lib);
#else #else
dlclose(sdl2Lib); dlclose(sdl2Lib);
#endif #endif
sdl2Lib = NULL; sdl2Lib = NULL;
#endif
} }
/* /*
@ -600,7 +591,7 @@ IN_ResetMouse
FIXME: Call through to engine? FIXME: Call through to engine?
=========== ===========
*/ */
void IN_ResetMouse( void ) void GoldSourceInput::IN_ResetMouse( void )
{ {
// no work to do in SDL // no work to do in SDL
#if XASH_WIN32 #if XASH_WIN32
@ -609,9 +600,8 @@ void IN_ResetMouse( void )
{ {
if ( !m_bMouseThread && m_bRawInput ) if ( !m_bMouseThread && m_bRawInput )
{ {
#if !USE_SDL2 if (!sdl2Lib)
SetCursorPos ( gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY() ); SetCursorPos ( gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY() );
#endif
} }
else if ( !m_bRawInput ) else if ( !m_bRawInput )
{ {
@ -743,15 +733,18 @@ void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY)
else else
#endif #endif
{ {
#if USE_SDL2 if (sdl2Lib)
safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY ); {
current_pos.x = deltaX; safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY );
current_pos.y = deltaY; current_pos.x = deltaX;
#else current_pos.y = deltaY;
GetCursorPos (&current_pos); }
deltaX = current_pos.x - gEngfuncs.GetWindowCenterX(); else
deltaY = current_pos.y - gEngfuncs.GetWindowCenterY(); {
#endif GetCursorPos (&current_pos);
deltaX = current_pos.x - gEngfuncs.GetWindowCenterX();
deltaY = current_pos.y - gEngfuncs.GetWindowCenterY();
}
} }
#if XASH_WIN32 #if XASH_WIN32
@ -800,17 +793,11 @@ void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY)
if(m_bRawInput && !isMouseRelative) if(m_bRawInput && !isMouseRelative)
{ {
#if USE_SDL2 IN_SetMouseRelative(true);
safe_pfnSDL_SetRelativeMouseMode(SDL_TRUE);
#endif
isMouseRelative = true;
} }
else if(!m_bRawInput && isMouseRelative) else if(!m_bRawInput && isMouseRelative)
{ {
#if USE_SDL2 IN_SetMouseRelative(false);
safe_pfnSDL_SetRelativeMouseMode(SDL_FALSE);
#endif
isMouseRelative = false;
} }
UpdateMouseThreadActive(); UpdateMouseThreadActive();
@ -951,17 +938,20 @@ void GoldSourceInput::IN_Accumulate (void)
else else
#endif #endif
{ {
#if USE_SDL2 if (sdl2Lib)
int deltaX, deltaY; {
safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY ); int deltaX, deltaY;
mx_accum += deltaX; safe_pfnSDL_GetRelativeMouseState( &deltaX, &deltaY );
my_accum += deltaY; mx_accum += deltaX;
#else my_accum += deltaY;
GetCursorPos (&current_pos); }
else
{
GetCursorPos (&current_pos);
mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX(); mx_accum += current_pos.x - gEngfuncs.GetWindowCenterX();
my_accum += current_pos.y - gEngfuncs.GetWindowCenterY(); my_accum += current_pos.y - gEngfuncs.GetWindowCenterY();
#endif }
} }
// force the mouse to the center, so there's room to move // force the mouse to the center, so there's room to move
@ -1006,7 +996,7 @@ void IN_StartupJoystick (void)
// assume no joystick // assume no joystick
joy_avail = 0; joy_avail = 0;
#if USE_SDL2 #if !XASH_WIN32
int nJoysticks = safe_pfnSDL_NumJoysticks(); int nJoysticks = safe_pfnSDL_NumJoysticks();
if ( nJoysticks > 0 ) if ( nJoysticks > 0 )
{ {
@ -1093,7 +1083,7 @@ void IN_StartupJoystick (void)
#endif #endif
} }
#if USE_SDL2 #if !XASH_WIN32
int RawValuePointer (int axis) int RawValuePointer (int axis)
{ {
switch (axis) switch (axis)
@ -1110,7 +1100,7 @@ int RawValuePointer (int axis)
} }
} }
#elif XASH_WIN32 #else
PDWORD RawValuePointer (int axis) PDWORD RawValuePointer (int axis)
{ {
switch (axis) switch (axis)
@ -1193,7 +1183,7 @@ void Joy_AdvancedUpdate_f (void)
dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS; dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
} }
#if !USE_SDL2 && XASH_WIN32 #if XASH_WIN32
// compute the axes to collect from DirectInput // compute the axes to collect from DirectInput
joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV; joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
for (i = 0; i < JOY_MAX_AXES; i++) for (i = 0; i < JOY_MAX_AXES; i++)
@ -1225,7 +1215,7 @@ void GoldSourceInput::IN_Commands (void)
// loop through the joystick buttons // loop through the joystick buttons
// key a joystick event or auxillary event for higher number buttons for each state change // key a joystick event or auxillary event for higher number buttons for each state change
#if USE_SDL2 #if !XASH_WIN32
buttonstate = 0; buttonstate = 0;
for ( i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++ ) for ( i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++ )
{ {
@ -1239,7 +1229,7 @@ void GoldSourceInput::IN_Commands (void)
{ {
pdwRawValue[i] = RawValuePointer(i); pdwRawValue[i] = RawValuePointer(i);
} }
#elif XASH_WIN32 #else
buttonstate = ji.dwButtons; buttonstate = ji.dwButtons;
#endif #endif
@ -1265,7 +1255,7 @@ void GoldSourceInput::IN_Commands (void)
// this avoids any potential problems related to moving from one // this avoids any potential problems related to moving from one
// direction to another without going through the center position // direction to another without going through the center position
povstate = 0; povstate = 0;
#if !USE_SDL2 && XASH_WIN32 #if XASH_WIN32
if(ji.dwPOV != JOY_POVCENTERED) if(ji.dwPOV != JOY_POVCENTERED)
{ {
if (ji.dwPOV == JOY_POVFORWARD) if (ji.dwPOV == JOY_POVFORWARD)
@ -1303,7 +1293,7 @@ IN_ReadJoystick
*/ */
int IN_ReadJoystick (void) int IN_ReadJoystick (void)
{ {
#if USE_SDL2 #if !XASH_WIN32
safe_pfnSDL_JoystickUpdate(); safe_pfnSDL_JoystickUpdate();
return 1; return 1;
#elif XASH_WIN32 #elif XASH_WIN32
@ -1383,7 +1373,7 @@ void IN_JoyMove ( float frametime, usercmd_t *cmd )
for (i = 0; i < JOY_MAX_AXES; i++) for (i = 0; i < JOY_MAX_AXES; i++)
{ {
// get the floating point zero-centered, potentially-inverted data for the current axis // get the floating point zero-centered, potentially-inverted data for the current axis
#if USE_SDL2 #if !XASH_WIN32
fAxisValue = (float)pdwRawValue[i]; fAxisValue = (float)pdwRawValue[i];
#elif XASH_WIN32 #elif XASH_WIN32
fAxisValue = (float) *pdwRawValue[i]; fAxisValue = (float) *pdwRawValue[i];
@ -1590,7 +1580,7 @@ void GoldSourceInput::IN_Init (void)
if (m_bMouseThread) if (m_bMouseThread)
{ {
// init mouseThreadSleep: // init mouseThreadSleep:
#if USE_SDL2 // _beginthreadex is not defined on VS 6? #if 0 // _beginthreadex is not defined on VS 6?
InterlockedExchange(&mouseThreadSleep, (LONG)m_mousethread_sleep->value); InterlockedExchange(&mouseThreadSleep, (LONG)m_mousethread_sleep->value);
s_hMouseQuitEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); s_hMouseQuitEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
@ -1610,28 +1600,27 @@ void GoldSourceInput::IN_Init (void)
} }
#endif #endif
#if USE_SDL2
#if XASH_APPLE #if XASH_APPLE
#define SDL2_FULL_LIBNAME "libsdl2-2.0.0.dylib" #define SDL2_FULL_LIBNAME "libsdl2-2.0.0.dylib"
#elif _WIN32 #elif XASH_WIN32
#define SDL2_FULL_LIBNAME "SDL2.dll" #define SDL2_FULL_LIBNAME "SDL2.dll"
#else #else
#define SDL2_FULL_LIBNAME "libSDL2-2.0.so.0" #define SDL2_FULL_LIBNAME "libSDL2-2.0.so.0"
#endif #endif
#if _WIN32 #if XASH_WIN32
sdl2Lib = LoadLibrary(SDL2_FULL_LIBNAME); sdl2Lib = LoadLibrary(SDL2_FULL_LIBNAME);
#else #else
sdl2Lib = dlopen(SDL2_FULL_LIBNAME, RTLD_NOW|RTLD_LOCAL); sdl2Lib = dlopen(SDL2_FULL_LIBNAME, RTLD_NOW|RTLD_LOCAL);
#endif #endif
if (sdl2Lib) { if (sdl2Lib) {
for (int j=0; j<ARRAYSIZE(sdlFunctions); ++j) { for (int j=0; j<ARRAYSIZE(sdlFunctions); ++j) {
#if _WIN32 #if XASH_WIN32
*(sdlFunctions[j].ppfnFunc) = GetProcAddress((HMODULE)sdl2Lib, sdlFunctions[j].name); *(sdlFunctions[j].ppfnFunc) = GetProcAddress((HMODULE)sdl2Lib, sdlFunctions[j].name);
#else #else
*(sdlFunctions[j].ppfnFunc) = dlsym(sdl2Lib, sdlFunctions[j].name); *(sdlFunctions[j].ppfnFunc) = dlsym(sdl2Lib, sdlFunctions[j].name);
#endif #endif
if (*sdlFunctions[j].ppfnFunc == NULL) { if (*sdlFunctions[j].ppfnFunc == NULL) {
#if _WIN32 #if XASH_WIN32
gEngfuncs.Con_Printf("Could not load SDL2 function %s\n", sdlFunctions[j].name); gEngfuncs.Con_Printf("Could not load SDL2 function %s\n", sdlFunctions[j].name);
#else #else
gEngfuncs.Con_Printf("Could not load SDL2 function %s: %s\n", sdlFunctions[j].name, dlerror()); gEngfuncs.Con_Printf("Could not load SDL2 function %s: %s\n", sdlFunctions[j].name, dlerror());
@ -1639,13 +1628,12 @@ void GoldSourceInput::IN_Init (void)
} }
} }
} else { } else {
#if _WIN32 #if XASH_WIN32
gEngfuncs.Con_Printf("Could not load SDL2\n"); gEngfuncs.Con_Printf("Could not load SDL2\n");
#else #else
gEngfuncs.Con_Printf("Could not load SDL2: %s\n", dlerror()); gEngfuncs.Con_Printf("Could not load SDL2: %s\n", dlerror());
#endif #endif
} }
#endif
gEngfuncs.pfnAddCommand ("force_centerview", Force_CenterView_f); gEngfuncs.pfnAddCommand ("force_centerview", Force_CenterView_f);
gEngfuncs.pfnAddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f); gEngfuncs.pfnAddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);

View File

@ -81,3 +81,8 @@ void IN_Init( void )
#endif #endif
currentInput->IN_Init(); currentInput->IN_Init();
} }
void IN_ResetMouse()
{
currentInput->IN_ResetMouse();
}

View File

@ -19,6 +19,7 @@ public:
virtual void IN_Commands( void ) = 0; virtual void IN_Commands( void ) = 0;
virtual void IN_Shutdown( void ) = 0; virtual void IN_Shutdown( void ) = 0;
virtual void IN_Init( void ) = 0; virtual void IN_Init( void ) = 0;
virtual void IN_ResetMouse( void ) = 0;
}; };
class FWGSInput : public AbstractInput class FWGSInput : public AbstractInput
@ -35,6 +36,7 @@ public:
virtual void IN_Commands( void ); virtual void IN_Commands( void );
virtual void IN_Shutdown( void ); virtual void IN_Shutdown( void );
virtual void IN_Init( void ); virtual void IN_Init( void );
virtual void IN_ResetMouse( void ) {}
protected: protected:
float ac_forwardmove; float ac_forwardmove;
@ -76,6 +78,7 @@ public:
virtual void IN_Commands( void ); virtual void IN_Commands( void );
virtual void IN_Shutdown( void ); virtual void IN_Shutdown( void );
virtual void IN_Init( void ); virtual void IN_Init( void );
virtual void IN_ResetMouse( void );
protected: protected:
void IN_GetMouseDelta( int *pOutX, int *pOutY); void IN_GetMouseDelta( int *pOutX, int *pOutY);