Skip to content

refactor: Refactor evaluateContextCommand phase 1 (#1192)#2714

Open
RikuAnt wants to merge 4 commits into
TheSuperHackers:mainfrom
RikuAnt:refactor/#1192_Refactor_evaluateContextCommand_phase1
Open

refactor: Refactor evaluateContextCommand phase 1 (#1192)#2714
RikuAnt wants to merge 4 commits into
TheSuperHackers:mainfrom
RikuAnt:refactor/#1192_Refactor_evaluateContextCommand_phase1

Conversation

@RikuAnt
Copy link
Copy Markdown

@RikuAnt RikuAnt commented May 15, 2026

Relates to: #1192

  • Refactor context input normalization into separate function
  • Refactor GUI command target normalization into separate function
  • Refactor waypoint mode command into separate function
  • Clarify intent of early returns

Initial plan is to extract the context command handling into focused sub-functions, so the decision path in evaluateContextCommand becomes immediately legible as a dispatcher. Once the structure is clear, the aim is to simplify the logical flow by eliminating redundant branching and guard conditions that no longer need to live at the top level

TODO:

  • Replicate in Generals.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 15, 2026

Greptile Summary

This PR extracts three helper functions from the evaluateContextCommand monolith: normalizeContextInputs (clears draw/obj for masked, mine, force-move/attack targets), handleWaypointModeCommand (issues or hints a waypoint move), and normalizeGuiCommandTarget (strips shrubbery, mine, and relationship-filtered targets before GUI command dispatch). The evaluateContextCommand caller is restructured around explicit early returns and a canPerformActions guard, making its dispatch logic more legible.

  • normalizeContextInputs is correctly extracted and called with pass-by-reference semantics; drawableInWay is still consumed at the move-to fallback path (~line 2460).
  • handleWaypointModeCommand is now always returned from unconditionally, resolving the previously reported early-return regression.
  • normalizeGuiCommandTarget is now correctly called inside the if(command && …) block, restoring the shrubbery/mine/relationship filtering that was temporarily missing.

Confidence Score: 5/5

Safe to merge; all three regressions reported in prior review rounds have been corrected and the extracted helpers are behaviourally equivalent to the original inline code.

The three issues called out in earlier rounds — normalizeGuiCommandTarget never being called, handleWaypointModeCommand not unconditionally returning, and the orphaned else-if chain — are all resolved. The refactored evaluateContextCommand preserves the original execution order: input normalisation, prefer-selection guard, beacon early-return, controllability gate, waypoint dispatch, GUI-command dispatch with target normalisation, then the full natural-action cascade. drawableInWay is still correctly threaded through to the move-to fallback at the bottom of the function. No new logic has been introduced.

No files require special attention.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Three helpers extracted from evaluateContextCommand; previously-reported regressions (missing normalizeGuiCommandTarget call, waypoint non-return, orphaned else-if) are resolved in this revision. Logic is semantically equivalent to the original.
GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h Three new private method declarations added matching the extracted implementations; minor blank-line removal. No structural concerns.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[evaluateContextCommand] --> B[normalizeContextInputs]
    B --> C{preferSelection?}
    C -- yes --> RET0[return MSG_INVALID]
    C -- no --> D{PLACE_BEACON?}
    D -- yes --> RET1[return MSG_VALID_GUICOMMAND_HINT]
    D -- no --> E{canPerformActions?}
    E -- no --> RET2[return MSG_INVALID]
    E -- yes --> F{isInWaypointMode?}
    F -- yes --> G[handleWaypointModeCommand]
    G --> RET3[return msgType]
    F -- no --> H{command context/SP?}
    H -- yes --> I[normalizeGuiCommandTarget]
    I --> J[switch/issue command]
    H -- no --> K{CONSTRUCT?}
    K -- yes --> L[issue SP construct]
    K -- no --> M[natural action cascade]
    M --> N[issueMoveToLocationCommand]
    J --> RET4[return msgType]
    L --> RET4
    N --> RET4
Loading

Reviews (3): Last reviewed commit: "refactor: move brackets to their own lin..." | Re-trigger Greptile

Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Outdated
@RikuAnt RikuAnt marked this pull request as draft May 15, 2026 12:07
- Refactor context input normalization into separate function
- Refactor GUI command target normalization into separate function
- Refactor waypoint mode command into separate function
- Clarify intent of early returns
@RikuAnt RikuAnt force-pushed the refactor/#1192_Refactor_evaluateContextCommand_phase1 branch from 3712493 to 4fd400f Compare May 15, 2026 12:11
@RikuAnt RikuAnt marked this pull request as ready for review May 15, 2026 12:24
@Skyaero42
Copy link
Copy Markdown

Brackets need to be on their own line.

Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

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

We first need to merge CommandXlat from Generals and Zero Hour because there are a number of differences and it will be easier to make the refactor just once. I have already started that and can try to finish it next days.

return msgType;
}

// TheSuperHackers @refactor RiQQ 15/5/2026 Extracted from evaluateContextCommand monolith. Preparation for proper refactor
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the verbose refactor comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants