msgstat.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: msgstat.cpp
  20. // Project:
  21. // Author: Tom Spencer-Smith
  22. // Date:
  23. // Description:
  24. //
  25. //------------------------------------------------------------------------------------
  26. #include "msgstat.h" // I WANNA BE FIRST!
  27. #include <string.h>
  28. #include "mathutil.h"
  29. #include "wwdebug.h"
  30. //
  31. // Class statics
  32. //
  33. //------------------------------------------------------------------------------------
  34. cMsgStat::cMsgStat(void) :
  35. NumMsgSent(0),
  36. NumByteSent(0),
  37. NumMsgRecd(0),
  38. NumByteRecd(0)
  39. {
  40. ::strcpy(Name, "UNNAMED");
  41. }
  42. //---------------- --------------------------------------------------------------------
  43. cMsgStat::~cMsgStat(void)
  44. {
  45. }
  46. //---------------- --------------------------------------------------------------------
  47. void cMsgStat::Increment_Num_Msg_Sent(int increment)
  48. {
  49. WWASSERT(increment > 0);
  50. NumMsgSent += increment;
  51. }
  52. //---------------- --------------------------------------------------------------------
  53. void cMsgStat::Increment_Num_Byte_Sent(int increment)
  54. {
  55. WWASSERT(increment > 0);
  56. NumByteSent += increment;
  57. }
  58. //---------------- --------------------------------------------------------------------
  59. void cMsgStat::Increment_Num_Msg_Recd(int increment)
  60. {
  61. WWASSERT(increment > 0);
  62. NumMsgRecd += increment;
  63. }
  64. //---------------- --------------------------------------------------------------------
  65. void cMsgStat::Increment_Num_Byte_Recd(int increment)
  66. {
  67. WWASSERT(increment > 0);
  68. NumByteRecd += increment;
  69. }
  70. //---------------- --------------------------------------------------------------------
  71. DWORD cMsgStat::Compute_Avg_Num_Byte_Sent(void) const
  72. {
  73. DWORD avg = 0;
  74. if (NumMsgSent > 0) {
  75. avg = (DWORD) cMathUtil::Round(NumByteSent / (float) NumMsgSent);
  76. }
  77. return avg;
  78. }
  79. //---------------- --------------------------------------------------------------------
  80. DWORD cMsgStat::Compute_Avg_Num_Byte_Recd(void) const
  81. {
  82. DWORD avg = 0;
  83. if (NumMsgRecd > 0) {
  84. avg = (DWORD) cMathUtil::Round(NumByteRecd / (float) NumMsgRecd);
  85. }
  86. return avg;
  87. }
  88. //---------------- --------------------------------------------------------------------
  89. void cMsgStat::Set_Name(LPCSTR name)
  90. {
  91. WWASSERT(name != NULL);
  92. WWASSERT(::strlen(name) < sizeof(Name));
  93. ::strcpy(Name, name);
  94. }