refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | All switch cases extracted into dedicated on* member functions; logic preserved; getMessagePlayer helper introduced; include AI.h correctly removed (moved to headers). No behavioral differences found. |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | New on* method declarations added with correct signatures; include AI.h added for AIGroupPtr; ALLOW_SURRENDER overloads include the AIGroupPtr currentlySelectedGroup parameter, matching the implementation. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Identical set of on* declarations as the Generals header; signatures match the implementation including ALLOW_SURRENDER overloads. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[logicMessageDispatcher] --> B{switch msgType}
B -->|MSG_NEW_GAME| C[onNewGame]
B -->|MSG_CLEAR_GAME_DATA| D[onClearGameData]
B -->|MSG_SET_RALLY_POINT| E[onSetRallyPoint]
B -->|MSG_DO_SPECIAL_POWER| F[onDoSpecialPower variants]
B -->|MSG_LOGIC_CRC| H[onLogicCrc]
B -->|MSG_EXIT| I[onExit]
B -->|other cases| J[on* handlers]
C --> K[break to post-switch cleanup]
D --> K
E --> K
F --> K
H --> K
I --> K
J --> K
K --> L[AIGroup cleanup and Replay camera sync]
Reviews (5): Last reviewed commit: "Fix compile error" | 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?
| Player *msgPlayer = getMessagePlayer(msg); | ||
|
|
||
| #if RETAIL_COMPATIBLE_CRC | ||
| (void)msgPlayer; |
| { | ||
| Object* obj = findObjectByID( msg->getArgument( 0 )->objectID ); | ||
| if (!obj) | ||
| return false; |
There was a problem hiding this comment.
Indentation; 2 times in this function.
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onEnableRetaliationMode(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| return true; | ||
| } | ||
|
|
||
| bool GameLogic::onInternetHack(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup) |
| 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.
|
|
||
| TheRecorder->handleCRCMessage(newCRC, msgPlayer->getPlayerIndex(), (msg->getArgument(1)->boolean)); | ||
| } | ||
| return true; |
There was a problem hiding this comment.
Empty line before return like all other functions.
This change breaks all switch cases of
GameLogic::logicMessageDispatcherinto separate functions for ease of readability and maintainability.The logic is unchanged.
TODO