Skip to content

Commit

Permalink
Add ClImproveMousePrecision
Browse files Browse the repository at this point in the history
  • Loading branch information
SollyBunny committed Nov 23, 2024
1 parent ae45100 commit e62b6a5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/engine/shared/tater_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MACRO_CONFIG_INT(ClPingNameCircle, tc_nameplate_ping_circle, 0, 0, 1, CFGFLAG_CL
MACRO_CONFIG_INT(ClSpecmenuID, tc_spec_menu_ID, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Shows player IDs in spectate menu")

MACRO_CONFIG_INT(ClLimitMouseToScreen, tc_limit_mouse_to_screen, 0, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Limit mouse to screen boundries")
MACRO_CONFIG_INT(ClImproveMousePrecision, tc_improve_mouse_precision, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Improve mouse precision by scaling max distance to 2000")

MACRO_CONFIG_INT(ClHammerRotatesWithCursor, tc_hammer_rotates_with_cursor, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Allow your hammer to rotate like other weapons")

Expand Down
39 changes: 19 additions & 20 deletions src/game/client/components/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,36 @@ int CControls::SnapInput(int *pData)

// set the target anyway though so that we can keep seeing our surroundings,
// even if chat or menu are activated
m_aInputData[g_Config.m_ClDummy].m_TargetX = (int)m_aMousePos[g_Config.m_ClDummy].x;
m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)m_aMousePos[g_Config.m_ClDummy].y;

// scale TargetX, TargetY by zoom.
vec2 Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
if(g_Config.m_ClImproveMousePrecision)
Pos *= length(Pos) * 2000.0f / (float)(g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance);
if(!m_pClient->m_Snap.m_SpecInfo.m_Active && !g_Config.m_ClOldMouseZoom)
{
m_aInputData[g_Config.m_ClDummy].m_TargetX *= m_pClient->m_Camera.m_Zoom;
m_aInputData[g_Config.m_ClDummy].m_TargetY *= m_pClient->m_Camera.m_Zoom;
}
Pos *= m_pClient->m_Camera.m_Zoom;
m_aInputData[g_Config.m_ClDummy].m_TargetX = (int)Pos.x;
m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)Pos.y;

// send once a second just to be sure
Send = Send || time_get() > m_LastSendTime + time_freq();
}
else
{
m_aInputData[g_Config.m_ClDummy].m_TargetX = (int)m_aMousePos[g_Config.m_ClDummy].x;
m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)m_aMousePos[g_Config.m_ClDummy].y;

vec2 Pos;
if(g_Config.m_ClSubTickAiming && m_aMousePosOnAction[g_Config.m_ClDummy] != vec2(0.0f, 0.0f))
{
m_aInputData[g_Config.m_ClDummy].m_TargetX = (int)m_aMousePosOnAction[g_Config.m_ClDummy].x;
m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)m_aMousePosOnAction[g_Config.m_ClDummy].y;
Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
m_aMousePosOnAction[g_Config.m_ClDummy] = vec2(0.0f, 0.0f);
}
else
Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
if(!m_pClient->m_Snap.m_SpecInfo.m_Active)
{
if(g_Config.m_ClImproveMousePrecision)
Pos *= length(Pos) * 2000.0f / (float)(g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance);
if(!g_Config.m_ClOldMouseZoom)
Pos *= m_pClient->m_Camera.m_Zoom;
}
m_aInputData[g_Config.m_ClDummy].m_TargetX = (int)Pos.x;
m_aInputData[g_Config.m_ClDummy].m_TargetY = (int)Pos.y;

if(!m_aInputData[g_Config.m_ClDummy].m_TargetX && !m_aInputData[g_Config.m_ClDummy].m_TargetY)
{
Expand All @@ -246,13 +252,6 @@ int CControls::SnapInput(int *pData)
if(!m_aInputDirectionLeft[g_Config.m_ClDummy] && m_aInputDirectionRight[g_Config.m_ClDummy])
m_aInputData[g_Config.m_ClDummy].m_Direction = 1;

// scale TargetX, TargetY by zoom.
if(!m_pClient->m_Snap.m_SpecInfo.m_Active && !g_Config.m_ClOldMouseZoom)
{
m_aInputData[g_Config.m_ClDummy].m_TargetX *= m_pClient->m_Camera.m_Zoom;
m_aInputData[g_Config.m_ClDummy].m_TargetY *= m_pClient->m_Camera.m_Zoom;
}

// dummy copy moves
if(g_Config.m_ClDummyCopyMoves)
{
Expand Down
5 changes: 4 additions & 1 deletion src/game/client/components/menus_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,8 @@ void CMenus::RenderSettingsTClient(CUIRect MainView)
Column.HSplitTop(LineSize, nullptr, &Column);
Column.HSplitTop(MarginSmall, nullptr, &Column);
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClOldMouseZoom, Localize("Old Mouse Precision (fixes precision at low zoom levels, \nbreaks /tc, /telecursor while zoomed)"), &g_Config.m_ClOldMouseZoom, &Column, LineSize);
Column.HSplitTop(MarginSmall, nullptr, &Column);
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClImproveMousePrecision, Localize("Improve mouse precision by scaling max distance to 2000"), &g_Config.m_ClImproveMousePrecision, &Column, LineSize);
s_SectionBoxes.back().h = Column.y - s_SectionBoxes.back().y;

// ***** Anti Latency Tools ***** //
Expand Down Expand Up @@ -3615,6 +3617,7 @@ void CMenus::RenderSettingsTClient(CUIRect MainView)
int RainbowSelectedOld = g_Config.m_ClRainbowMode - 1;
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClRainbow, Localize("Rainbow"), &g_Config.m_ClRainbow, &Column, LineSize);
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClRainbowOthers, Localize("Rainbow Others"), &g_Config.m_ClRainbowOthers, &Column, LineSize);
Column.HSplitTop(MarginExtraSmall, nullptr, &Column);
CUIRect DropDownRect;
Column.HSplitTop(LineSize, &DropDownRect, &Column);
const int RainbowSelectedNew = Ui()->DoDropDown(&DropDownRect, RainbowSelectedOld, s_DropDownNames.data(), s_DropDownNames.size(), s_RainbowDropDownState);
Expand All @@ -3634,7 +3637,7 @@ void CMenus::RenderSettingsTClient(CUIRect MainView)
// Scroll
CUIRect ScrollRegion;
ScrollRegion.x = MainView.x;
ScrollRegion.y = maximum(LeftView.y, RightView.y) + MarginSmall;
ScrollRegion.y = maximum(LeftView.y, RightView.y) + MarginSmall * 2.0f;
ScrollRegion.w = MainView.w;
ScrollRegion.h = 0.0f;
s_ScrollRegion.AddRect(ScrollRegion);
Expand Down
50 changes: 25 additions & 25 deletions src/game/client/components/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,21 @@ void CPlayers::RenderHookCollLine(
if(Local && (!m_pClient->m_Snap.m_SpecInfo.m_Active || m_pClient->m_Snap.m_SpecInfo.m_SpectatorId != SPEC_FREEVIEW) && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
// just use the direct input if it's the local player we are rendering
Angle = angle(m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy] * m_pClient->m_Camera.m_Zoom);
if(g_Config.m_ClOldMouseZoom)
Angle = angle(m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy]);
vec2 Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
if(g_Config.m_ClImproveMousePrecision)
Pos *= length(Pos) * 2000.0f / (float)(g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance);
if(!g_Config.m_ClOldMouseZoom)
Pos *= m_pClient->m_Camera.m_Zoom;
Pos.x = (int)Pos.x;
Pos.y = (int)Pos.y;
Angle = angle(Pos);
}
else
{
Angle = GetPlayerTargetAngle(&Prev, &Player, ClientId, IntraTick);
}

vec2 Direction = direction(Angle);
vec2 ExDirection = direction(Angle);
vec2 Position;
if(in_range(ClientId, MAX_CLIENTS - 1))
Position = m_pClient->m_aClients[ClientId].m_RenderPos;
Expand Down Expand Up @@ -234,23 +239,6 @@ void CPlayers::RenderHookCollLine(
#endif
if((AlwaysRenderHookColl || RenderHookCollPlayer) && RenderHookCollVideo)
{
vec2 ExDirection = Direction;

if(Local && (!m_pClient->m_Snap.m_SpecInfo.m_Active || m_pClient->m_Snap.m_SpecInfo.m_SpectatorId != SPEC_FREEVIEW) && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
ExDirection = normalize(
vec2((int)((int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].x * m_pClient->m_Camera.m_Zoom),
(int)((int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].y * m_pClient->m_Camera.m_Zoom)));

if(g_Config.m_ClOldMouseZoom)
ExDirection = normalize(
vec2((int)((int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].x),
(int)((int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].y)));

// fix direction if mouse is exactly in the center
if(!(int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].x && !(int)m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy].y)
ExDirection = vec2(1, 0);
}
Graphics()->TextureClear();
vec2 InitPos = Position;
vec2 FinishPos = InitPos + ExDirection * (m_pClient->m_aTuning[g_Config.m_ClDummy].m_HookLength - 42.0f);
Expand Down Expand Up @@ -484,9 +472,14 @@ void CPlayers::RenderPlayer(
if(Local && (!m_pClient->m_Snap.m_SpecInfo.m_Active || m_pClient->m_Snap.m_SpecInfo.m_SpectatorId != SPEC_FREEVIEW) && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
// just use the direct input if it's the local player we are rendering
Angle = angle(m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy] * m_pClient->m_Camera.m_Zoom);
if(g_Config.m_ClOldMouseZoom)
Angle = angle(m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy]);
vec2 Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
if(g_Config.m_ClImproveMousePrecision)
Pos *= length(Pos) * 2000.0f / (float)(g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance);
if(!g_Config.m_ClOldMouseZoom)
Pos *= m_pClient->m_Camera.m_Zoom;
Pos.x = (int)Pos.x;
Pos.y = (int)Pos.y;
Angle = angle(Pos);
}
else
{
Expand Down Expand Up @@ -914,7 +907,14 @@ void CPlayers::RenderPlayerGhost(
if(Local && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
// just use the direct input if it's the local player we are rendering
Angle = angle(m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy]);
vec2 Pos = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy];
if(g_Config.m_ClImproveMousePrecision)
Pos *= length(Pos) * 2000.0f / (float)(g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance);
if(!g_Config.m_ClOldMouseZoom)
Pos *= m_pClient->m_Camera.m_Zoom;
Pos.x = (int)Pos.x;
Pos.y = (int)Pos.y;
Angle = angle(Pos);
}
else
{
Expand Down

0 comments on commit e62b6a5

Please sign in to comment.