Skip to content

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

Open
xezon wants to merge 7 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 7 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 extracts all switch case bodies from GameLogic::logicMessageDispatcher into dedicated on* member functions, each receiving only the parameters they require (primarily GameMessage *msg and optionally AIGroupPtr &currentlySelectedGroup). A shared getMessagePlayer helper is added to centralise player lookup.

  • GameLogicDispatch.cpp loses ~1 600 lines of inline case logic and gains an equivalent set of named on* functions, with breakreturn false/true conversions that are semantically equivalent because callers still break out of the switch.
  • Both Generals and GeneralsMD GameLogic.h headers gain the full set of on* declarations, the ALLOW_SURRENDER guarded trio, and the moved #include "GameLogic/AI.h" (removed from the .cpp).

Confidence Score: 5/5

Pure mechanical extraction of switch-case bodies into named member functions; all control-flow paths, ownership guards, and conditional compilation blocks are faithfully reproduced.

Every previously identified concern has been resolved: getMessagePlayer(msg) is called inside each function that needs msgPlayer, the ALLOW_SURRENDER trio correctly takes AIGroupPtr &currentlySelectedGroup, both headers carry the matching guarded declarations, and the onLogicCrc slot-finding loop still uses break with the subsequent return false correctly substituting for the original switch-level break. No new logic changes were introduced.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp ~1600-line refactor extracting all switch-case bodies into named on* member functions; all player-ownership guards, msgPlayer lookups via getMessagePlayer, AIGroupPtr parameters, and ALLOW_SURRENDER guards are correctly reproduced.
Generals/Code/GameEngine/Include/GameLogic/GameLogic.h Adds the full on* declaration block matching the implementations, including properly guarded ALLOW_SURRENDER and debug-only declarations; adds #include "GameLogic/AI.h" for AIGroupPtr.
GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h Mirror of the Generals header change; declaration set and preprocessor guards are consistent with the implementations.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant logicMessageDispatcher
    participant on_Handler as on*() handler
    participant AIGroup
    participant TheNetwork

    Caller->>logicMessageDispatcher: msg, userData
    logicMessageDispatcher->>logicMessageDispatcher: getMessagePlayer(msg)
    logicMessageDispatcher->>logicMessageDispatcher: switch(msgType)
    logicMessageDispatcher->>on_Handler: onXxx(msg [, currentlySelectedGroup])
    alt needs player
        on_Handler->>on_Handler: getMessagePlayer(msg)
    end
    alt needs AI group
        on_Handler->>AIGroup: groupXxx(...)
    end
    alt MSG_LOGIC_CRC
        on_Handler->>TheNetwork: getPlayerName / isPlayerConnected
        on_Handler-->>logicMessageDispatcher: false (disconnected) or true (CRC written)
    end
    on_Handler-->>logicMessageDispatcher: bool result (unused)
    logicMessageDispatcher->>logicMessageDispatcher: break (exits switch)
    logicMessageDispatcher-->>Caller: (cleanup continues)
Loading

Reviews (4): Last reviewed commit: "Fix compile error" | 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 thread Generals/Code/GameEngine/Include/GameLogic/GameLogic.h
@Caball009
Copy link
Copy Markdown

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

@xezon
Copy link
Copy Markdown
Author

xezon commented May 13, 2026

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?

@xezon xezon force-pushed the xezon/refactor-gamelogicdispatch branch from 91c7c5d to 5d14b30 Compare May 13, 2026 19:41
@Caball009
Copy link
Copy Markdown

I don't have a strong opinion on it either way, but I lean toward removing them to make the function shorter.

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