Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
6.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ====
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "hammer.h"
  8. #include "IEditorTexture.h"
  9. #include "MapEntity.h"
  10. #include "MapFace.h"
  11. #include "MapSolid.h"
  12. #include "MapWorld.h"
  13. #include "MapInfoDlg.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include <tier0/memdbgon.h>
  16. static BOOL CountObject(CMapClass *pobj);
  17. BEGIN_MESSAGE_MAP(CMapInfoDlg, CDialog)
  18. //{{AFX_MSG_MAP(CMapInfoDlg)
  19. //}}AFX_MSG_MAP
  20. END_MESSAGE_MAP()
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Callback for enumerating map objects while gathering statistics for
  23. // the map information dialog. Routes each object to the apppropriate
  24. // handler.
  25. // Input : *pobj - Object to count.
  26. // Output : Returns TRUE to continue enumerating.
  27. //-----------------------------------------------------------------------------
  28. static BOOL CountObject(CMapClass *pobj, unsigned int dwParam)
  29. {
  30. CMapInfoDlg *pdlg = (CMapInfoDlg *)dwParam;
  31. if (pdlg != NULL)
  32. {
  33. if (pobj->IsMapClass(MAPCLASS_TYPE(CMapSolid)))
  34. {
  35. pdlg->CountSolid((CMapSolid *)pobj);
  36. }
  37. else if (pobj->IsMapClass(MAPCLASS_TYPE(CMapEntity)))
  38. {
  39. pdlg->CountEntity((CMapEntity *)pobj);
  40. }
  41. }
  42. return TRUE;
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose: Constructor.
  46. // Input : pWorld -
  47. // pParent
  48. //-----------------------------------------------------------------------------
  49. CMapInfoDlg::CMapInfoDlg(CMapWorld *pWorld, CWnd* pParent /*=NULL*/)
  50. : CDialog(CMapInfoDlg::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(CMapInfoDlg)
  53. // NOTE: the ClassWizard will add member initialization here
  54. //}}AFX_DATA_INIT
  55. this->pWorld = pWorld;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose: Gathers statistics about an entity.
  59. // Input : *pEntity - Entity to count.
  60. //-----------------------------------------------------------------------------
  61. void CMapInfoDlg::CountEntity(CMapEntity *pEntity)
  62. {
  63. if (pEntity->IsPlaceholder())
  64. {
  65. m_uPointEntityCount++;
  66. }
  67. else
  68. {
  69. m_uSolidEntityCount++;
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose: Gathers statistics about a face.
  74. // Input : *pFace - Face to count.
  75. //-----------------------------------------------------------------------------
  76. void CMapInfoDlg::CountFace(CMapFace *pFace)
  77. {
  78. if (pFace->GetTexture() != NULL)
  79. {
  80. CountTexture(pFace->GetTexture());
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose: Gathers statistics about a brush.
  85. // Input : *pSolid - Brush to count.
  86. //-----------------------------------------------------------------------------
  87. void CMapInfoDlg::CountSolid(CMapSolid *pSolid)
  88. {
  89. m_uSolidCount++;
  90. UINT uFaceCount = pSolid->GetFaceCount();
  91. m_uFaceCount += uFaceCount;
  92. for (UINT uFace = 0; uFace < uFaceCount; uFace++)
  93. {
  94. CMapFace *pFace = pSolid->GetFace(uFace);
  95. if (pFace != NULL)
  96. {
  97. CountFace(pFace);
  98. }
  99. }
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose: Gathers statistics about this texture. Increments the count of
  103. // unique textures in the map and total texture memory used. Adds this
  104. // texture's WAD file to the list of used WADs.
  105. // Input : *pTex - Texture to count.
  106. //-----------------------------------------------------------------------------
  107. void CMapInfoDlg::CountTexture(IEditorTexture *pTex)
  108. {
  109. //
  110. // If this texture is in our list, don't do anything - it has been tallied.
  111. //
  112. for (UINT uTexture = 0; uTexture < m_uUniqueTextures; uTexture++)
  113. {
  114. if (m_pTextures[uTexture] == pTex)
  115. {
  116. return;
  117. }
  118. }
  119. //
  120. // Add the texture to our list of used textures.
  121. //
  122. m_pTextures[m_uUniqueTextures] = pTex;
  123. m_uUniqueTextures++;
  124. //
  125. // Calculate memory used by this texture.
  126. //
  127. short nWidth = pTex->GetWidth();
  128. short nHeight = pTex->GetHeight();
  129. m_uTextureMemory += nWidth * nHeight * 3;
  130. //
  131. // Add the filename to the list box if it isn't already there.
  132. //
  133. const char *pszFileName = pTex->GetFileName();
  134. if (pszFileName[0] != '\0')
  135. {
  136. if (m_WadsUsed.FindStringExact(0, pszFileName) == LB_ERR)
  137. {
  138. m_WadsUsed.AddString(pszFileName);
  139. }
  140. }
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Sets up child windows.
  144. // Input : pDX -
  145. //-----------------------------------------------------------------------------
  146. void CMapInfoDlg::DoDataExchange(CDataExchange *pDX)
  147. {
  148. CDialog::DoDataExchange(pDX);
  149. //{{AFX_DATA_MAP(CMapInfoDlg)
  150. DDX_Control(pDX, IDC_FACES, m_Faces);
  151. DDX_Control(pDX, IDC_SOLIDS, m_Solids);
  152. DDX_Control(pDX, IDC_SOLIDENTITIES, m_SolidEntities);
  153. DDX_Control(pDX, IDC_POINTENTITIES, m_PointEntities);
  154. DDX_Control(pDX, IDC_UNIQUETEXTURES, m_UniqueTextures);
  155. DDX_Control(pDX, IDC_TEXTUREMEMORY, m_TextureMemory);
  156. DDX_Control(pDX, IDC_WADSUSED, m_WadsUsed);
  157. //}}AFX_DATA_MAP
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: Tallies up statistics about this map and puts it in the dialog
  161. // controls for display.
  162. //-----------------------------------------------------------------------------
  163. BOOL CMapInfoDlg::OnInitDialog(void)
  164. {
  165. CDialog::OnInitDialog();
  166. m_uSolidCount = 0;
  167. m_uPointEntityCount = 0;
  168. m_uSolidEntityCount = 0;
  169. m_uFaceCount = 0;
  170. m_uUniqueTextures = 0;
  171. m_uTextureMemory = 0;
  172. // count objects!
  173. pWorld->EnumChildren(ENUMMAPCHILDRENPROC(CountObject), (DWORD)this);
  174. char szBuf[128];
  175. ultoa(m_uSolidCount, szBuf, 10);
  176. m_Solids.SetWindowText(szBuf);
  177. ultoa(m_uSolidEntityCount, szBuf, 10);
  178. m_SolidEntities.SetWindowText(szBuf);
  179. ultoa(m_uPointEntityCount, szBuf, 10);
  180. m_PointEntities.SetWindowText(szBuf);
  181. ultoa(m_uFaceCount, szBuf, 10);
  182. m_Faces.SetWindowText(szBuf);
  183. ultoa(m_uUniqueTextures, szBuf, 10);
  184. m_UniqueTextures.SetWindowText(szBuf);
  185. ultoa(m_uTextureMemory, szBuf, 10);
  186. sprintf(szBuf, "%u bytes (%.2f MB)", m_uTextureMemory, (float)m_uTextureMemory / 1024000.0);
  187. m_TextureMemory.SetWindowText(szBuf);
  188. return TRUE;
  189. }