netstats.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // Filename: netstats.h
  20. // Project: wwnet
  21. // Author: Tom Spencer-Smith
  22. // Date: Oct 1998
  23. // Description:
  24. //
  25. //-----------------------------------------------------------------------------
  26. #if defined(_MSV_VER)
  27. #pragma once
  28. #endif
  29. #ifndef NETSTATS_H
  30. #define NETSTATS_H
  31. #include "bittype.h"
  32. #include "wwdebug.h"
  33. //
  34. // Statistics.
  35. // Abbrev:
  36. // R = Reliable
  37. // U = Unreliable
  38. // Pkt = packet
  39. // Rcv = Received
  40. // App = Application
  41. // Hdr = Header
  42. // Byte = bytes, including header
  43. //
  44. // Syntax is U/R then Pkt/Byte/AppByte then Sent/Rcv
  45. //
  46. typedef enum Statistic
  47. {
  48. STAT_PktSent,
  49. STAT_PktRcv,
  50. STAT_MsgSent, // Need to count separately since messages can be combined
  51. STAT_MsgRcv, // into packets TSS - bug: this not accurate because of combining
  52. STAT_AppByteSent,
  53. STAT_AppByteRcv,
  54. //STAT_HdrByteSent,
  55. //STAT_HdrByteRcv,
  56. STAT_BitsSent,
  57. STAT_BitsRcv,
  58. STAT_UPktSent,
  59. STAT_RPktSent,
  60. STAT_UByteSent,
  61. STAT_RByteSent,
  62. STAT_UPktRcv,
  63. STAT_RPktRcv,
  64. STAT_UByteRcv,
  65. STAT_RByteRcv,
  66. /*
  67. STAT_AppDataSentPc, // App / (App + Hdr)
  68. STAT_AppDataRcvPc, // App / (App + Hdr)
  69. */
  70. STAT_AckCountSent,
  71. STAT_AckCountRcv,
  72. STAT_DiscardCount,
  73. STAT_ResendCount,
  74. STAT_SendFailureCount,
  75. STAT_PktRcvRemote,
  76. STAT_UPktShouldRcv,
  77. STAT_UPktRcv2, // used in packetloss calculations. Slightly less than STAT_UPktRcv
  78. STAT_ServiceCount,
  79. STAT_COUNT // must include, used as array bound
  80. };
  81. //-----------------------------------------------------------------------------
  82. class cNetStats
  83. {
  84. public:
  85. cNetStats();
  86. ~cNetStats() {};
  87. void Init_Net_Stats();
  88. bool Update_If_Sample_Done(int this_frame_time, bool force_update = false);
  89. double Get_Pc_Packetloss_Received() const;
  90. void Set_Pc_Packetloss_Sent(double packetloss_pc);
  91. double Get_Pc_Packetloss_Sent() const {return RemotePacketloss;}
  92. int Get_Remote_Service_Count() {return RemoteServiceCount;}
  93. void Set_Remote_Service_Count(int remote_service_count);
  94. int Get_Sample_Start_Time() const {return SampleStartTime;}
  95. int Get_Last_Unreliable_Packet_Id() const {return LastUnreliablePacketId;}
  96. void Set_Last_Unreliable_Packet_Id(int id) {LastUnreliablePacketId = id;}
  97. int Get_Freeze_Packet_Id() const {return FreezePacketId;}
  98. void Increment_Unreliable_Count() {UnreliableCount++;}
  99. UINT Get_Stat_Sample(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatSample[stat];}
  100. UINT Get_Stat_Macro_Sample(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatMacroSample[stat];}
  101. UINT Get_Stat_Snapshot(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatSnapshot[stat];}
  102. UINT Get_Stat_Macro_Snapshot(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatMacroSnapshot[stat];}
  103. UINT Get_Stat_Total(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatTotal[stat];}
  104. UINT Get_Stat_Average(int stat) const {WWASSERT(stat >= 0 && stat < STAT_COUNT); return StatAverage[stat];}
  105. void Increment_Stat_Sample(int stat, UINT increment) {WWASSERT(stat >= 0 && stat < STAT_COUNT); StatSample[stat] += increment;}
  106. void Increment_Stat_Macro_Sample(int stat, UINT increment) {WWASSERT(stat >= 0 && stat < STAT_COUNT); StatMacroSample[stat] += increment;}
  107. void Increment_Stat_Snapshot(int stat, UINT increment) {WWASSERT(stat >= 0 && stat < STAT_COUNT); StatSnapshot[stat] += increment;}
  108. void Increment_Stat_Macro_Snapshot(int stat, UINT increment){WWASSERT(stat >= 0 && stat < STAT_COUNT); StatMacroSnapshot[stat] += increment;}
  109. void Increment_Stat_Total(int stat, UINT increment) {WWASSERT(stat >= 0 && stat < STAT_COUNT); StatTotal[stat] += increment;}
  110. void Increment_Stat_Average(int stat, UINT increment) {WWASSERT(stat >= 0 && stat < STAT_COUNT); StatAverage[stat] += increment;}
  111. //
  112. // TSS - shift these down, and use above access operators
  113. //
  114. UINT StatSample[STAT_COUNT];
  115. UINT StatMacroSample[STAT_COUNT];
  116. UINT StatSnapshot[STAT_COUNT];
  117. UINT StatMacroSnapshot[STAT_COUNT];
  118. UINT StatTotal[STAT_COUNT];
  119. UINT StatAverage[STAT_COUNT];
  120. private:
  121. cNetStats(const cNetStats& source); // Disallow copy (compile/link time)
  122. cNetStats& operator=(const cNetStats& rhs); // Disallow assignment (compile/link time)
  123. //int PrevLastUnreliable;
  124. unsigned long SampleStartTime;
  125. int LastUnreliablePacketId;
  126. int FreezePacketId;
  127. int UnreliableCount;
  128. unsigned long StartTime;
  129. double RemotePacketloss;
  130. int RemoteServiceCount;
  131. };
  132. //-----------------------------------------------------------------------------
  133. #endif // NETSTATS_H
  134. //static const USHORT SAMPLE_TIME; // stats gathering period in ms