mirror of
https://github.com/YGGverse/hlsdk-portable.git
synced 2025-01-11 15:38:12 +00:00
Dynamic sdl2 loading from client
This commit is contained in:
parent
646d2d92f6
commit
1759e8c956
@ -27,7 +27,10 @@ set (CLDLL_LIBRARY client)
|
|||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-write-strings -DLINUX -D_LINUX -Dstricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -DCLIENT_WEAPONS -DCLIENT_DLL -w")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-write-strings -DLINUX -D_LINUX -Dstricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -DCLIENT_WEAPONS -DCLIENT_DLL -w")
|
||||||
if (GOLDSOURCE_SUPPORT)
|
if (GOLDSOURCE_SUPPORT)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGOLDSOURCE_SUPPORT -lSDL2")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGOLDSOURCE_SUPPORT")
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ldl")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
|
||||||
|
|
||||||
|
@ -28,8 +28,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
|
#include <dlfcn.h>
|
||||||
#include <SDL2/SDL_mouse.h>
|
#include <SDL2/SDL_mouse.h>
|
||||||
#include <SDL2/SDL_gamecontroller.h>
|
#include <SDL2/SDL_gamecontroller.h>
|
||||||
|
int (*pfnSDL_SetRelativeMouseMode)(SDL_bool);
|
||||||
|
Uint32 (*pfnSDL_GetRelativeMouseState)(int* x, int* y);
|
||||||
|
int (*pfnSDL_NumJoysticks)(void);
|
||||||
|
SDL_bool (*pfnSDL_IsGameController)(int);
|
||||||
|
SDL_GameController* (*pfnSDL_GameControllerOpen)(int);
|
||||||
|
Sint16 (*pfnSDL_GameControllerGetAxis)(SDL_GameController*, SDL_GameControllerAxis);
|
||||||
|
Uint8 (*pfnSDL_GameControllerGetButton)(SDL_GameController*, SDL_GameControllerButton);
|
||||||
|
void (*pfnSDL_JoystickUpdate)(void);
|
||||||
|
const char* (*pfnSDL_GameControllerName)(SDL_GameController*);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -289,12 +299,12 @@ void IN_SetMouseMode(bool enable)
|
|||||||
if(m_bRawInput)
|
if(m_bRawInput)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
pfnSDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
isMouseRelative = true;
|
isMouseRelative = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
pfnSDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
currentMouseMode = true;
|
currentMouseMode = true;
|
||||||
@ -305,7 +315,7 @@ void IN_SetMouseMode(bool enable)
|
|||||||
if(isMouseRelative)
|
if(isMouseRelative)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
pfnSDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
#endif
|
#endif
|
||||||
isMouseRelative = false;
|
isMouseRelative = false;
|
||||||
}
|
}
|
||||||
@ -313,7 +323,7 @@ void IN_SetMouseMode(bool enable)
|
|||||||
if (restore_spi)
|
if (restore_spi)
|
||||||
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
|
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
|
||||||
#else
|
#else
|
||||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
pfnSDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
currentMouseMode = false;
|
currentMouseMode = false;
|
||||||
@ -464,6 +474,11 @@ void GoldSourceInput::IN_Shutdown (void)
|
|||||||
s_hMouseThreadActiveLock = (HANDLE)0;
|
s_hMouseThreadActiveLock = (HANDLE)0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SDL2
|
||||||
|
dlclose(sdl2Lib);
|
||||||
|
sdl2Lib = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -623,7 +638,7 @@ void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_GetRelativeMouseState( &deltaX, &deltaY );
|
pfnSDL_GetRelativeMouseState( &deltaX, &deltaY );
|
||||||
current_pos.x = deltaX;
|
current_pos.x = deltaX;
|
||||||
current_pos.y = deltaY;
|
current_pos.y = deltaY;
|
||||||
#else
|
#else
|
||||||
@ -679,14 +694,14 @@ void GoldSourceInput::IN_GetMouseDelta( int *pOutX, int *pOutY)
|
|||||||
if(m_bRawInput && !isMouseRelative)
|
if(m_bRawInput && !isMouseRelative)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
pfnSDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
isMouseRelative = true;
|
isMouseRelative = true;
|
||||||
}
|
}
|
||||||
else if(!m_bRawInput && isMouseRelative)
|
else if(!m_bRawInput && isMouseRelative)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
pfnSDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
#endif
|
#endif
|
||||||
isMouseRelative = false;
|
isMouseRelative = false;
|
||||||
}
|
}
|
||||||
@ -815,7 +830,7 @@ void GoldSourceInput::IN_Accumulate (void)
|
|||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
int deltaX, deltaY;
|
int deltaX, deltaY;
|
||||||
SDL_GetRelativeMouseState( &deltaX, &deltaY );
|
pfnSDL_GetRelativeMouseState( &deltaX, &deltaY );
|
||||||
mx_accum += deltaX;
|
mx_accum += deltaX;
|
||||||
my_accum += deltaY;
|
my_accum += deltaY;
|
||||||
#else
|
#else
|
||||||
@ -869,14 +884,14 @@ void IN_StartupJoystick (void)
|
|||||||
// assume no joystick
|
// assume no joystick
|
||||||
joy_avail = 0;
|
joy_avail = 0;
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
int nJoysticks = SDL_NumJoysticks();
|
int nJoysticks = pfnSDL_NumJoysticks();
|
||||||
if ( nJoysticks > 0 )
|
if ( nJoysticks > 0 )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < nJoysticks; i++ )
|
for ( int i = 0; i < nJoysticks; i++ )
|
||||||
{
|
{
|
||||||
if ( SDL_IsGameController( i ) )
|
if ( pfnSDL_IsGameController( i ) )
|
||||||
{
|
{
|
||||||
s_pJoystick = SDL_GameControllerOpen( i );
|
s_pJoystick = pfnSDL_GameControllerOpen( i );
|
||||||
if ( s_pJoystick )
|
if ( s_pJoystick )
|
||||||
{
|
{
|
||||||
//save the joystick's number of buttons and POV status
|
//save the joystick's number of buttons and POV status
|
||||||
@ -888,7 +903,7 @@ void IN_StartupJoystick (void)
|
|||||||
|
|
||||||
// mark the joystick as available and advanced initialization not completed
|
// mark the joystick as available and advanced initialization not completed
|
||||||
// this is needed as cvars are not available during initialization
|
// this is needed as cvars are not available during initialization
|
||||||
gEngfuncs.Con_Printf ("joystick found\n\n", SDL_GameControllerName(s_pJoystick));
|
gEngfuncs.Con_Printf ("joystick found\n\n", pfnSDL_GameControllerName(s_pJoystick));
|
||||||
joy_avail = 1;
|
joy_avail = 1;
|
||||||
joy_advancedinit = 0;
|
joy_advancedinit = 0;
|
||||||
break;
|
break;
|
||||||
@ -912,13 +927,13 @@ int RawValuePointer (int axis)
|
|||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case JOY_AXIS_X:
|
case JOY_AXIS_X:
|
||||||
return SDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_LEFTX );
|
return pfnSDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_LEFTX );
|
||||||
case JOY_AXIS_Y:
|
case JOY_AXIS_Y:
|
||||||
return SDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_LEFTY );
|
return pfnSDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_LEFTY );
|
||||||
case JOY_AXIS_Z:
|
case JOY_AXIS_Z:
|
||||||
return SDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_RIGHTX );
|
return pfnSDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_RIGHTX );
|
||||||
case JOY_AXIS_R:
|
case JOY_AXIS_R:
|
||||||
return SDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_RIGHTY );
|
return pfnSDL_GameControllerGetAxis( s_pJoystick, SDL_CONTROLLER_AXIS_RIGHTY );
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -1011,7 +1026,7 @@ void GoldSourceInput::IN_Commands (void)
|
|||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
for ( i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++ )
|
for ( i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++ )
|
||||||
{
|
{
|
||||||
if ( SDL_GameControllerGetButton( s_pJoystick, (SDL_GameControllerButton)i ) )
|
if ( pfnSDL_GameControllerGetButton( s_pJoystick, (SDL_GameControllerButton)i ) )
|
||||||
{
|
{
|
||||||
buttonstate |= 1<<i;
|
buttonstate |= 1<<i;
|
||||||
}
|
}
|
||||||
@ -1071,7 +1086,7 @@ IN_ReadJoystick
|
|||||||
int IN_ReadJoystick (void)
|
int IN_ReadJoystick (void)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL2
|
#ifdef USE_SDL2
|
||||||
SDL_JoystickUpdate();
|
pfnSDL_JoystickUpdate();
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1344,6 +1359,28 @@ void GoldSourceInput::IN_Init (void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SDL2
|
||||||
|
sdl2Lib = dlopen("libSDL2.so", RTLD_NOW|RTLD_LOCAL);
|
||||||
|
if (!sdl2Lib)
|
||||||
|
sdl2Lib = dlopen("libSDL2-2.0.so.0", RTLD_NOW|RTLD_LOCAL);
|
||||||
|
if (sdl2Lib) {
|
||||||
|
void** sdlFunctions[] = {(void**)&pfnSDL_SetRelativeMouseMode, (void**)&pfnSDL_GetRelativeMouseState, (void**)&pfnSDL_NumJoysticks,
|
||||||
|
(void**)&pfnSDL_IsGameController, (void**)&pfnSDL_GameControllerOpen, (void**)&pfnSDL_GameControllerGetAxis,
|
||||||
|
(void**)&pfnSDL_GameControllerGetButton, (void**)&pfnSDL_JoystickUpdate, (void**)&pfnSDL_GameControllerName};
|
||||||
|
const char* const sdlFuncNames[] = {"SDL_SetRelativeMouseMode", "SDL_GetRelativeMouseState", "SDL_NumJoysticks",
|
||||||
|
"SDL_IsGameController", "SDL_GameControllerOpen", "SDL_GameControllerGetAxis",
|
||||||
|
"SDL_GameControllerGetButton", "SDL_JoystickUpdate", "SDL_GameControllerName"};
|
||||||
|
for (int j=0; j<sizeof(sdlFunctions)/sizeof(sdlFunctions[0]); ++j) {
|
||||||
|
*(sdlFunctions[j]) = dlsym(sdl2Lib, sdlFuncNames[j]);
|
||||||
|
if (*sdlFunctions[j] == NULL) {
|
||||||
|
gEngfuncs.Con_Printf("Could not load SDL2 function %s: %s\n", sdlFuncNames[j], dlerror());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gEngfuncs.Con_Printf("Could not load SDL2: %s\n", dlerror());
|
||||||
|
}
|
||||||
|
#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);
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ protected:
|
|||||||
POINT current_pos;
|
POINT current_pos;
|
||||||
int old_mouse_x, old_mouse_y, mx_accum, my_accum;
|
int old_mouse_x, old_mouse_y, mx_accum, my_accum;
|
||||||
int mouseinitialized;
|
int mouseinitialized;
|
||||||
|
void* sdl2Lib;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user