vissectorstats.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/vissectorstats.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 6/06/01 5:45p $*
  31. * *
  32. * $Revision:: 7 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * Count_Textures -- counts textures used by the given object *
  37. * VisSectorStatsClass::VisSectorStatsClass -- Constructor *
  38. * VisSectorStatsClass::~VisSectorStatsClass -- Destructor *
  39. * VisSectorStatsClass::Compute_Stats -- Initializes the statistics for the given object *
  40. * VisSectorStatsClass::operator= -- Safely copies the member data from the source object. *
  41. * VisSectorStatsClass::Get_Name -- Returns the name of the model this vis sector contains *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #include "vissectorstats.h"
  44. #include "pscene.h"
  45. #include "vistable.h"
  46. #include "staticphys.h"
  47. #include "statistics.h"
  48. #include "matinfo.h"
  49. /***********************************************************************************************
  50. * Count_Textures -- counts textures used by the given object *
  51. * *
  52. * INPUT: *
  53. * *
  54. * OUTPUT: *
  55. * *
  56. * WARNINGS: *
  57. * *
  58. * HISTORY: *
  59. * 6/6/2000 gth : Created. *
  60. *=============================================================================================*/
  61. static void Count_Textures(RenderObjClass * obj)
  62. {
  63. if (obj == NULL) {
  64. return;
  65. }
  66. /*
  67. ** Count the textures for the sub objects
  68. */
  69. for (int i=0; i<obj->Get_Num_Sub_Objects(); i++) {
  70. RenderObjClass * subobj = obj->Get_Sub_Object(i);
  71. Count_Textures(subobj);
  72. REF_PTR_RELEASE(subobj);
  73. }
  74. /*
  75. ** Count the textures for this object
  76. */
  77. MaterialInfoClass * matinfo = obj->Get_Material_Info();
  78. if (matinfo != NULL) {
  79. for (int ti=0; ti<matinfo->Texture_Count(); ti++) {
  80. Debug_Statistics::Record_Texture(matinfo->Peek_Texture(ti));
  81. }
  82. }
  83. }
  84. /*********************************************************************************************
  85. **
  86. ** VisSectorStatsClass Implementation
  87. **
  88. *********************************************************************************************/
  89. /***********************************************************************************************
  90. * VisSectorStatsClass::VisSectorStatsClass -- Constructor *
  91. * *
  92. * INPUT: *
  93. * *
  94. * OUTPUT: *
  95. * *
  96. * WARNINGS: *
  97. * *
  98. * HISTORY: *
  99. * 6/6/2000 gth : Created. *
  100. *=============================================================================================*/
  101. VisSectorStatsClass::VisSectorStatsClass(void) :
  102. VisId(-1),
  103. PolygonCount(0),
  104. TextureCount(0),
  105. TextureBytes(0),
  106. CenterPoint(0,0,0),
  107. PhysObj(NULL)
  108. {
  109. }
  110. /***********************************************************************************************
  111. * VisSectorStatsClass::VisSectorStatsClass -- Constructor *
  112. * *
  113. * INPUT: *
  114. * *
  115. * OUTPUT: *
  116. * *
  117. * WARNINGS: *
  118. * *
  119. * HISTORY: *
  120. * 6/6/2000 pds : Created. *
  121. *=============================================================================================*/
  122. VisSectorStatsClass::VisSectorStatsClass(const VisSectorStatsClass &src) :
  123. VisId(-1),
  124. PolygonCount(0),
  125. TextureCount(0),
  126. TextureBytes(0),
  127. CenterPoint(0,0,0),
  128. PhysObj(NULL)
  129. {
  130. (*this) = src;
  131. }
  132. /***********************************************************************************************
  133. * VisSectorStatsClass::~VisSectorStatsClass -- Destructor *
  134. * *
  135. * INPUT: *
  136. * *
  137. * OUTPUT: *
  138. * *
  139. * WARNINGS: *
  140. * *
  141. * HISTORY: *
  142. *=============================================================================================*/
  143. VisSectorStatsClass::~VisSectorStatsClass(void)
  144. {
  145. REF_PTR_RELEASE(PhysObj);
  146. }
  147. /***********************************************************************************************
  148. * VisSectorStatsClass::Compute_Stats -- Initializes the statistics for the given object *
  149. * *
  150. * INPUT: *
  151. * *
  152. * OUTPUT: *
  153. * *
  154. * WARNINGS: *
  155. * *
  156. * HISTORY: *
  157. * 6/6/2000 gth : Created. *
  158. *=============================================================================================*/
  159. void VisSectorStatsClass::Compute_Stats(StaticPhysClass * obj,VisTableClass * vistable)
  160. {
  161. /*
  162. ** Save the vis id and a point above the center of the object
  163. */
  164. VisId = obj->Get_Vis_Object_ID();
  165. CenterPoint = obj->Get_Cull_Box().Center + Vector3(0.0f,0.0f,2.0f);
  166. /*
  167. ** Reset the texture statistics tracker
  168. */
  169. PolygonCount = 0;
  170. TextureCount = 0;
  171. TextureBytes = 0;
  172. if (vistable != NULL) {
  173. Debug_Statistics::Begin_Statistics();
  174. Debug_Statistics::Record_Texture_Mode(Debug_Statistics::RECORD_TEXTURE_DETAILS);
  175. /*
  176. ** Walk through every static object in the level, adding its resources
  177. ** to our stats if it is visible from this sector
  178. */
  179. RefPhysListIterator it = PhysicsSceneClass::Get_Instance()->Get_Static_Object_Iterator();
  180. for (it.First(); !it.Is_Done(); it.Next()) {
  181. StaticPhysClass * obj = it.Peek_Obj()->As_StaticPhysClass();
  182. if (obj && vistable->Get_Bit(obj->Get_Vis_Object_ID())) {
  183. PolygonCount += obj->Peek_Model()->Get_Num_Polys();
  184. Count_Textures(obj->Peek_Model());
  185. }
  186. }
  187. /*
  188. ** Finish the texture statistics
  189. */
  190. Debug_Statistics::Record_Texture_Mode(Debug_Statistics::RECORD_TEXTURE_NONE);
  191. Debug_Statistics::End_Statistics();
  192. TextureCount = Debug_Statistics::Get_Record_Texture_Count();
  193. TextureBytes = Debug_Statistics::Get_Record_Texture_Size();
  194. }
  195. /*
  196. ** Save a reference to the physics object
  197. */
  198. REF_PTR_SET (PhysObj, obj);
  199. }
  200. /***********************************************************************************************
  201. * VisSectorStatsClass::operator= -- Safely copies the member data from the source object. *
  202. * *
  203. * INPUT: *
  204. * *
  205. * OUTPUT: *
  206. * *
  207. * WARNINGS: *
  208. * *
  209. * HISTORY: *
  210. * 6/6/2000 pds : Created. *
  211. *=============================================================================================*/
  212. const VisSectorStatsClass &VisSectorStatsClass::operator= (const VisSectorStatsClass &src)
  213. {
  214. VisId = src.VisId;
  215. PolygonCount = src.PolygonCount;
  216. TextureCount = src.TextureCount;
  217. TextureBytes = src.TextureBytes;
  218. CenterPoint = src.CenterPoint;
  219. REF_PTR_SET (PhysObj, src.PhysObj);
  220. return (*this);
  221. }
  222. /***********************************************************************************************
  223. * VisSectorStatsClass::Get_Name -- Returns the name of the model this vis sector contains *
  224. * *
  225. * INPUT: *
  226. * *
  227. * OUTPUT: *
  228. * *
  229. * WARNINGS: *
  230. * *
  231. * HISTORY: *
  232. * 6/6/2000 pds : Created. *
  233. *=============================================================================================*/
  234. const char *VisSectorStatsClass::Get_Name(void)
  235. {
  236. const char *name = NULL;
  237. if (PhysObj != NULL && PhysObj->Peek_Model () != NULL) {
  238. name = PhysObj->Peek_Model ()->Get_Name ();
  239. }
  240. return name;
  241. }