refactor(gamelogic): Split switch cases of GameLogic::logicMessageDispatcher into separate functions#2702
refactor(gamelogic): Split switch cases of GameLogic::logicMessageDispatcher into separate functions#2702xezon wants to merge 11 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp | Large refactor: switch cases replaced with on*() calls; all handler implementations appended at end of file. break→return false conversions and msgPlayer/currentlySelectedGroup parameter threading are all correct in this revision. |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds private on*() declarations and moves #include "GameLogic/AI.h" here to satisfy AIGroupPtr parameters. ALLOW_SURRENDER signatures correctly carry the AIGroupPtr & parameter. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Mirror of the Generals header change — identical on*() declarations and AI.h include added. |
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 / onDoSpecialPowerAtLocation / onDoSpecialPowerAtObject / onDoSpecialPowerOverrideDestination]
B -->|Movement msgs| G[onDoMoveto / onDoAttackmoveto / onAddWaypoint / ...]
B -->|Production msgs| H[onQueueUnitCreate / onCancelUnitCreate / onDozerConstruct / ...]
B -->|MSG_LOGIC_CRC| I[onLogicCrc]
B -->|ALLOW_SURRENDER msgs| J[onDoSurrender / onPickUpPrisoner / onReturnToPrison]
B -->|...more cases| K[30+ more on* functions]
I -->|slotIndex found and connected| L[m_shouldValidateCRCs = TRUE / m_cachedCRCs update]
I -->|slot not found or disconnected| M[return false]
I -->|playback mode| N[TheRecorder handleCRCMessage]
Reviews (7): Last reviewed commit: "Add MAYBE_UNUSED to GameMessage args" | 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. |
5d14b30 to
883093b
Compare
|
Rebased without conflicts. |
| 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 |
They ought to be marked as unused, though, otherwise this PR is going to add a bunch of new warnings for it. |
I think unused function arguments trigger no warning. I did a recompile in VS2022 and there is no warning for this file. |
|
Perhaps it only shows up when compiling with clang-cl and / or using clang-tidy. Edit: |
|
Do we care for this? I don't mind unused function arguments. Just disable the warning for that particular aspect. |
|
Disabling a warning should be the last resort. |
|
Yes but what is this warning good for? What problem does it solve? The problem with removing unused function argument names is that they will need to be added again when they are needed anyway. void doStuff(float value, const char* name);
void doStuff(int value, const char*); // const char* unused-> void doStuff(float value, const char* name);
void doStuff(int value, const char* myNewCustomName); // Now argument name is
// added but different from the other because we did not pay attention when we added itWhy is not ok? void doStuff(float value, const char* name);
void doStuff(int value, const char* name); // const char* unused |
I'm not arguing in favor of removing them. I can see the merit of having uniform arguments for all those functions. Unused variables are unexpected and could indicate an issue (typo or badly refactored code or whatever), though. I'm arguing in favor marking them as ununsed with |
|
Oh ok. I actually was not aware this is possible to set on function arguments. I will try. |
…patcher into separate functions
3539719 to
19df18e
Compare
|
MAYBE_UNUSED added to function arguments. |
This change breaks all switch cases of
GameLogic::logicMessageDispatcherinto separate functions for ease of readability and maintainability.The logic is unchanged.
TODO