refactor(metaevent): Split MetaEventTranslator::translateGameMessage() into smaller functions#2758
refactor(metaevent): Split MetaEventTranslator::translateGameMessage() into smaller functions#2758xezon wants to merge 3 commits into
Conversation
…) into smaller functions
|
| Filename | Overview |
|---|---|
| GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h | Adds six private helper method declarations to MetaEventTranslator; correctly placed under a new private: section. |
| GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp | Implements the six new helper methods extracted from translateGameMessage(). Logic is semantically equivalent to the original; the refactoring improves cohesion without introducing new behavioral changes. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["translateGameMessage(msg)"] --> B{msg type?}
B -->|RAW_KEY_DOWN / RAW_KEY_UP| C["onKeyEvent(msg, disp)"]
B -->|RAW_MOUSE_*| D["onMouseEvent(msg)"]
B -->|other| E[return KEEP_MESSAGE]
C --> F["getActionKeyType(systemKey) → MappableKeyType"]
C --> G["getKeyModState(systemKeyState) → MappableKeyModState"]
C --> H{keyType == MK_NONE AND RAW_KEY_UP?}
H -->|yes – modifier released| I["onKeyModStateRemoved(disp, keyModState)"]
H -->|no – normal key event| J["onKeyPressed(disp, systemKeyState, keyType, keyModState)"]
D --> K{Mouse message type}
K -->|BUTTON_DOWN| L[Record mouseDownPosition]
K -->|DOUBLE_CLICK| M[Set doubleClick flag]
K -->|BUTTON_UP| N[Insert CLICK or DOUBLE_CLICK into stream]
Reviews (3): Last reviewed commit: "Refactor long conditions" | Re-trigger Greptile
RikuAnt
left a comment
There was a problem hiding this comment.
Logically sound change. The focus is clearly to just relocate the code into new helper methods, but I would recommend some minor refactors as well.
| ) | ||
| ) | ||
| { | ||
| if( systemKeyState & KEY_STATE_AUTOREPEAT ) |
There was a problem hiding this comment.
Extract condition and invert to eliminate unnecessary code block
const bool isAutorepeat = (systemKeyState & KEY_STATE_AUTOREPEAT) != 0;
if ( !isAutorepeat ) ...
There was a problem hiding this comment.
It is a reasonable suggestions but I will leave it as is in this particular refactor because there is a reasoned comment and commented code in this branch.
There was a problem hiding this comment.
The comment could be moved before the inverted test to explain the autorepeat case. Also I would argue whether debug log is worthy commented code or not.
In any case, these are minor remarks so I'm fine if the code remains as is.
| //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() normal: %s", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta))); | ||
| } | ||
| if (!(map->m_key == keyDown && map->m_modState == keyDownModState && map->m_transition == UP)) | ||
| continue; |
There was a problem hiding this comment.
Consider extracting this condition into a local variable (for example, "isMatchingKeyUp") to improve readability.
| if (map->m_key == keyType && | ||
| map->m_modState == keyModState && ( | ||
| (map->m_transition == UP && (systemKeyState & KEY_STATE_UP)) | ||
| || (map->m_transition == DOWN && (systemKeyState & KEY_STATE_DOWN)) |
There was a problem hiding this comment.
Consider extracting this condition into a local variable (for example, "isMatchingKeyPressReleaseEdge") to improve readability.
|
I don't have permission to resolve my own comments, so feel free to resolve them. Applies also for approval, so someone elses blessing is needed here. FYI @xezon |
This change splits
MetaEventTranslator::translateGameMessage()into smaller functions for better maintainability.Logically it should function the same.
TODO