Skip to content

Commit 367b3cd

Browse files
committed
refactor(network): further simplify allConnectionsDone() logic
Use bitwise AND to detect odd/even numbers and calculate required rounds more concisely.
1 parent c3aee33 commit 367b3cd

File tree

2 files changed

+8
-18
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameNetwork
  • Generals/Code/GameEngine/Source/GameNetwork

2 files changed

+8
-18
lines changed

Generals/Code/GameEngine/Source/GameNetwork/NAT.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,11 @@ void NAT::processManglerResponse(UnsignedShort mangledPort) {
907907
// check to see if we've completed all the rounds
908908
// this is kind of a cheesy way to check, but it works.
909909
Bool NAT::allConnectionsDone() {
910-
if ((m_numNodes == 2 && m_connectionRound >= 1) ||
911-
(m_numNodes == 3 && m_connectionRound >= 3) ||
912-
(m_numNodes == 4 && m_connectionRound >= 3) ||
913-
(m_numNodes == 5 && m_connectionRound >= 5) ||
914-
(m_numNodes == 6 && m_connectionRound >= 5) ||
915-
(m_numNodes == 7 && m_connectionRound >= 7) ||
916-
(m_numNodes == 8 && m_connectionRound >= 7)) {
917-
return TRUE;
910+
if (m_numNodes < 2) {
911+
return FALSE;
918912
}
919-
return FALSE;
913+
const Int requiredRounds = (m_numNodes & 1) ? m_numNodes : m_numNodes - 1;
914+
return m_connectionRound >= requiredRounds;
920915
}
921916

922917
Bool NAT::allConnectionsDoneThisRound() {

GeneralsMD/Code/GameEngine/Source/GameNetwork/NAT.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,11 @@ void NAT::processManglerResponse(UnsignedShort mangledPort) {
907907
// check to see if we've completed all the rounds
908908
// this is kind of a cheesy way to check, but it works.
909909
Bool NAT::allConnectionsDone() {
910-
if ((m_numNodes == 2 && m_connectionRound >= 1) ||
911-
(m_numNodes == 3 && m_connectionRound >= 3) ||
912-
(m_numNodes == 4 && m_connectionRound >= 3) ||
913-
(m_numNodes == 5 && m_connectionRound >= 5) ||
914-
(m_numNodes == 6 && m_connectionRound >= 5) ||
915-
(m_numNodes == 7 && m_connectionRound >= 7) ||
916-
(m_numNodes == 8 && m_connectionRound >= 7)) {
917-
return TRUE;
910+
if (m_numNodes < 2) {
911+
return FALSE;
918912
}
919-
return FALSE;
913+
const Int requiredRounds = (m_numNodes & 1) ? m_numNodes : m_numNodes - 1;
914+
return m_connectionRound >= requiredRounds;
920915
}
921916

922917
Bool NAT::allConnectionsDoneThisRound() {

0 commit comments

Comments
 (0)