msgstatlist.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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: msgstatlist.cpp
  20. // Project:
  21. // Author: Tom Spencer-Smith
  22. // Date:
  23. // Description:
  24. //
  25. //------------------------------------------------------------------------------------
  26. #include "msgstatlist.h" // I WANNA BE FIRST!
  27. #include "mathutil.h"
  28. #include "wwdebug.h"
  29. //
  30. // Class statics
  31. //
  32. //------------------------------------------------------------------------------------
  33. cMsgStatList::cMsgStatList(void) :
  34. NumStats(0)
  35. {
  36. }
  37. //---------------- --------------------------------------------------------------------
  38. cMsgStatList::~cMsgStatList(void)
  39. {
  40. if (PStat != NULL) {
  41. delete [] PStat;
  42. PStat = NULL;
  43. }
  44. }
  45. //-----------------------------------------------------------------------------
  46. void cMsgStatList::Init(int num_stats)
  47. {
  48. WWASSERT(num_stats > 0);
  49. NumStats = num_stats;
  50. PStat = new cMsgStat[NumStats + 1];
  51. WWASSERT(PStat != NULL);
  52. }
  53. //-----------------------------------------------------------------------------
  54. void cMsgStatList::Increment_Num_Msg_Sent(int message_type, int increment)
  55. {
  56. WWASSERT(message_type >= 0 && message_type < NumStats);
  57. WWASSERT(increment > 0);
  58. PStat[message_type].Increment_Num_Msg_Sent(increment);
  59. PStat[NumStats].Increment_Num_Msg_Sent(increment);
  60. }
  61. //-----------------------------------------------------------------------------
  62. void cMsgStatList::Increment_Num_Byte_Sent(int message_type, int increment)
  63. {
  64. WWASSERT(message_type >= 0 && message_type < NumStats);
  65. WWASSERT(increment > 0);
  66. PStat[message_type].Increment_Num_Byte_Sent(increment);
  67. PStat[NumStats].Increment_Num_Byte_Sent(increment);
  68. }
  69. //-----------------------------------------------------------------------------
  70. void cMsgStatList::Increment_Num_Msg_Recd(int message_type, int increment)
  71. {
  72. WWASSERT(message_type >= 0 && message_type < NumStats);
  73. WWASSERT(increment > 0);
  74. PStat[message_type].Increment_Num_Msg_Recd(increment);
  75. PStat[NumStats].Increment_Num_Msg_Recd(increment);
  76. }
  77. //-----------------------------------------------------------------------------
  78. void cMsgStatList::Increment_Num_Byte_Recd(int message_type, int increment)
  79. {
  80. WWASSERT(message_type >= 0 && message_type < NumStats);
  81. WWASSERT(increment > 0);
  82. PStat[message_type].Increment_Num_Byte_Recd(increment);
  83. PStat[NumStats].Increment_Num_Byte_Recd(increment);
  84. }
  85. //-----------------------------------------------------------------------------
  86. DWORD cMsgStatList::Get_Num_Msg_Sent(int message_type) const
  87. {
  88. if (message_type == ALL_MESSAGES) {
  89. message_type = NumStats;
  90. }
  91. WWASSERT(message_type >= 0 && message_type <= NumStats);
  92. return PStat[message_type].Get_Num_Msg_Sent();
  93. }
  94. //-----------------------------------------------------------------------------
  95. DWORD cMsgStatList::Get_Num_Byte_Sent(int message_type) const
  96. {
  97. if (message_type == ALL_MESSAGES) {
  98. message_type = NumStats;
  99. }
  100. WWASSERT(message_type >= 0 && message_type <= NumStats);
  101. return PStat[message_type].Get_Num_Byte_Sent();
  102. }
  103. //-----------------------------------------------------------------------------
  104. DWORD cMsgStatList::Get_Num_Msg_Recd(int message_type) const
  105. {
  106. if (message_type == ALL_MESSAGES) {
  107. message_type = NumStats;
  108. }
  109. WWASSERT(message_type >= 0 && message_type <= NumStats);
  110. return PStat[message_type].Get_Num_Msg_Recd();
  111. }
  112. //-----------------------------------------------------------------------------
  113. DWORD cMsgStatList::Get_Num_Byte_Recd(int message_type) const
  114. {
  115. if (message_type == ALL_MESSAGES) {
  116. message_type = NumStats;
  117. }
  118. WWASSERT(message_type >= 0 && message_type <= NumStats);
  119. return PStat[message_type].Get_Num_Byte_Recd();
  120. }
  121. //-----------------------------------------------------------------------------
  122. DWORD cMsgStatList::Compute_Avg_Num_Byte_Sent(int message_type) const
  123. {
  124. if (message_type == ALL_MESSAGES) {
  125. message_type = NumStats;
  126. }
  127. WWASSERT(message_type >= 0 && message_type <= NumStats);
  128. return PStat[message_type].Compute_Avg_Num_Byte_Sent();
  129. }
  130. //-----------------------------------------------------------------------------
  131. DWORD cMsgStatList::Compute_Avg_Num_Byte_Recd(int message_type) const
  132. {
  133. if (message_type == ALL_MESSAGES) {
  134. message_type = NumStats;
  135. }
  136. WWASSERT(message_type >= 0 && message_type <= NumStats);
  137. return PStat[message_type].Compute_Avg_Num_Byte_Recd();
  138. }
  139. //-----------------------------------------------------------------------------
  140. cMsgStat & cMsgStatList::Get_Stat(int message_type)
  141. {
  142. if (message_type == ALL_MESSAGES) {
  143. message_type = NumStats;
  144. }
  145. WWASSERT(message_type >= 0 && message_type <= NumStats);
  146. return PStat[message_type];
  147. }
  148. //-----------------------------------------------------------------------------
  149. void cMsgStatList::Set_Name(int message_type, LPCSTR name)
  150. {
  151. WWASSERT(message_type >= 0 && message_type < NumStats);
  152. PStat[message_type].Set_Name(name);
  153. }
  154. //-----------------------------------------------------------------------------
  155. LPCSTR cMsgStatList::Get_Name(int message_type) const
  156. {
  157. WWASSERT(message_type >= 0 && message_type <= NumStats);
  158. return PStat[message_type].Get_Name();
  159. }