clientfps.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/clientfps.cpp $*
  25. * *
  26. * $Author:: Tom_s $*
  27. * *
  28. * $Modtime:: 9/20/01 11:28a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "clientfps.h"
  36. #include "networkobjectfactory.h"
  37. #include "networkobjectmgr.h"
  38. #include "cnetwork.h"
  39. #include "playermanager.h"
  40. #include "apppackettypes.h"
  41. CClientFps * PClientFps = NULL;
  42. DECLARE_NETWORKOBJECT_FACTORY(CClientFps, NETCLASSID_CLIENTFPS);
  43. #pragma message("(TSS) high priority for me to fix this CClientFps bug...")
  44. //
  45. // TSS2001 problem: destruction of this object on the server. Quitting and rejoining
  46. // a game will crash the server.
  47. //
  48. //-----------------------------------------------------------------------------
  49. CClientFps::CClientFps(void)
  50. {
  51. ClientId = -1;
  52. Fps = 0;
  53. Set_App_Packet_Type(APPPACKETTYPE_CLIENTFPS);
  54. }
  55. //-----------------------------------------------------------------------------
  56. CClientFps::~CClientFps(void)
  57. {
  58. }
  59. //-----------------------------------------------------------------------------
  60. void
  61. CClientFps::Init(void)
  62. {
  63. WWASSERT(cNetwork::I_Am_Client());
  64. ClientId = cNetwork::Get_My_Id();
  65. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  66. Set_Object_Dirty_Bit(0, NetworkObjectClass::BIT_CREATION, true);
  67. }
  68. //-----------------------------------------------------------------------------
  69. void
  70. CClientFps::Set_Fps(int fps)
  71. {
  72. WWASSERT(cNetwork::I_Am_Client());
  73. WWASSERT(fps >= 0);
  74. Fps = (BYTE) fps;
  75. Set_Object_Dirty_Bit(0, NetworkObjectClass::BIT_FREQUENT, true);
  76. }
  77. //-----------------------------------------------------------------------------
  78. void
  79. CClientFps::Act(void)
  80. {
  81. WWASSERT(cNetwork::I_Am_Server());
  82. cPlayer * p_player = cPlayerManager::Find_Player(ClientId);
  83. if (p_player != NULL)
  84. {
  85. p_player->Set_Fps(Fps);
  86. }
  87. }
  88. //-----------------------------------------------------------------------------
  89. void
  90. CClientFps::Export_Creation(BitStreamClass & packet)
  91. {
  92. WWASSERT(cNetwork::I_Am_Client());
  93. NetworkObjectClass::Export_Creation(packet);
  94. packet.Add(ClientId);
  95. }
  96. //-----------------------------------------------------------------------------
  97. void
  98. CClientFps::Import_Creation(BitStreamClass & packet)
  99. {
  100. WWASSERT(cNetwork::I_Am_Server());
  101. NetworkObjectClass::Import_Creation(packet);
  102. packet.Get(ClientId);
  103. }
  104. //-----------------------------------------------------------------------------
  105. void
  106. CClientFps::Export_Frequent(BitStreamClass & packet)
  107. {
  108. WWASSERT(cNetwork::I_Am_Client());
  109. packet.Add(Fps);
  110. }
  111. //-----------------------------------------------------------------------------
  112. void
  113. CClientFps::Import_Frequent(BitStreamClass & packet)
  114. {
  115. WWASSERT(cNetwork::I_Am_Server());
  116. packet.Get(Fps);
  117. Act();
  118. }