-
Notifications
You must be signed in to change notification settings - Fork 134
refactor(network): replace manual size calculations with packed structs #1675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(network): replace manual size calculations with packed structs #1675
Conversation
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot compile this branch. There are 700 linker errors.
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
|
You can still do this for the messages that are variable in length, just make the fixed portion of the message a struct. |
dbb01a8 to
9d9e804
Compare
9d9e804 to
db5c043
Compare
GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
|
|
||
| ++msglen; // the NetPacketFieldTypes::Data | ||
| msglen += sizeof(UnsignedByte); // string msglength | ||
| UnsignedByte textmsglen = cmdMsg->getText().getLength(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: This truncates 4 bytes to 1 byte 👀
GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
34ab595 to
ba6335d
Compare
960e7a4 to
ad27a6c
Compare
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
586fafb to
07b592f
Compare
GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Include/GameNetwork/NetPacketStructs.h
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very promising.
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameNetwork/NetCommandMsg.cpp
Outdated
Show resolved
Hide resolved
| // Frame Info Command Packet | ||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| struct NetPacketFrameCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it perhaps make sense to put these packed structs into the non packed message classes?
Such as:
class NetGameCommandMsg : public NetCommandMsg
{
...
public:
#pragma pack(push, 1)
struct Packed
{
...
};
#pragma pack(pop)
...
};This way they would sit together and would perhaps be easier to maintain? Not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we could do that, we'd get to use return sizeof(Packed) instead of return sizeof(NetPacketGameCommand), and we could remove some imports, and it keeps the related code together visually. On the other hand, the packed structs are really about network serialization, not about the message logic. Are there places where we only want to import one vs both? Any file that includes NetCommandMsg.h would now also pull in all the packed struct definitions. Whatever you think is best
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move in later changes when more refactor work is done and we have a clearer picture. Right now seems to be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean later in another PR or now in this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future Pull.
|
@xezon any changes you want still? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you push all changes? (Some Review Comments were closed without response or action)
I just pushed the latest. I tried to only resolve comments if I addressed them in a commit. |
|
For example you marked resolved the virtual function comment without action. Or the obsolete CppMacros.h comment without action. So I wonder what was the resolution for it. Edit: I see the edits now. Strangely GitHub did not show the changes before. I will look over tomorrow. |
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good. Needs replication in Generals.
I just pushed the replication commit. Note, I just copied NetCommandMsg and NetPacket.cpp and corrected comments that mentioned Zero Hour. |
|
Copying files from ZH to Generals is risky, unless they are identical. Better use script to replicate: Batch: |
Ah ok. 118 rejected hunks. I'll try going through them like it's a merge conflict. |
…mand pattern Reorganize getPackedByteCount() functions to their respective class sections for better code organization
… switch statement
…classes - Add NetLoadCompleteCommandMsg and NetTimeOutGameStartCommandMsg classes - Update ConnectionManager.cpp to use specific classes instead of base NetCommandMsg - Remove special case handling from NetPacket.cpp since all types now have classes - Eliminate the switch statement entirely - now just calls virtual function
nit: Clean up tabs from empty lines nit: clean up import nit: add comments, split line for readability nit: clean up comments
refactor(network): move NetPacketStructs to Core
…ndMsg and NetTimeOutGameStartCommandMsg
…nd isRoomForTimeOutGameStartMessage size calculations
…age serialization
…ndRequest serialization
…rameResendRequest to include Frame field
…teMessage and isRoomForTimeOutGameStartMessage
b52ea4a to
275e85e
Compare
I tested all but the following: |
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sizes of PacketRouterAckCommand, PacketRouterQueryCommand are correct.
| inline UnsignedInt getPlayerID() const { return m_playerID; } | ||
| inline UnsignedShort getID() const { return m_id; } | ||
| inline void setNetCommandType(NetCommandType type) { m_commandType = type; } | ||
| inline NetCommandType getNetCommandType() { return m_commandType; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove inline again
…d additions, and conditional type check
Created NetPacketStructs.h with packed struct definitions for network packets
Refactored 27 getPackedByteCount() functions to use packed structs: 22 use pure sizeof(struct) calls, 5 use sizeof(struct) as a base for additional calculations.