Skip to content

Conversation

@bobtista
Copy link

Refactored:

  • Recorder::readArgument(): 11-deep enum dispatch for argument types
  • UDP::GetStatus(): Windows (11-deep) and Unix (12-deep) error code mapping
  • NAT::allConnectionsDone(): 7-deep player count logic

// check to see if we've completed all the rounds
// this is kind of a cheesy way to check, but it works.
Bool NAT::allConnectionsDone() {
if (m_numNodes == 2) {
Copy link

@johnneijzen johnneijzen Oct 10, 2025

Choose a reason for hiding this comment

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

Can't this just be simplified to this, or is there a reason why it was coded this way?

Bool NAT::allConnectionsDone() {
	if ((m_numNodes == 2 && m_connectionRound >= 1) ||
	    (m_numNodes == 3 && m_connectionRound >= 3) ||
	    (m_numNodes == 4 && m_connectionRound >= 3) ||
	    (m_numNodes == 5 && m_connectionRound >= 5) ||
	    (m_numNodes == 6 && m_connectionRound >= 5) ||
	    (m_numNodes == 7 && m_connectionRound >= 7) ||
	    (m_numNodes == 8 && m_connectionRound >= 7)) {
		return TRUE;
	}
	return FALSE;
}

Copy link
Author

Choose a reason for hiding this comment

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

I had the same thought, so yeah I've added your version.

Choose a reason for hiding this comment

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

Could maybe even do something like this:

Bool NAT::allConnectionsDone()
{
	switch (m_numNodes)
	{
		case 2:
			return m_connectionRound >= 1;
		case 3:
			return m_connectionRound >= 3;
		case 4:
			return m_connectionRound >= 3;
		case 5:
			return m_connectionRound >= 5;
		case 6:
			return m_connectionRound >= 5;
		case 7:
			return m_connectionRound >= 7;
		case 8:
			return m_connectionRound >= 7;
		default:
			return FALSE;
	}
}

I'm not sure if VC6 will warn for a missing return statement, but if it does, you can make the default case break and add a return statement outside the switch statement.

Choose a reason for hiding this comment

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

more compact, not sure if it is more performant.

    if (m_numNodes < 2 || m_numNodes > 8) {
        return FALSE;
    }
    
    int requiredRounds = (m_numNodes % 2 == 0) ? m_numNodes - 1 : m_numNodes;
    return m_connectionRound >= requiredRounds;

Copy link

@Caball009 Caball009 Oct 10, 2025

Choose a reason for hiding this comment

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

more compact, not sure if it is more performant.

    if (m_numNodes < 2 || m_numNodes > 8) {
        return FALSE;
    }
    
    int requiredRounds = (m_numNodes % 2 == 0) ? m_numNodes - 1 : m_numNodes;
    return m_connectionRound >= requiredRounds;

This generates better code with modern compilers, not sure about VC6. I'd suggest to make it unsigned, though, to avoid a warning for comparison with unsigned in the return statement.

I don't know if VC6 optimizes % 2 == 1 to & 1, which modern compilers do (for unsigned integers).

Copy link
Author

Choose a reason for hiding this comment

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

I like your first suggestion if ((m_numNodes == 2 && m_connectionRound >= 1) ||....

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.

5 participants