refactor(network): Clean up utility functions for network commands#2725
refactor(network): Clean up utility functions for network commands#2725Caball009 wants to merge 7 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp | Refactors five utility functions from if/else chains to switch statements; adds two previously-missing enum values to GetNetCommandTypeAsString; simplifies CommandRequiresAck to delegate to DoesCommandRequireACommandID. All covered enum sets match the originals. |
| Core/GameEngine/Include/GameNetwork/networkutil.h | Adds const qualifiers to CommandRequiresAck and CommandRequiresDirectSend parameters — a straightforward const-correctness improvement with no semantic change. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Caller] --> B{CommandRequiresAck\nconst NetCommandMsg*}
B --> C[DoesCommandRequireACommandID\nNetCommandType]
A --> D{CommandRequiresDirectSend\nconst NetCommandMsg*}
A --> E{IsCommandSynchronized\nNetCommandType}
A --> F{GetNetCommandTypeAsString\nNetCommandType}
C --> G{switch on type}
G -->|GAMECOMMAND, FRAMEINFO,\nPLAYERLEAVE, RUNAHEAD*,\nDESTROYPLAYER, CHAT,\nLOADCOMPLETE, TIMEOUTSTART,\nWRAPPER, FILE*, FRAMERESENDREQUEST,\nDISCONNECT*| H[return TRUE]
G -->|default| I[return FALSE]
D --> J{switch on type}
J -->|LOADCOMPLETE, TIMEOUTSTART,\nFILE*, FRAMERESENDREQUEST,\nDISCONNECTPLAYER, DISCONNECTVOTE,\nDISCONNECTFRAME, DISCONNECTSCREENOFF| K[return TRUE]
J -->|default| L[return FALSE]
E --> M{switch on type}
M -->|FRAMEINFO, GAMECOMMAND,\nPLAYERLEAVE, RUNAHEAD,\nDESTROYPLAYER| N[return TRUE]
M -->|default| O[return FALSE]
F --> P{switch on type}
P -->|NETCOMMANDTYPE_UNKNOWN| Q[return string name]
P -->|default| R[DEBUG_CRASH +\nreturn invalid string]
P -->|all other known types| S[return string name via CASE_LABEL]
Reviews (5): Last reviewed commit: "Changed default / unknown case for 'GetN..." | Re-trigger Greptile
4d28261 to
4d43c80
Compare
| switch (type) { | ||
| default: return "NETCOMMANDTYPE_UNKNOWN"; | ||
| CASE_LABEL(NETCOMMANDTYPE_UNKNOWN) | ||
| default: |
There was a problem hiding this comment.
Can you move this to the very end? Then it is consistent with the other switch cases.
This PR cleans up some utility functions in the network code, mainly by refactoring them from if/else chains to switch statements. No change should have a functional difference.
See commits for cleaner (per function) diffs.