msgstatlistgroup.cpp 6.1 KB

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