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

@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 spurious drag-detection when using high camera scroll speed factors by threading the 3D camera position through Mouse::isClick(). Previously, only 2D mouse pixel movement and elapsed time were checked; after this change a third condition rejects the click if the camera has traveled more than DragTolerance3D world units between mouse-down and mouse-up.

  • BaseType.h gains arithmetic operators and lengthSqr() on all four coord types (Coord2D, ICoord2D, Coord3D, ICoord3D) to support the new distance comparison.
  • Mouse::isClick() is refactored from pointer arguments to const-references and adds the circular squared-distance check in place of the old axis-aligned rectangle check.
  • CommandXlat and SelectionXlat each capture TheTacticalView->getPosition() on both mouse-down and mouse-up and pass both positions to isClick(); the previously-dead camera subtraction in SelectionXlat is finally wired in correctly.

Confidence Score: 5/5

Safe to merge — the fix is well-scoped and correctly wires camera-position tracking into all right-click paths.

The logic change from axis-aligned rectangle to circular tolerance is intentional and correct. The dead camera-subtraction code in SelectionXlat is finally put to use, and CommandXlat gains equivalent coverage. No pre-existing click-detection path is broken; the only finding is a stale two-condition comment inside isClick() that does not document the new third condition.

No files require special attention. The INI field DragTolerance3D must be present in the game data files for the tolerance to have a non-zero value, but this is consistent with how DragTolerance and DragToleranceMS are also configured.

Important Files Changed

Filename Overview
Core/Libraries/Include/Lib/BaseType.h Adds arithmetic operators (+, -, +=, -=), set(), add(), sub() methods and lengthSqr() to Coord2D, ICoord2D, Coord3D, ICoord3D — foundations needed by the click-detection refactor.
Core/GameEngine/Source/GameClient/Input/Mouse.cpp isClick() signature extended with two Coord3D camera positions; drag check now uses circular lengthSqr comparison and adds a 3D camera-movement tolerance. Inline comment not updated to reflect the new 3rd condition.
Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp Dead camera-position subtraction code replaced with proper camera-position tracking; right-click handler now passes both down/up camera positions to isClick(). Clean refactor.
Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Captures camera position on right-mouse-down and right-mouse-up, passes both to isClick(). Member variables renamed for clarity. Clean refactor.
Core/GameEngine/Include/GameClient/Mouse.h isClick() signature updated to take const references instead of pointers, adding two Coord3D camera parameters. Clean API improvement.
Core/GameEngine/Include/GameClient/CommandXlat.h Four right-mouse member fields renamed for clarity; two new Coord3D camera position fields added.
Core/GameEngine/Include/GameClient/SelectionXlat.h Member fields renamed and m_deselectDownCameraPosition replaced by m_rightMouseDownCameraPos; m_lastClick renamed to m_rightMouseDownTimeMs for naming consistency.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Right Mouse Down] --> B[Store mouseDownAnchor\nStore mouseDownTimeMs\nStore cameraDownPos]
    C[Right Mouse Up] --> D[Store mouseUpAnchor\nStore mouseUpTimeMs\nStore cameraUpPos]
    D --> E[Call isClick]
    E --> F{timeDelta > dragToleranceMS?}
    F -- YES --> G[Return FALSE\nnot a click]
    F -- NO --> H{mouseAnchorDelta.lengthSqr\n> sqr dragTolerance?}
    H -- YES --> G
    H -- NO --> I{cameraPosDelta.lengthSqr\n> sqr dragTolerance3D?}
    I -- YES --> G
    I -- NO --> J[Return TRUE\nit is a click]
    J --> K[Execute 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[Right Mouse Down] --> B[Store mouseDownAnchor\nStore mouseDownTimeMs\nStore cameraDownPos]
    C[Right Mouse Up] --> D[Store mouseUpAnchor\nStore mouseUpTimeMs\nStore cameraUpPos]
    D --> E[Call isClick]
    E --> F{timeDelta > dragToleranceMS?}
    F -- YES --> G[Return FALSE\nnot a click]
    F -- NO --> H{mouseAnchorDelta.lengthSqr\n> sqr dragTolerance?}
    H -- YES --> G
    H -- NO --> I{cameraPosDelta.lengthSqr\n> sqr dragTolerance3D?}
    I -- YES --> G
    I -- NO --> J[Return TRUE\nit is a click]
    J --> K[Execute right-click action]
Loading

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

Comment thread Core/Libraries/Include/Lib/BaseType.h
@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.

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