refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702
Conversation
…patcher into separate functions
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Large refactor extracting all switch-case bodies from logicMessageDispatcher into ~55 separate member functions; logic is preserved, msgPlayer declarations are correctly added to all functions that need it, and ALLOW_SURRENDER functions correctly receive AIGroupPtr by reference. |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds 55 new private method declarations; the ALLOW_SURRENDER trio (onDoSurrender, onPickUpPrisoner, onReturnToPrison) is missing the AIGroupPtr parameter present in both the implementation and the GeneralsMD counterpart, causing a definition/declaration mismatch. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds the same 55 private method declarations as the Generals header, with all signatures matching the implementations correctly. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[logicMessageDispatcher] --> B{switch msgType}
B --> C[onNewGame]
B --> D[onClearGameData]
B --> E[onSetRallyPoint\ngetMessagePlayer]
B --> F[onDoSpecialPower\ngetMessagePlayer]
B --> G[onLogicCrc\ngetMessagePlayer]
B --> H[onExit\ngetMessagePlayer]
B --> I[... ~50 more handlers]
E & F & G & H --> J[getMessagePlayer helper\nThePlayerList-getNthPlayer]
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
Generals/Code/GameEngine/Include/GameLogic/GameLogic.h:344-348
The three `ALLOW_SURRENDER` method declarations are missing the `AIGroupPtr ¤tlySelectedGroup` parameter. The implementations in `GameLogicDispatch.cpp` take that parameter, and the call sites pass it. If `ALLOW_SURRENDER` is ever defined for a Generals build, this signature mismatch will produce a compile error. The `GeneralsMD/GameLogic.h` already has the correct signatures.
```suggestion
#ifdef ALLOW_SURRENDER
bool onDoSurrender(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
bool onReturnToPrison(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
#endif
```
Reviews (3): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile
|
Generals fails to compile until replicated. |
| #ifdef ALLOW_SURRENDER | ||
| bool onDoSurrender(GameMessage *msg); | ||
| bool onPickUpPrisoner(GameMessage *msg); | ||
| bool onReturnToPrison(GameMessage *msg); | ||
| #endif |
There was a problem hiding this comment.
The three
ALLOW_SURRENDER method declarations are missing the AIGroupPtr ¤tlySelectedGroup parameter. The implementations in GameLogicDispatch.cpp take that parameter, and the call sites pass it. If ALLOW_SURRENDER is ever defined for a Generals build, this signature mismatch will produce a compile error. The GeneralsMD/GameLogic.h already has the correct signatures.
| #ifdef ALLOW_SURRENDER | |
| bool onDoSurrender(GameMessage *msg); | |
| bool onPickUpPrisoner(GameMessage *msg); | |
| bool onReturnToPrison(GameMessage *msg); | |
| #endif | |
| #ifdef ALLOW_SURRENDER | |
| bool onDoSurrender(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup); | |
| bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup); | |
| bool onReturnToPrison(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup); | |
| #endif |
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Include/GameLogic/GameLogic.h
Line: 344-348
Comment:
The three `ALLOW_SURRENDER` method declarations are missing the `AIGroupPtr ¤tlySelectedGroup` parameter. The implementations in `GameLogicDispatch.cpp` take that parameter, and the call sites pass it. If `ALLOW_SURRENDER` is ever defined for a Generals build, this signature mismatch will produce a compile error. The `GeneralsMD/GameLogic.h` already has the correct signatures.
```suggestion
#ifdef ALLOW_SURRENDER
bool onDoSurrender(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
bool onReturnToPrison(GameMessage *msg, AIGroupPtr ¤tlySelectedGroup);
#endif
```
How can I resolve this? If you propose a fix, please make it concise.|
Do we need the braces per case? It makes the function a lot longer. |
This change breaks all switch cases of
GameLogic::logicMessageDispatcherinto separate functions for ease of readability and maintainability.The logic is unchanged.
TODO