refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702
refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702xezon wants to merge 10 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | ~1600 lines of switch-case body moved into ~50 extracted member functions; logic is faithful to the original. Previously flagged issues (missing msgPlayer, missing currentlySelectedGroup param in ALLOW_SURRENDER functions, onLogicCrc early-exit) are all resolved. The static getMessagePlayer helper is correctly used. |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds declarations for all extracted on* methods including the three ALLOW_SURRENDER functions with the correct AIGroupPtr& parameter; adds #include "GameLogic/AI.h" required for AIGroupPtr. Matches the GeneralsMD header. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Mirrors the Generals header: adds declarations for all extracted on* methods with correct signatures and adds #include "GameLogic/AI.h". Unchanged from the correct version used as the reference in the prior review. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["logicMessageDispatcher(msg)"] --> B["getMessagePlayer(msg)\nvalidate msgPlayer != null"]
B --> C["AIGroup selection setup"]
C --> D["switch(msgType)"]
D --> E1["MSG_NEW_GAME → onNewGame(msg)"]
D --> E2["MSG_CLEAR_GAME_DATA → onClearGameData(msg, grp)"]
D --> E3["MSG_SET_RALLY_POINT → onSetRallyPoint(msg)"]
D --> E4["MSG_DO_SPECIAL_POWER → onDoSpecialPower(msg, grp)"]
D --> E5["MSG_DO_SPECIAL_POWER_AT_LOCATION → onDoSpecialPowerAtLocation(msg, grp)"]
D --> E6["MSG_DO_SPECIAL_POWER_AT_OBJECT → onDoSpecialPowerAtObject(msg, grp)"]
D --> E7["MSG_DO_SPECIAL_POWER_OVERRIDE_DESTINATION → onDoSpecialPowerOverrideDestination(msg, grp)"]
D --> E8["MSG_ENTER / MSG_EXIT → onEnter / onExit(msg, grp)"]
D --> E9["MSG_LOGIC_CRC → onLogicCrc(msg)"]
D --> E10["MSG_DOZER_CONSTRUCT → onDozerConstruct(msg, grp)"]
D --> E11["~40 more cases..."]
E1 --> F["return bool\n(ignored at call site)"]
E9 --> F
F --> G["Post-switch:\nRETAIL_COMPATIBLE_AIGROUP\ngroup cleanup"]
Reviews (6): Last reviewed commit: "Fix line spacing" | Re-trigger Greptile
|
Generals fails to compile until replicated. |
|
Do we need the braces per case? It makes the function a lot longer. |
Is not strictly necessary. Braces are only needed if a variable needs declaration in the top switch case scope. Do you want it removed? |
91c7c5d to
5d14b30
Compare
|
I don't have a strong opinion on it either way, but I lean toward removing them to make the function shorter. |
|
Needs rebase. |
…patcher into separate functions
5d14b30 to
883093b
Compare
|
Rebased without conflicts. |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onDoWeapon(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
There was a problem hiding this comment.
Why is currentlySelectedGroup passed as AIGroup*& everywhere?
There was a problem hiding this comment.
Because some of them do actually release the AI group and set the pointer to null. To keep the code simple, I passed it as reference to all of them. It reduces the likelyhood of mistakes this way, because we then do not need to verify that all the correct functions get it as reference.
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onInternetHack(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
There was a problem hiding this comment.
Ok but that is fine. We can keep msg anyway to keep it consistent with all the others. Plus there is a commented code line that uses msg.
Many times in this class.
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onDoCheer(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onEvacuate(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onExecuteRailedTransport(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onToggleOvercharge(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onReturnToPrison(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
There was a problem hiding this comment.
Incomplete review.
- There's a bunch of unused function parameters. Could remove or mark with
MAYBE_UNUSED. Player *msgPlayer = getMessagePlayer(msg)can be madeconstin some functions.currentlySelectedGroupcan be passed by pointer instead of pointer ref, I think.
| case GameMessage::MSG_SELECTED_GROUP_COMMAND: | ||
| { | ||
|
|
||
| break; | ||
|
|
||
| } |
There was a problem hiding this comment.
This case could be removed technically.
There was a problem hiding this comment.
I will keep it because the original had it too.
I would like to keep passing all the message pointers because it is the common expectation that the message data is needed to properly act on a message - when it has message arguments.
I checked and would like to keep it as is, because some functions do use it in const context but the constness is not consistently applied to all getter methods across the code base. I think that would need a polishing pass first.
I looked over it one more time and it strictly needs passing as reference only to |
This change breaks all switch cases of
GameLogic::logicMessageDispatcherinto separate functions for ease of readability and maintainability.The logic is unchanged.
TODO