Skip to content

NetCommandList::addMessage sorts messages by id using different functions #2795

@Caball009

Description

@Caball009

NetCommandList::addMessage sorts messages chronologically in two different ways, using getID and getSortNumber, but it's not clear why that is.

// Messages that are inserted in order should just be put in one right after the other.
// So saving the placement of the last message inserted can give us a huge boost in
// efficiency.
NetCommandRef *theNext = m_lastMessageInserted->getNext();
if ((m_lastMessageInserted->getCommand()->getNetCommandType() == msg->getCommand()->getNetCommandType()) &&
(m_lastMessageInserted->getCommand()->getPlayerID() == msg->getCommand()->getPlayerID()) &&
(m_lastMessageInserted->getCommand()->getID() < msg->getCommand()->getID()) &&
((theNext == nullptr) || ((theNext->getCommand()->getNetCommandType() > msg->getCommand()->getNetCommandType()) ||
(theNext->getCommand()->getPlayerID() > msg->getCommand()->getPlayerID()) ||
(theNext->getCommand()->getID() > msg->getCommand()->getID())))) {

// Find the position within the player's section based on the command ID.
// If the command type doesn't require a command ID, sort by whatever it should be sorted by.
while ((tempmsg != nullptr) && (msg->getCommand()->getNetCommandType() == tempmsg->getCommand()->getNetCommandType()) && (msg->getCommand()->getPlayerID() == tempmsg->getCommand()->getPlayerID()) && (msg->getCommand()->getSortNumber() > tempmsg->getCommand()->getSortNumber())) {
tempmsg = tempmsg->getNext();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions