Skip to content

Commit ffab2a4

Browse files
committed
Make getPackedByteCount() a pure virtual function and eliminate switch statement
1 parent c749578 commit ffab2a4

File tree

3 files changed

+48
-96
lines changed

3 files changed

+48
-96
lines changed

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NetCommandMsg : public MemoryPoolObject
5353
inline void setNetCommandType(NetCommandType type) { m_commandType = type; }
5454
inline NetCommandType getNetCommandType() { return m_commandType; }
5555
virtual Int getSortNumber();
56+
virtual size_t getPackedByteCount() const = 0;
5657
void attach();
5758
void detach();
5859

@@ -83,7 +84,7 @@ class NetGameCommandMsg : public NetCommandMsg
8384
void addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg);
8485
void setGameMessageType(GameMessage::Type type);
8586

86-
size_t getPackedByteCount() const;
87+
size_t getPackedByteCount() const override;
8788

8889
protected:
8990
Int m_numArgs;
@@ -111,7 +112,7 @@ class NetAckBothCommandMsg : public NetCommandMsg
111112
void setOriginalPlayerID(UnsignedByte originalPlayerID);
112113
virtual Int getSortNumber();
113114

114-
static size_t getPackedByteCount();
115+
size_t getPackedByteCount() const override;
115116

116117
protected:
117118
UnsignedShort m_commandID;
@@ -137,7 +138,7 @@ class NetAckStage1CommandMsg : public NetCommandMsg
137138
void setOriginalPlayerID(UnsignedByte originalPlayerID);
138139
virtual Int getSortNumber();
139140

140-
static size_t getPackedByteCount();
141+
size_t getPackedByteCount() const override;
141142

142143
protected:
143144
UnsignedShort m_commandID;
@@ -163,7 +164,7 @@ class NetAckStage2CommandMsg : public NetCommandMsg
163164
void setOriginalPlayerID(UnsignedByte originalPlayerID);
164165
virtual Int getSortNumber();
165166

166-
static size_t getPackedByteCount();
167+
size_t getPackedByteCount() const override;
167168

168169
protected:
169170
UnsignedShort m_commandID;
@@ -181,7 +182,7 @@ class NetFrameCommandMsg : public NetCommandMsg
181182
void setCommandCount(UnsignedShort commandCount);
182183
UnsignedShort getCommandCount();
183184

184-
static size_t getPackedByteCount();
185+
size_t getPackedByteCount() const override;
185186

186187
protected:
187188
UnsignedShort m_commandCount;
@@ -198,7 +199,7 @@ class NetPlayerLeaveCommandMsg : public NetCommandMsg
198199
UnsignedByte getLeavingPlayerID();
199200
void setLeavingPlayerID(UnsignedByte id);
200201

201-
static size_t getPackedByteCount();
202+
size_t getPackedByteCount() const override;
202203

203204
protected:
204205
UnsignedByte m_leavingPlayerID;
@@ -217,7 +218,7 @@ class NetRunAheadMetricsCommandMsg : public NetCommandMsg
217218
Int getAverageFps();
218219
void setAverageFps(Int fps);
219220

220-
static size_t getPackedByteCount();
221+
size_t getPackedByteCount() const override;
221222

222223
protected:
223224
Real m_averageLatency;
@@ -238,7 +239,7 @@ class NetRunAheadCommandMsg : public NetCommandMsg
238239
UnsignedByte getFrameRate();
239240
void setFrameRate(UnsignedByte frameRate);
240241

241-
static size_t getPackedByteCount();
242+
size_t getPackedByteCount() const override;
242243

243244
protected:
244245
UnsignedShort m_runAhead;
@@ -256,7 +257,7 @@ class NetDestroyPlayerCommandMsg : public NetCommandMsg
256257
UnsignedInt getPlayerIndex();
257258
void setPlayerIndex(UnsignedInt playerIndex);
258259

259-
static size_t getPackedByteCount();
260+
size_t getPackedByteCount() const override;
260261

261262
protected:
262263
UnsignedInt m_playerIndex;
@@ -270,7 +271,7 @@ class NetKeepAliveCommandMsg : public NetCommandMsg
270271
NetKeepAliveCommandMsg();
271272
//virtual ~NetKeepAliveCommandMsg();
272273

273-
static size_t getPackedByteCount();
274+
size_t getPackedByteCount() const override;
274275
};
275276

276277
//-----------------------------------------------------------------------------
@@ -281,7 +282,7 @@ class NetDisconnectKeepAliveCommandMsg : public NetCommandMsg
281282
NetDisconnectKeepAliveCommandMsg();
282283
//virtual ~NetDisconnectKeepAliveCommandMsg();
283284

284-
static size_t getPackedByteCount();
285+
size_t getPackedByteCount() const override;
285286
};
286287

287288
//-----------------------------------------------------------------------------
@@ -298,7 +299,7 @@ class NetDisconnectPlayerCommandMsg : public NetCommandMsg
298299
UnsignedInt getDisconnectFrame();
299300
void setDisconnectFrame(UnsignedInt frame);
300301

301-
static size_t getPackedByteCount();
302+
size_t getPackedByteCount() const override;
302303

303304
protected:
304305
UnsignedByte m_disconnectSlot;
@@ -313,7 +314,7 @@ class NetPacketRouterQueryCommandMsg : public NetCommandMsg
313314
NetPacketRouterQueryCommandMsg();
314315
//virtual ~NetPacketRouterQueryCommandMsg();
315316

316-
static size_t getPackedByteCount();
317+
size_t getPackedByteCount() const override;
317318
};
318319

319320
//-----------------------------------------------------------------------------
@@ -324,7 +325,7 @@ class NetPacketRouterAckCommandMsg : public NetCommandMsg
324325
NetPacketRouterAckCommandMsg();
325326
//virtual ~NetPacketRouterAckCommandMsg();
326327

327-
static size_t getPackedByteCount();
328+
size_t getPackedByteCount() const override;
328329
};
329330

330331
//-----------------------------------------------------------------------------
@@ -338,7 +339,7 @@ class NetDisconnectChatCommandMsg : public NetCommandMsg
338339
UnicodeString getText();
339340
void setText(UnicodeString text);
340341

341-
size_t getPackedByteCount() const;
342+
size_t getPackedByteCount() const override;
342343

343344
protected:
344345
UnicodeString m_text;
@@ -358,7 +359,7 @@ class NetChatCommandMsg : public NetCommandMsg
358359
Int getPlayerMask( void );
359360
void setPlayerMask( Int playerMask );
360361

361-
size_t getPackedByteCount() const;
362+
size_t getPackedByteCount() const override;
362363

363364
protected:
364365
UnicodeString m_text;
@@ -379,7 +380,7 @@ class NetDisconnectVoteCommandMsg : public NetCommandMsg
379380
UnsignedInt getVoteFrame();
380381
void setVoteFrame(UnsignedInt voteFrame);
381382

382-
static size_t getPackedByteCount();
383+
size_t getPackedByteCount() const override;
383384

384385
protected:
385386
UnsignedByte m_slot;
@@ -397,7 +398,7 @@ class NetProgressCommandMsg: public NetCommandMsg
397398
UnsignedByte getPercentage();
398399
void setPercentage( UnsignedByte percent );
399400

400-
static size_t getPackedByteCount();
401+
size_t getPackedByteCount() const override;
401402
protected:
402403
UnsignedByte m_percent;
403404
};
@@ -413,7 +414,7 @@ class NetWrapperCommandMsg : public NetCommandMsg
413414
UnsignedByte * getData();
414415
void setData(UnsignedByte *data, UnsignedInt dataLength);
415416

416-
static size_t getPackedByteCount();
417+
size_t getPackedByteCount() const override;
417418

418419
UnsignedInt getChunkNumber();
419420
void setChunkNumber(UnsignedInt chunkNumber);
@@ -462,7 +463,7 @@ class NetFileCommandMsg : public NetCommandMsg
462463
UnsignedByte * getFileData();
463464
void setFileData(UnsignedByte *data, UnsignedInt dataLength);
464465

465-
size_t getPackedByteCount() const;
466+
size_t getPackedByteCount() const override;
466467

467468
protected:
468469
AsciiString m_portableFilename;
@@ -491,7 +492,7 @@ class NetFileAnnounceCommandMsg : public NetCommandMsg
491492
UnsignedByte getPlayerMask(void);
492493
void setPlayerMask(UnsignedByte playerMask);
493494

494-
size_t getPackedByteCount() const;
495+
size_t getPackedByteCount() const override;
495496

496497
protected:
497498
AsciiString m_portableFilename;
@@ -513,7 +514,7 @@ class NetFileProgressCommandMsg : public NetCommandMsg
513514
Int getProgress();
514515
void setProgress(Int val);
515516

516-
static size_t getPackedByteCount();
517+
size_t getPackedByteCount() const override;
517518

518519
protected:
519520
UnsignedShort m_fileID;
@@ -530,7 +531,7 @@ class NetDisconnectFrameCommandMsg : public NetCommandMsg
530531
UnsignedInt getDisconnectFrame();
531532
void setDisconnectFrame(UnsignedInt disconnectFrame);
532533

533-
static size_t getPackedByteCount();
534+
size_t getPackedByteCount() const override;
534535

535536
protected:
536537
UnsignedInt m_disconnectFrame;
@@ -546,7 +547,7 @@ class NetDisconnectScreenOffCommandMsg : public NetCommandMsg
546547
UnsignedInt getNewFrame();
547548
void setNewFrame(UnsignedInt newFrame);
548549

549-
static size_t getPackedByteCount();
550+
size_t getPackedByteCount() const override;
550551

551552
protected:
552553
UnsignedInt m_newFrame;
@@ -562,7 +563,7 @@ class NetFrameResendRequestCommandMsg : public NetCommandMsg
562563
UnsignedInt getFrameToResend();
563564
void setFrameToResend(UnsignedInt frame);
564565

565-
static size_t getPackedByteCount();
566+
size_t getPackedByteCount() const override;
566567

567568
protected:
568569
UnsignedInt m_frameToResend;

0 commit comments

Comments
 (0)