Skip to content

bugfix(mouse): Fix bad drag tolerances with high scroll speed factors, alternative#2826

Open
xezon wants to merge 2 commits into
TheSuperHackers:mainfrom
xezon:xezon/fix-drag-tolerance-2
Open

bugfix(mouse): Fix bad drag tolerances with high scroll speed factors, alternative#2826
xezon wants to merge 2 commits into
TheSuperHackers:mainfrom
xezon:xezon/fix-drag-tolerance-2

Conversation

@xezon

@xezon xezon commented Jun 23, 2026

Copy link
Copy Markdown

Merge with Rebase

This change fixes the bad drag tolerances with high scroll speed factors, which was introduced by #1501 and is especially pronounced in this Project because players are encouraged to set way higher scroll factors after #1026 when higher frame rates no longer increase the camera movement.

This is an alternative implementation to #2823 using the 3D camera tolerance.

TODO

  • Add pull id's to commit titles
  • Rework BaseType.h
  • Add fix comments

@xezon xezon added Bug Something is not working right, typically is user facing Critical Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Input labels Jun 23, 2026
@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes incorrect drag-detection behaviour at high scroll speed factors by incorporating a 3D camera-position delta into the isClick check alongside the existing 2D pixel and time tolerances. It also upgrades the pixel tolerance from a rectangle test (abs(dx) > tol || abs(dy) > tol) to a circular distance test (lengthSqr > sqr(tol)).

  • Mouse::isClick gains two Coord3D parameters for camera position at mouse-down and mouse-up; a non-zero camera movement beyond m_dragTolerance3D is now treated as a drag.
  • Both CommandXlat and SelectionXlat are updated to capture TheTacticalView->getPosition() on button-down and pass it through the new signature.
  • BaseType.h receives arithmetic operators (+, -, +=, -=), lengthSqr(), and typed set() overloads for all four coord structs, enabling the in-place delta calculation inside isClick.

Confidence Score: 5/5

Safe to merge — the logic change is self-contained, all call sites have been updated, and the new circular tolerance is a straightforward improvement over the old rectangular check.

The camera-position delta is now correctly captured at button-down and button-up in both translators and passed directly to isClick, replacing what was previously a dead computed delta in SelectionXlat. All callers of the old signature have been updated. The new arithmetic helpers in BaseType.h are simple and correct. No paths appear missed.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/Input/Mouse.cpp isClick refactored to accept both 2D mouse anchors and 3D camera positions; switch from rectangular to circular pixel tolerance; new 3D camera delta check added
Core/GameEngine/Include/GameClient/Mouse.h isClick signature updated to pass anchors and camera positions by const-ref; m_dragTolerance3D already existed as UnsignedInt member
Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Adds m_rightMouseDownCameraPos / m_rightMouseUpCameraPos captured from TheTacticalView on each button event; all isClick call sites updated
Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp Member renames (deselectFeedbackAnchor→rightMouseDownAnchor, lastClick→rightMouseDownTimeMs, etc.); isClick now receives live cameraPos instead of pre-subtracted delta
Core/Libraries/Include/Lib/BaseType.h Adds operator+/-/+=/−=, add/sub, set, and lengthSqr to Coord2D, ICoord2D, Coord3D, ICoord3D; set() overloads correctly use matching scalar types
Core/GameEngine/Include/GameClient/CommandXlat.h Member variable renames and addition of Coord3D camera-position anchors for right mouse down/up events
Core/GameEngine/Include/GameClient/SelectionXlat.h Member renames aligned with CommandXlat naming convention; Coord3D camera position field added; m_deselectDownCameraPosition removed in favour of new name

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Mouse Button Down Event] --> B[Record mouseDownAnchor, timeMs, cameraPos]
    A2[Mouse Button Up Event] --> C[Record mouseUpAnchor, timeMs, cameraPos]
    C --> D[isClick mouse, camera, time]
    D --> E{timeMsDelta > m_dragToleranceMS?}
    E -- YES --> F[return FALSE - is a drag]
    E -- NO --> G{mouseAnchorDelta.lengthSqr > sqr m_dragTolerance?}
    G -- YES --> F
    G -- NO --> H{cameraPosDelta.lengthSqr > sqr m_dragTolerance3D?}
    H -- YES --> F
    H -- NO --> I[return TRUE - is a click]
    I --> J[CommandXlat: Cancel build placement / Alternate-mouse move-to-ground]
    I --> K[SelectionXlat: Deselect / right-click action]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Mouse Button Down Event] --> B[Record mouseDownAnchor, timeMs, cameraPos]
    A2[Mouse Button Up Event] --> C[Record mouseUpAnchor, timeMs, cameraPos]
    C --> D[isClick mouse, camera, time]
    D --> E{timeMsDelta > m_dragToleranceMS?}
    E -- YES --> F[return FALSE - is a drag]
    E -- NO --> G{mouseAnchorDelta.lengthSqr > sqr m_dragTolerance?}
    G -- YES --> F
    G -- NO --> H{cameraPosDelta.lengthSqr > sqr m_dragTolerance3D?}
    H -- YES --> F
    H -- NO --> I[return TRUE - is a click]
    I --> J[CommandXlat: Cancel build placement / Alternate-mouse move-to-ground]
    I --> K[SelectionXlat: Deselect / right-click action]
Loading

Reviews (4): Last reviewed commit: "bugfix(mouse): Fix bad drag tolerances w..." | Re-trigger Greptile

Comment thread Core/Libraries/Include/Lib/BaseType.h Outdated
@xezon xezon force-pushed the xezon/fix-drag-tolerance-2 branch from 920fa79 to a412fc5 Compare June 23, 2026 19:31
@Skyaero42

Copy link
Copy Markdown

Would be nice if GO could do some A/B testing.

@xezon xezon force-pushed the xezon/fix-drag-tolerance-2 branch 2 times, most recently from 8399669 to cc8df7b Compare June 28, 2026 06:49
@xezon

xezon commented Jun 28, 2026

Copy link
Copy Markdown
Author

LoGicA

for me test build 2826 is good, i dont have any issue with any building or deselecting
in 2823 i dont think my clicks always register
ive tested this out alot on skirmish

@xezon

xezon commented Jun 28, 2026

Copy link
Copy Markdown
Author

SR_MaD^

both builds were fine for me, but this one was a bit better: #2826

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this one is preferred over #2823 then

Comment thread Core/GameEngine/Source/GameClient/Input/Mouse.cpp Outdated
@xezon xezon force-pushed the xezon/fix-drag-tolerance-2 branch from cc8df7b to 44c5f0b Compare June 29, 2026 18:20
@xezon

xezon commented Jun 29, 2026

Copy link
Copy Markdown
Author

Rebased. I had to reapply all edits in SelectionXlat because of the mass refactor from a previous commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Critical Severity: Minor < Major < Critical < Blocker Gen Relates to Generals Input ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Army gets deselected when moving camera with drag right click

2 participants