Skip to content

bugfix(network): Sort command list fast path by sort number - #3052

Open
CryoTheRenegade wants to merge 5 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:bugfix/netcommandlist-sort-number
Open

bugfix(network): Sort command list fast path by sort number#3052
CryoTheRenegade wants to merge 5 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:bugfix/netcommandlist-sort-number

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Aug 2, 2026

Copy link
Copy Markdown

Changed the cached NetCommandList::addMessage insertion path to use getSortNumber(), matching the full list traversal.

For normal commands this is equivalent to getID(). ACK commands override it with the ID of the command being acknowledged, so using it consistently prevents incorrect ACK ordering.

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting to look better, but still a few points of attention and some formatting

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated

static bool isCommandOrderedAfter(const NetCommandMsg *candidate, const NetCommandMsg *reference)
{
if (candidate->getNetCommandType() != reference->getNetCommandType()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. if candidate->getNetCommandType() < reference->getNetCommandType() it is not supposed to return false, but to move to the next if statement.

I think it should be

if (candidate->getNetCommandType() > reference->getNetCommandType())
{
  return true;
}

if (candidate->getPlayerID() > reference->getPlayerID())
{
  return true;
}

return isCommandIdNewer(candidate->getsortNumber(), msg->reference->getsortNumber());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lexicographic: type → player → sort number. A lower type must return false; otherwise (type=1, player=7) could incorrectly sort after (type=2, player=0).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a second opinion on this from someone else. You may be correct, but its very different from the original if-statement as well as your original fix (which only replaced id with sortednumber)

@Caball009

Caball009 commented Aug 3, 2026

Copy link
Copy Markdown

I'm a bit concerned this may affect retail compatibility. Please test this change in a multiplayer match. You can use two local instances, one with the change and one without.

@CryoTheRenegade

Copy link
Copy Markdown
Author

I'm a bit concerned this may affect retail compatibility. Please test this change in a multiplayer match. You can use two local instances, one with the change and one without.

Tested with latest weekly as control, no issues seen (had 2 instances of tracy in the background and nothing weird happened, but im not very good at playing against myself so i didnt stress it out too much :/)

@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch from 4c4ac92 to 727de6a Compare August 4, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetCommandList::addMessage sorts messages by id using different functions

3 participants