refactor(commandxlat): Split evaluateContextCommand into per-command handlers#3008
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/GameClient/CommandXlat.h | Declares the private helper methods used to decompose context-command evaluation. |
| Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp | Extracts the existing target normalization and ordered command-dispatch logic into helpers while preserving branch order and outcomes. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[evaluateContextCommand] --> B[Resolve context target]
B --> C{Selection or action guard exits?}
C -->|Yes| D[Return message type]
C -->|No| E{Waypoint mode?}
E -->|Yes| F[Handle waypoint command]
E -->|No| G{GUI command active?}
G -->|Yes| H[Normalize GUI target and dispatch]
G -->|No| I[Evaluate ordered context actions]
I --> J[Delegate to matching helper]
I --> K[Handle default movement]
F --> D
H --> D
J --> D
K --> D
Reviews (2): Last reviewed commit: "refactor(commandxlat): Split evaluateCon..." | Re-trigger Greptile
xezon
left a comment
There was a problem hiding this comment.
I think this refactor does not go far enough. Function can be split into many small handle functions.
| GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw, | ||
| const Coord3D *pos, | ||
| CommandEvaluateType type ) | ||
| void CommandTranslator::normalizeContextInputs(Drawable*& draw, Object*& obj, Drawable*& drawableInWay) |
There was a problem hiding this comment.
Is normalizeContextInputs a fitting name for this?
There was a problem hiding this comment.
no, renamed to resolveContextTarget. Same for normalizeGuiCommandTarget while I'm at it.
Agreed. I took another pass and split evaluateContextCommand into 21 per-command handlers, plus separate target-resolution, GUI-command, waypoint, and default-move helpers. The main function is now only the ordered dispatch chain, with its behavior and branch order preserved. |
Replaces #2714 by @RikuAnt (tracking #1192), rebased onto current main.
evaluateContextCommandwas ~830 lines. This splits it into per-command handlers, leaving the function as the dispatch chain alone (~180 lines), with no change to behavior:resolveContextTarget/resolveGuiCommandTarget— null out draw/obj so evaluation falls back to a position interaction (masked, mine, force-move/attack; shrubbery/mine/relationship filtering).handleXCommandhelpers — one per arm of the else-if chain.Since #2765 (merge ZH CommandXlat) and #2805 (move CommandXlat to Core), this lives in
Core/, which is what #2714 was blocked on.Notes
handleAttackObjectCommandtakes the hint type (ATTACKRESULT_POSSIBLE/ATTACKRESULT_POSSIBLE_AFTER_MOVING), andhandleHackCommandtakes the special power (disable vehicle / steal cash / disable building).handleSetRallyPointCommandandhandleImpossibleAttackHintdrop a deadmsgType = MSG_INVALIDthat was immediately overwritten.resultassignment stays inside theATTACKRESULT_POSSIBLEcondition — two later arms read it, so hoisting it into a helper would have changed behavior.