[HL25] Backport input related changes

This commit is contained in:
Joël Troch 2024-08-28 16:16:45 +02:00
parent 4f0d502e4e
commit 0dd796c295
4 changed files with 94 additions and 31 deletions

View file

@ -80,7 +80,7 @@ static CHLVoiceStatusHelper g_VoiceStatusHelper;
extern client_sprite_t* GetSpriteList(client_sprite_t* pList, const char* psz, int iRes, int iCount);
extern cvar_t* sensitivity;
extern float IN_GetMouseSensitivity();
cvar_t* cl_lw = NULL;
cvar_t* cl_rollangle = nullptr;
cvar_t* cl_rollspeed = nullptr;
@ -326,7 +326,7 @@ void CHud::Init()
m_iLogo = 0;
m_iFOV = 0;
CVAR_CREATE("zoom_sensitivity_ratio", "1.2", 0);
CVAR_CREATE("zoom_sensitivity_ratio", "1.2", FCVAR_ARCHIVE);
CVAR_CREATE("cl_autowepswitch", "1", FCVAR_ARCHIVE | FCVAR_USERINFO);
default_fov = CVAR_CREATE("default_fov", "90", FCVAR_ARCHIVE);
m_pCvarStealMouse = CVAR_CREATE("hud_capturemouse", "1", FCVAR_ARCHIVE);
@ -661,7 +661,7 @@ bool CHud::MsgFunc_SetFOV(const char* pszName, int iSize, void* pbuf)
else
{
// set a new sensitivity that is proportional to the change from the FOV default
m_flMouseSensitivity = sensitivity->value * ((float)newfov / (float)def_fov) * CVAR_GET_FLOAT("zoom_sensitivity_ratio");
m_flMouseSensitivity = IN_GetMouseSensitivity() * ((float)newfov / (float)def_fov) * CVAR_GET_FLOAT("zoom_sensitivity_ratio");
}
return true;

View file

@ -33,7 +33,7 @@ extern bool g_iVisibleMouse;
float HUD_GetFOV();
extern cvar_t* sensitivity;
extern float IN_GetMouseSensitivity();
// Think
void CHud::Think()
@ -72,7 +72,7 @@ void CHud::Think()
else
{
// set a new sensitivity that is proportional to the change from the FOV default
m_flMouseSensitivity = sensitivity->value * ((float)newfov / (float)default_fov->value) * CVAR_GET_FLOAT("zoom_sensitivity_ratio");
m_flMouseSensitivity = IN_GetMouseSensitivity() * ((float)newfov / (float)V_max(default_fov->value, 90.0f)) * CVAR_GET_FLOAT("zoom_sensitivity_ratio");
}
// think about default fov

View file

@ -28,6 +28,7 @@
#include "PlatformHeaders.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_mouse.h>
#include <SDL2/SDL_gamecontroller.h>
@ -158,6 +159,7 @@ cvar_t* joy_advaxisz;
cvar_t* joy_advaxisr;
cvar_t* joy_advaxisu;
cvar_t* joy_advaxisv;
cvar_t* joy_supported;
cvar_t* joy_forwardthreshold;
cvar_t* joy_sidethreshold;
cvar_t* joy_pitchthreshold;
@ -169,7 +171,7 @@ cvar_t* joy_yawsensitivity;
cvar_t* joy_wwhack1;
cvar_t* joy_wwhack2;
bool joy_avail, joy_advancedinit, joy_haspov;
bool joy_avail = false, joy_advancedinit, joy_haspov;
/*
===========
@ -378,6 +380,28 @@ void IN_GetMousePos(int* mx, int* my)
gEngfuncs.GetMousePosition(mx, my);
}
/*
===========
IN_GetMouseSensitivity
Get mouse sensitivity with sanitization
===========
*/
float IN_GetMouseSensitivity()
{
// Absurdly high sensitivity values can cause the game to hang, so clamp
if (sensitivity->value > 10000.0)
{
gEngfuncs.Cvar_SetValue("sensitivity", 10000.0);
}
else if (sensitivity->value < 0.01)
{
gEngfuncs.Cvar_SetValue("sensitivity", 0.01);
}
return sensitivity->value;
}
/*
===========
IN_ResetMouse
@ -389,11 +413,6 @@ void IN_ResetMouse()
{
// no work to do in SDL
#ifdef WIN32
if (IN_UseRawInput() && !g_iVisibleMouse)
{
IN_SetMouseRelative(true);
}
if (!IN_UseRawInput() && mouseactive && gEngfuncs.GetWindowCenterX && gEngfuncs.GetWindowCenterY)
{
SetCursorPos(gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
@ -404,6 +423,21 @@ void IN_ResetMouse()
#endif
}
/*
===========
IN_ResetRelativeMouseState
===========
*/
void IN_ResetRelativeMouseState(void)
{
if (IN_UseRawInput())
{
SDL_PumpEvents();
int deltaX, deltaY;
SDL_GetRelativeMouseState(&deltaX, &deltaY);
}
}
/*
===========
IN_MouseEvent
@ -447,7 +481,7 @@ void IN_ScaleMouse(float* x, float* y)
float my = *y;
// This is the default sensitivity
float mouse_senstivity = (gHUD.GetSensitivity() != 0) ? gHUD.GetSensitivity() : sensitivity->value;
float mouse_senstivity = (gHUD.GetSensitivity() != 0) ? gHUD.GetSensitivity() : IN_GetMouseSensitivity();
// Using special accleration values
if (m_customaccel->value != 0)
@ -689,39 +723,55 @@ void IN_StartupJoystick()
if (0 != gEngfuncs.CheckParm("-nojoy", NULL))
return;
// assume no joystick
joy_avail = false;
static float flLastCheck = 0.0f;
if (flLastCheck > 0.0f && (gEngfuncs.GetAbsoluteTime() - flLastCheck) < 1.0f)
return;
//gEngfuncs.Con_Printf("IN_StartupJoystick, %f\n", flLastCheck);
flLastCheck = gEngfuncs.GetAbsoluteTime();
int nJoysticks = SDL_NumJoysticks();
if (nJoysticks > 0)
{
for (int i = 0; i < nJoysticks; i++)
if (s_pJoystick == NULL)
{
if (SDL_FALSE != SDL_IsGameController(i))
for (int i = 0; i < nJoysticks; i++)
{
s_pJoystick = SDL_GameControllerOpen(i);
if (s_pJoystick)
if (SDL_FALSE != SDL_IsGameController(i))
{
//save the joystick's number of buttons and POV status
joy_numbuttons = SDL_CONTROLLER_BUTTON_MAX;
joy_haspov = false;
s_pJoystick = SDL_GameControllerOpen(i);
if (s_pJoystick)
{
// save the joystick's number of buttons and POV status
joy_numbuttons = SDL_CONTROLLER_BUTTON_MAX;
joy_haspov = false;
// old button and POV states default to no buttons pressed
joy_oldbuttonstate = joy_oldpovstate = 0;
// old button and POV states default to no buttons pressed
joy_oldbuttonstate = joy_oldpovstate = 0;
// mark the joystick as available and advanced initialization not completed
// this is needed as cvars are not available during initialization
gEngfuncs.Con_Printf("joystick found %s\n\n", SDL_GameControllerName(s_pJoystick));
joy_avail = true;
joy_advancedinit = false;
break;
// mark the joystick as available and advanced initialization not completed
// this is needed as cvars are not available during initialization
gEngfuncs.Con_Printf("joystick found %s\n\n", SDL_GameControllerName(s_pJoystick));
joy_avail = true;
joy_advancedinit = false;
break;
}
}
}
}
}
else
{
gEngfuncs.Con_DPrintf("joystick not found -- driver not present\n\n");
if (s_pJoystick)
SDL_GameControllerClose(s_pJoystick);
s_pJoystick = NULL;
if (joy_avail)
{
joy_avail = 0;
gEngfuncs.Con_DPrintf("joystick not found -- driver not present\n\n");
}
}
}
@ -842,12 +892,14 @@ void IN_Commands()
{
key_index = (i < 4) ? K_JOY1 : K_AUX1;
gEngfuncs.Key_Event(key_index + i, 1);
//gEngfuncs.Con_Printf("Button %d pressed\n", i);
}
if ((buttonstate & (1 << i)) == 0 && (joy_oldbuttonstate & (1 << i)) != 0)
{
key_index = (i < 4) ? K_JOY1 : K_AUX1;
gEngfuncs.Key_Event(key_index + i, 0);
//gEngfuncs.Con_Printf("Button %d released\n", i);
}
}
joy_oldbuttonstate = buttonstate;
@ -911,6 +963,9 @@ void IN_JoyMove(float frametime, usercmd_t* cmd)
joy_advancedinit = true;
}
// re-scan for joystick presence
IN_StartupJoystick();
// verify joystick is available and that the user wants to use it
if (!joy_avail || 0 == in_joystick->value)
{
@ -1097,7 +1152,7 @@ IN_Init
void IN_Init()
{
m_filter = gEngfuncs.pfnRegisterVariable("m_filter", "0", FCVAR_ARCHIVE);
sensitivity = gEngfuncs.pfnRegisterVariable("sensitivity", "3", FCVAR_ARCHIVE); // user mouse sensitivity setting.
sensitivity = gEngfuncs.pfnRegisterVariable("sensitivity", "3", FCVAR_ARCHIVE | FCVAR_FILTERSTUFFTEXT); // user mouse sensitivity setting.
in_joystick = gEngfuncs.pfnRegisterVariable("joystick", "0", FCVAR_ARCHIVE);
joy_name = gEngfuncs.pfnRegisterVariable("joyname", "joystick", 0);
@ -1108,6 +1163,7 @@ void IN_Init()
joy_advaxisr = gEngfuncs.pfnRegisterVariable("joyadvaxisr", "0", 0);
joy_advaxisu = gEngfuncs.pfnRegisterVariable("joyadvaxisu", "0", 0);
joy_advaxisv = gEngfuncs.pfnRegisterVariable("joyadvaxisv", "0", 0);
joy_supported = gEngfuncs.pfnRegisterVariable("joysupported", "1", 0);
joy_forwardthreshold = gEngfuncs.pfnRegisterVariable("joyforwardthreshold", "0.15", 0);
joy_sidethreshold = gEngfuncs.pfnRegisterVariable("joysidethreshold", "0.15", 0);
joy_pitchthreshold = gEngfuncs.pfnRegisterVariable("joypitchthreshold", "0.15", 0);

View file

@ -77,6 +77,7 @@ int g_iUser3 = 0;
#define SBOARD_INDENT_Y_400 20
void IN_ResetMouse();
void IN_ResetRelativeMouseState();
extern CMenuPanel* CMessageWindowPanel_Create(const char* szMOTD, const char* szTitle, bool iShadeFullscreen, bool iRemoveMe, int x, int y, int wide, int tall);
extern float* GetClientColor(int clientIndex);
@ -1673,6 +1674,12 @@ void TeamFortressViewport::UpdateCursorState()
IN_ResetMouse();
}
if (g_iVisibleMouse)
{
// Clear any residual input so our camera doesn't jerk when dismissing the UI
IN_ResetRelativeMouseState();
}
g_iVisibleMouse = false;
App::getInstance()->setCursorOveride(App::getInstance()->getScheme()->getCursor(Scheme::scu_none));
}