Skip to content

refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702

Open
xezon wants to merge 6 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-gamelogicdispatch
Open

refactor(gamelogic): Break switch cases of GameLogic::logicMessageDispatcher into separate functions#2702
xezon wants to merge 6 commits into
TheSuperHackers:mainfrom
xezon:xezon/refactor-gamelogicdispatch

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented May 12, 2026

This change breaks all switch cases of GameLogic::logicMessageDispatcher into separate functions for ease of readability and maintainability.

The logic is unchanged.

TODO

  • Replicate in Generals

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing labels May 12, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR refactors GameLogic::logicMessageDispatcher by extracting each switch-case handler into its own private member function (e.g. onNewGame, onSetRallyPoint, onLogicCrc), making the 1500-line switch statement significantly easier to read and maintain.

  • ~55 new handler functions are added to the shared GameLogicDispatch.cpp and declared in both Generals/GameLogic.h and GeneralsMD/GameLogic.h; AI.h is moved from the .cpp include to both headers to support the AIGroupPtr parameter type.
  • The Generals/GameLogic.h #ifdef ALLOW_SURRENDER block declares onDoSurrender, onPickUpPrisoner, and onReturnToPrison without the AIGroupPtr &currentlySelectedGroup parameter that both the implementations and the GeneralsMD header include, which would be a compile error if ALLOW_SURRENDER is defined in a Generals build.

Confidence Score: 4/5

Safe to merge for GeneralsMD builds; the Generals header has a signature mismatch for ALLOW_SURRENDER functions that would break compilation if that macro is enabled.

The vast majority of the refactor is a clean mechanical extraction with correct logic preservation. The Generals header declares the three ALLOW_SURRENDER handler methods without the AIGroupPtr parameter that the implementations and GeneralsMD header include — a definition/declaration mismatch that would cause a compile error if ALLOW_SURRENDER is enabled for a Generals build.

Generals/Code/GameEngine/Include/GameLogic/GameLogic.h — the ALLOW_SURRENDER section at lines 344-348 needs the AIGroupPtr parameter added to match the implementation and the GeneralsMD counterpart.

Important Files Changed

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]
Loading
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 &currentlySelectedGroup` 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 &currentlySelectedGroup);
	bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
	bool onReturnToPrison(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
#endif
```

Reviews (3): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile

@xezon
Copy link
Copy Markdown
Author

xezon commented May 12, 2026

Generals fails to compile until replicated.

Comment thread Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Comment thread Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Comment thread Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
Comment on lines +344 to +348
#ifdef ALLOW_SURRENDER
bool onDoSurrender(GameMessage *msg);
bool onPickUpPrisoner(GameMessage *msg);
bool onReturnToPrison(GameMessage *msg);
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The three ALLOW_SURRENDER method declarations are missing the AIGroupPtr &currentlySelectedGroup 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.

Suggested change
#ifdef ALLOW_SURRENDER
bool onDoSurrender(GameMessage *msg);
bool onPickUpPrisoner(GameMessage *msg);
bool onReturnToPrison(GameMessage *msg);
#endif
#ifdef ALLOW_SURRENDER
bool onDoSurrender(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
bool onReturnToPrison(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
#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 &currentlySelectedGroup` 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 &currentlySelectedGroup);
	bool onPickUpPrisoner(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
	bool onReturnToPrison(GameMessage *msg, AIGroupPtr &currentlySelectedGroup);
#endif
```

How can I resolve this? If you propose a fix, please make it concise.

@Caball009
Copy link
Copy Markdown

Do we need the braces per case? It makes the function a lot longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants