Skip to content

Commit ce3c915

Browse files
committed
Fix abstract class instantiation by creating missing command message classes
- Add NetLoadCompleteCommandMsg and NetTimeOutGameStartCommandMsg classes - Update ConnectionManager.cpp to use specific classes instead of base NetCommandMsg - Remove special case handling from NetPacket.cpp since all types now have classes - Eliminate the switch statement entirely - now just calls virtual function
1 parent 06d97b5 commit ce3c915

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

GeneralsMD/Code/GameEngine/Include/GameNetwork/NetCommandMsg.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,31 @@ class NetFrameResendRequestCommandMsg : public NetCommandMsg
568568
protected:
569569
UnsignedInt m_frameToResend;
570570
};
571+
572+
//-----------------------------------------------------------------------------
573+
/**
574+
* The NetLoadCompleteCommandMsg is a simple command message for load complete notifications
575+
*/
576+
class NetLoadCompleteCommandMsg : public NetCommandMsg
577+
{
578+
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetLoadCompleteCommandMsg, "NetLoadCompleteCommandMsg")
579+
public:
580+
NetLoadCompleteCommandMsg();
581+
582+
size_t getPackedByteCount() const;
583+
};
584+
585+
//-----------------------------------------------------------------------------
586+
/**
587+
* The NetTimeOutGameStartCommandMsg is a simple command message for timeout game start notifications
588+
*/
589+
class NetTimeOutGameStartCommandMsg : public NetCommandMsg
590+
{
591+
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetTimeOutGameStartCommandMsg, "NetTimeOutGameStartCommandMsg")
592+
public:
593+
NetTimeOutGameStartCommandMsg();
594+
595+
size_t getPackedByteCount() const;
596+
};
597+
571598
#endif

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,12 +2222,11 @@ void ConnectionManager::updateLoadProgress( Int progress )
22222222

22232223
void ConnectionManager::loadProgressComplete()
22242224
{
2225-
NetCommandMsg *msg = newInstance(NetCommandMsg);
2225+
NetLoadCompleteCommandMsg *msg = newInstance(NetLoadCompleteCommandMsg);
22262226
msg->setPlayerID( m_localSlot );
22272227
if (DoesCommandRequireACommandID(msg->getNetCommandType()) == TRUE) {
22282228
msg->setID(GenerateNextCommandID());
22292229
}
2230-
msg->setNetCommandType(NETCOMMANDTYPE_LOADCOMPLETE);
22312230
processLoadComplete(msg);
22322231
sendLocalCommand(msg, 0xff ^ (1 << m_localSlot));
22332232

@@ -2236,9 +2235,8 @@ void ConnectionManager::loadProgressComplete()
22362235

22372236
void ConnectionManager::sendTimeOutGameStart()
22382237
{
2239-
NetCommandMsg *msg = newInstance(NetCommandMsg);
2238+
NetTimeOutGameStartCommandMsg *msg = newInstance(NetTimeOutGameStartCommandMsg);
22402239
msg->setPlayerID( m_localSlot );
2241-
msg->setNetCommandType(NETCOMMANDTYPE_TIMEOUTSTART);
22422240
if (DoesCommandRequireACommandID(msg->getNetCommandType()) == TRUE) {
22432241
msg->setID(GenerateNextCommandID());
22442242
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,3 +1254,25 @@ size_t NetFrameResendRequestCommandMsg::getPackedByteCount() const {
12541254
return sizeof(NetPacketFrameResendRequestCommand);
12551255
}
12561256

1257+
//-------------------------
1258+
// NetLoadCompleteCommandMsg
1259+
//-------------------------
1260+
NetLoadCompleteCommandMsg::NetLoadCompleteCommandMsg() : NetCommandMsg() {
1261+
m_commandType = NETCOMMANDTYPE_LOADCOMPLETE;
1262+
}
1263+
1264+
size_t NetLoadCompleteCommandMsg::getPackedByteCount() const {
1265+
return sizeof(NetPacketLoadCompleteMessage);
1266+
}
1267+
1268+
//-------------------------
1269+
// NetTimeOutGameStartCommandMsg
1270+
//-------------------------
1271+
NetTimeOutGameStartCommandMsg::NetTimeOutGameStartCommandMsg() : NetCommandMsg() {
1272+
m_commandType = NETCOMMANDTYPE_TIMEOUTSTART;
1273+
}
1274+
1275+
size_t NetTimeOutGameStartCommandMsg::getPackedByteCount() const {
1276+
return sizeof(NetPacketTimeOutGameStartMessage);
1277+
}
1278+

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,8 @@ UnsignedInt NetPacket::GetBufferSizeNeededForCommand(NetCommandMsg *msg) {
278278
if (msg == NULL) {
279279
return TRUE; // There was nothing to add, so it was successful.
280280
}
281-
// Handle special cases that don't have corresponding command message classes
282-
switch(msg->getNetCommandType())
283-
{
284-
case NETCOMMANDTYPE_LOADCOMPLETE:
285-
return sizeof(NetPacketLoadCompleteMessage);
286-
case NETCOMMANDTYPE_TIMEOUTSTART:
287-
return sizeof(NetPacketTimeOutGameStartMessage);
288-
default:
289-
return msg->getPackedByteCount();
290-
}
291-
292-
return 0;
281+
// Use the virtual function for all command message types
282+
return msg->getPackedByteCount();
293283
}
294284

295285

0 commit comments

Comments
 (0)