Skip to content

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

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

refactor: Refactor evaluateContextCommand phase 1 (#1192)#2714
RikuAnt wants to merge 2 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 focused helpers from the evaluateContextCommand monolith — normalizeContextInputs, handleWaypointModeCommand, and normalizeGuiCommandTarget — and restructures the dispatch logic in evaluateContextCommand to use explicit early returns and a canPerformActions guard. All previously-reported issues (missing normalizeGuiCommandTarget call, waypoint fallthrough, null-pointer deref on command, and orphaned else if chain) appear resolved in the current state.

  • Three private methods extracted and declared in the header; normalizeGuiCommandTarget is now correctly called inside the if(command && isContextCommand() || ...) block at line 1700.
  • handleWaypointModeCommand is now unconditionally returned from the waypoint branch, and evaluateContextCommand uses explicit return MSG_INVALID early exits in place of the old nested else if for controllability.
  • Minor style inconsistencies remain: bool used instead of the codebase's Bool typedef for canPerformActions, and the normalizeGuiCommandTarget call site has space-based indentation where tabs are expected.

Confidence Score: 4/5

Safe to merge after a quick scan of the two style nits; the functional logic is correct and all previously-flagged regressions are resolved.

All previously flagged functional regressions are resolved: normalizeGuiCommandTarget is called, the waypoint branch always returns, command is guarded before the switch, and the else-if chain is correctly attached inside the bare block. The only remaining findings are cosmetic (Bool/bool mismatch and one mis-indented call site).

GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp — verify the bool/Bool inconsistency and the indentation on the normalizeGuiCommandTarget call.

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp Three new private methods extracted from evaluateContextCommand (normalizeContextInputs, handleWaypointModeCommand, normalizeGuiCommandTarget); all previously-reported missing-call and orphaned-else-if issues appear resolved; minor bool/Bool style inconsistency introduced.
GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h Three new private method declarations added; uses #pragma once correctly; no issues found.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[evaluateContextCommand] --> B[normalizeContextInputs]
    B --> C{prefer selection mode?}
    C -->|yes| D[return MSG_INVALID]
    C -->|no| E{PLACE_BEACON command?}
    E -->|yes| F[return MSG_VALID_GUICOMMAND_HINT]
    E -->|no| G{canPerformActions?}
    G -->|no| H[return MSG_INVALID]
    G -->|yes| I{isInWaypointMode?}
    I -->|yes| J[handleWaypointModeCommand - return]
    I -->|no| K{command and isContextCommand or SPECIAL_POWER?}
    K -->|yes| L[normalizeGuiCommandTarget]
    L --> M[switch on command type - build hint or issue command]
    K -->|no| N[else-if CONSTRUCT branches]
    N --> O[else-if action branches - attack, repair, dock, enter, etc.]
    O --> P[else - issueMoveToLocation]
    M --> R[return msgType]
    P --> R
Loading
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp:1679-1682
The surrounding codebase uses the `Bool` typedef throughout (see `Bool currentlyValid = FALSE;` just below), but `canPerformActions` is declared with the built-in `bool`. Prefer `Bool` here for consistency.

```suggestion
	const Bool canPerformActions = (
		TheInGameUI->areSelectedObjectsControllable() || 
		(command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)
	);
```

### Issue 2 of 2
GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp:1700
The `normalizeGuiCommandTarget` call is indented with spaces while the rest of the block uses tabs, leaving a visible indentation mismatch. Align with the surrounding tab-indented code.

Reviews (2): Last reviewed commit: "fix: Revert incorrectly changed logic du..." | Re-trigger Greptile

@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.

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.

2 participants