Skip to content

Commit 4661df4

Browse files
committed
refactor: convert if-else chains to switch statements in Generals
1 parent 69866e7 commit 4661df4

File tree

3 files changed

+217
-142
lines changed

3 files changed

+217
-142
lines changed

Generals/Code/GameEngine/Source/Common/Recorder.cpp

Lines changed: 125 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,117 +1445,153 @@ void RecorderClass::appendNextCommand() {
14451445
}
14461446

14471447
void RecorderClass::readArgument(GameMessageArgumentDataType type, GameMessage *msg) {
1448-
if (type == ARGUMENTDATATYPE_INTEGER) {
1449-
Int theint;
1450-
m_file->read(&theint, sizeof(theint));
1451-
msg->appendIntegerArgument(theint);
1448+
switch (type) {
1449+
case ARGUMENTDATATYPE_INTEGER: {
1450+
Int theint;
1451+
m_file->read(&theint, sizeof(theint));
1452+
msg->appendIntegerArgument(theint);
14521453
#ifdef DEBUG_LOGGING
1453-
if (m_doingAnalysis)
1454-
{
1455-
DEBUG_LOG(("Integer argument: %d (%8.8X)", theint, theint));
1456-
}
1454+
if (m_doingAnalysis)
1455+
{
1456+
DEBUG_LOG(("Integer argument: %d (%8.8X)", theint, theint));
1457+
}
14571458
#endif
1458-
} else if (type == ARGUMENTDATATYPE_REAL) {
1459-
Real thereal;
1460-
m_file->read(&thereal, sizeof(thereal));
1461-
msg->appendRealArgument(thereal);
1462-
#ifdef DEBUG_LOGGING
1463-
if (m_doingAnalysis)
1464-
{
1465-
DEBUG_LOG(("Real argument: %g (%8.8X)", thereal, *(int *)&thereal));
1459+
break;
14661460
}
1467-
#endif
1468-
} else if (type == ARGUMENTDATATYPE_BOOLEAN) {
1469-
Bool thebool;
1470-
m_file->read(&thebool, sizeof(thebool));
1471-
msg->appendBooleanArgument(thebool);
1461+
1462+
case ARGUMENTDATATYPE_REAL: {
1463+
Real thereal;
1464+
m_file->read(&thereal, sizeof(thereal));
1465+
msg->appendRealArgument(thereal);
14721466
#ifdef DEBUG_LOGGING
1473-
if (m_doingAnalysis)
1474-
{
1475-
DEBUG_LOG(("Bool argument: %d", thebool));
1476-
}
1467+
if (m_doingAnalysis)
1468+
{
1469+
DEBUG_LOG(("Real argument: %g (%8.8X)", thereal, *(int *)&thereal));
1470+
}
14771471
#endif
1478-
} else if (type == ARGUMENTDATATYPE_OBJECTID) {
1479-
ObjectID theid;
1480-
m_file->read(&theid, sizeof(theid));
1481-
msg->appendObjectIDArgument(theid);
1482-
#ifdef DEBUG_LOGGING
1483-
if (m_doingAnalysis)
1484-
{
1485-
DEBUG_LOG(("Object ID argument: %d", theid));
1472+
break;
14861473
}
1487-
#endif
1488-
} else if (type == ARGUMENTDATATYPE_DRAWABLEID) {
1489-
DrawableID theid;
1490-
m_file->read(&theid, sizeof(theid));
1491-
msg->appendDrawableIDArgument(theid);
1474+
1475+
case ARGUMENTDATATYPE_BOOLEAN: {
1476+
Bool thebool;
1477+
m_file->read(&thebool, sizeof(thebool));
1478+
msg->appendBooleanArgument(thebool);
14921479
#ifdef DEBUG_LOGGING
1493-
if (m_doingAnalysis)
1494-
{
1495-
DEBUG_LOG(("Drawable ID argument: %d", theid));
1496-
}
1480+
if (m_doingAnalysis)
1481+
{
1482+
DEBUG_LOG(("Bool argument: %d", thebool));
1483+
}
14971484
#endif
1498-
} else if (type == ARGUMENTDATATYPE_TEAMID) {
1499-
UnsignedInt theid;
1500-
m_file->read(&theid, sizeof(theid));
1501-
msg->appendTeamIDArgument(theid);
1502-
#ifdef DEBUG_LOGGING
1503-
if (m_doingAnalysis)
1504-
{
1505-
DEBUG_LOG(("Team ID argument: %d", theid));
1485+
break;
15061486
}
1507-
#endif
1508-
} else if (type == ARGUMENTDATATYPE_LOCATION) {
1509-
Coord3D loc;
1510-
m_file->read(&loc, sizeof(loc));
1511-
msg->appendLocationArgument(loc);
1487+
1488+
case ARGUMENTDATATYPE_OBJECTID: {
1489+
ObjectID theid;
1490+
m_file->read(&theid, sizeof(theid));
1491+
msg->appendObjectIDArgument(theid);
15121492
#ifdef DEBUG_LOGGING
1513-
if (m_doingAnalysis)
1514-
{
1515-
DEBUG_LOG(("Coord3D argument: %g %g %g (%8.8X %8.8X %8.8X)", loc.x, loc.y, loc.z,
1516-
*(int *)&loc.x, *(int *)&loc.y, *(int *)&loc.z));
1517-
}
1493+
if (m_doingAnalysis)
1494+
{
1495+
DEBUG_LOG(("Object ID argument: %d", theid));
1496+
}
15181497
#endif
1519-
} else if (type == ARGUMENTDATATYPE_PIXEL) {
1520-
ICoord2D pixel;
1521-
m_file->read(&pixel, sizeof(pixel));
1522-
msg->appendPixelArgument(pixel);
1523-
#ifdef DEBUG_LOGGING
1524-
if (m_doingAnalysis)
1525-
{
1526-
DEBUG_LOG(("Pixel argument: %d,%d", pixel.x, pixel.y));
1498+
break;
15271499
}
1500+
1501+
case ARGUMENTDATATYPE_DRAWABLEID: {
1502+
DrawableID theid;
1503+
m_file->read(&theid, sizeof(theid));
1504+
msg->appendDrawableIDArgument(theid);
1505+
#ifdef DEBUG_LOGGING
1506+
if (m_doingAnalysis)
1507+
{
1508+
DEBUG_LOG(("Drawable ID argument: %d", theid));
1509+
}
15281510
#endif
1529-
} else if (type == ARGUMENTDATATYPE_PIXELREGION) {
1530-
IRegion2D reg;
1531-
m_file->read(&reg, sizeof(reg));
1532-
msg->appendPixelRegionArgument(reg);
1511+
break;
1512+
}
1513+
1514+
case ARGUMENTDATATYPE_TEAMID: {
1515+
UnsignedInt theid;
1516+
m_file->read(&theid, sizeof(theid));
1517+
msg->appendTeamIDArgument(theid);
15331518
#ifdef DEBUG_LOGGING
1534-
if (m_doingAnalysis)
1535-
{
1536-
DEBUG_LOG(("Pixel Region argument: %d,%d -> %d,%d", reg.lo.x, reg.lo.y, reg.hi.x, reg.hi.y));
1519+
if (m_doingAnalysis)
1520+
{
1521+
DEBUG_LOG(("Team ID argument: %d", theid));
1522+
}
1523+
#endif
1524+
break;
15371525
}
1526+
1527+
case ARGUMENTDATATYPE_LOCATION: {
1528+
Coord3D loc;
1529+
m_file->read(&loc, sizeof(loc));
1530+
msg->appendLocationArgument(loc);
1531+
#ifdef DEBUG_LOGGING
1532+
if (m_doingAnalysis)
1533+
{
1534+
DEBUG_LOG(("Coord3D argument: %g %g %g (%8.8X %8.8X %8.8X)", loc.x, loc.y, loc.z,
1535+
*(int *)&loc.x, *(int *)&loc.y, *(int *)&loc.z));
1536+
}
15381537
#endif
1539-
} else if (type == ARGUMENTDATATYPE_TIMESTAMP) { // Not to be confused with Terrance Stamp... Kneel before Zod!!!
1540-
UnsignedInt stamp;
1541-
m_file->read(&stamp, sizeof(stamp));
1542-
msg->appendTimestampArgument(stamp);
1538+
break;
1539+
}
1540+
1541+
case ARGUMENTDATATYPE_PIXEL: {
1542+
ICoord2D pixel;
1543+
m_file->read(&pixel, sizeof(pixel));
1544+
msg->appendPixelArgument(pixel);
15431545
#ifdef DEBUG_LOGGING
1544-
if (m_doingAnalysis)
1545-
{
1546-
DEBUG_LOG(("Timestamp argument: %d", stamp));
1546+
if (m_doingAnalysis)
1547+
{
1548+
DEBUG_LOG(("Pixel argument: %d,%d", pixel.x, pixel.y));
1549+
}
1550+
#endif
1551+
break;
15471552
}
1553+
1554+
case ARGUMENTDATATYPE_PIXELREGION: {
1555+
IRegion2D reg;
1556+
m_file->read(&reg, sizeof(reg));
1557+
msg->appendPixelRegionArgument(reg);
1558+
#ifdef DEBUG_LOGGING
1559+
if (m_doingAnalysis)
1560+
{
1561+
DEBUG_LOG(("Pixel Region argument: %d,%d -> %d,%d", reg.lo.x, reg.lo.y, reg.hi.x, reg.hi.y));
1562+
}
15481563
#endif
1549-
} else if (type == ARGUMENTDATATYPE_WIDECHAR) {
1550-
WideChar theid;
1551-
m_file->read(&theid, sizeof(theid));
1552-
msg->appendWideCharArgument(theid);
1564+
break;
1565+
}
1566+
1567+
case ARGUMENTDATATYPE_TIMESTAMP: { // Not to be confused with Terrance Stamp... Kneel before Zod!!!
1568+
UnsignedInt stamp;
1569+
m_file->read(&stamp, sizeof(stamp));
1570+
msg->appendTimestampArgument(stamp);
15531571
#ifdef DEBUG_LOGGING
1554-
if (m_doingAnalysis)
1555-
{
1556-
DEBUG_LOG(("WideChar argument: %d (%lc)", theid, theid));
1572+
if (m_doingAnalysis)
1573+
{
1574+
DEBUG_LOG(("Timestamp argument: %d", stamp));
1575+
}
1576+
#endif
1577+
break;
15571578
}
1579+
1580+
case ARGUMENTDATATYPE_WIDECHAR: {
1581+
WideChar theid;
1582+
m_file->read(&theid, sizeof(theid));
1583+
msg->appendWideCharArgument(theid);
1584+
#ifdef DEBUG_LOGGING
1585+
if (m_doingAnalysis)
1586+
{
1587+
DEBUG_LOG(("WideChar argument: %d (%lc)", theid, theid));
1588+
}
15581589
#endif
1590+
break;
1591+
}
1592+
1593+
default:
1594+
break;
15591595
}
15601596
}
15611597

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

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -907,34 +907,44 @@ 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) {
911-
if (m_connectionRound >= 1) {
912-
return TRUE;
913-
}
914-
} else if (m_numNodes == 3) {
915-
if (m_connectionRound >= 3) {
916-
return TRUE;
917-
}
918-
} else if (m_numNodes == 4) {
919-
if (m_connectionRound >= 3) {
920-
return TRUE;
921-
}
922-
} else if (m_numNodes == 5) {
923-
if (m_connectionRound >= 5) {
924-
return TRUE;
925-
}
926-
} else if (m_numNodes == 6) {
927-
if (m_connectionRound >= 5) {
928-
return TRUE;
929-
}
930-
} else if (m_numNodes == 7) {
931-
if (m_connectionRound >= 7) {
932-
return TRUE;
933-
}
934-
} else if (m_numNodes == 8) {
935-
if (m_connectionRound >= 7) {
936-
return TRUE;
937-
}
910+
switch (m_numNodes) {
911+
case 2:
912+
if (m_connectionRound >= 1) {
913+
return TRUE;
914+
}
915+
break;
916+
case 3:
917+
if (m_connectionRound >= 3) {
918+
return TRUE;
919+
}
920+
break;
921+
case 4:
922+
if (m_connectionRound >= 3) {
923+
return TRUE;
924+
}
925+
break;
926+
case 5:
927+
if (m_connectionRound >= 5) {
928+
return TRUE;
929+
}
930+
break;
931+
case 6:
932+
if (m_connectionRound >= 5) {
933+
return TRUE;
934+
}
935+
break;
936+
case 7:
937+
if (m_connectionRound >= 7) {
938+
return TRUE;
939+
}
940+
break;
941+
case 8:
942+
if (m_connectionRound >= 7) {
943+
return TRUE;
944+
}
945+
break;
946+
default:
947+
break;
938948
}
939949
return FALSE;
940950
}

0 commit comments

Comments
 (0)