sbbomanager.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/sbbomanager.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 11/27/01 12:13p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "sbbomanager.h"
  36. #include "debug.h"
  37. #include "cnetwork.h"
  38. //
  39. // Class statics
  40. //
  41. float cSbboManager::AccumTimeSNetUpdate = 0;
  42. float cSbboManager::AccumTimeSCombatThink = 0;
  43. float cSbboManager::NetToCombatRatio = 0;
  44. int cSbboManager::PoorRatios = 0;
  45. int cSbboManager::SlowSamples = 0;
  46. bool cSbboManager::IsEnabled = true;
  47. //-----------------------------------------------------------------------------
  48. void
  49. cSbboManager::Reset
  50. (
  51. void
  52. )
  53. {
  54. WWASSERT(cNetwork::I_Am_Server());
  55. AccumTimeSNetUpdate = 0;
  56. AccumTimeSCombatThink = 0;
  57. NetToCombatRatio = 0;
  58. PoorRatios = 0;
  59. SlowSamples = 0;
  60. }
  61. //-----------------------------------------------------------------------------
  62. void
  63. cSbboManager::Think
  64. (
  65. void
  66. )
  67. {
  68. //
  69. // This function reduces server bandwidth out if the framerate is low and we are
  70. // spending way too much time doing network updates.
  71. //
  72. if (!IsEnabled)
  73. {
  74. return;
  75. }
  76. WWASSERT(cNetwork::I_Am_Server());
  77. float total_time = AccumTimeSNetUpdate + AccumTimeSCombatThink;
  78. if (AccumTimeSCombatThink > 0 && total_time > 2)
  79. {
  80. NetToCombatRatio = AccumTimeSNetUpdate / AccumTimeSCombatThink;
  81. AccumTimeSNetUpdate = 0;
  82. AccumTimeSCombatThink = 0;
  83. if (NetToCombatRatio > 5) {
  84. PoorRatios++;
  85. } else {
  86. PoorRatios = 0;
  87. }
  88. if (cNetwork::Get_Fps() < 20) {
  89. SlowSamples++;
  90. } else {
  91. SlowSamples = 0;
  92. }
  93. if (SlowSamples >= 10 && PoorRatios >= 10) {
  94. ULONG sbbo = cNetwork::PServerConnection->Get_Bandwidth_Budget_Out();
  95. if (sbbo >= 64000)
  96. {
  97. sbbo *= 0.90;
  98. cNetwork::PServerConnection->Set_Bandwidth_Budget_Out(sbbo);
  99. Debug_Say(("cSbboManager::Think: reducing sbbo to %d\n", sbbo));
  100. SlowSamples = 0;
  101. PoorRatios = 0;
  102. }
  103. }
  104. }
  105. }
  106. //-----------------------------------------------------------------------------
  107. void
  108. cSbboManager::Increment_Accum_Time_S_Net_Update
  109. (
  110. float time_increment_s
  111. )
  112. {
  113. WWASSERT(cNetwork::I_Am_Server());
  114. WWASSERT(time_increment_s >= 0);
  115. AccumTimeSNetUpdate += time_increment_s;
  116. }
  117. //-----------------------------------------------------------------------------
  118. void
  119. cSbboManager::Increment_Accum_Time_S_Combat_Think
  120. (
  121. float time_increment_s
  122. )
  123. {
  124. WWASSERT(cNetwork::I_Am_Server());
  125. WWASSERT(time_increment_s >= 0);
  126. AccumTimeSCombatThink += time_increment_s;
  127. }
  128. //-----------------------------------------------------------------------------
  129. float
  130. cSbboManager::Get_Net_To_Combat_Ratio
  131. (
  132. void
  133. )
  134. {
  135. WWASSERT(cNetwork::I_Am_Server());
  136. return NetToCombatRatio;
  137. }
  138. //-----------------------------------------------------------------------------
  139. bool
  140. cSbboManager::Toggle_Is_Enabled
  141. (
  142. void
  143. )
  144. {
  145. IsEnabled = !IsEnabled;
  146. Reset();
  147. return IsEnabled;
  148. }