dx8rendererdebugger.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. #include "dx8rendererdebugger.h"
  19. #include "hashtemplate.h"
  20. #include "mesh.h"
  21. #include "meshmdl.h"
  22. static HashTemplateClass<unsigned, MeshClass*> MeshHash;
  23. bool DX8RendererDebugger::Enabled;
  24. void DX8RendererDebugger::Enable(bool enable)
  25. {
  26. Enabled=true;
  27. }
  28. void DX8RendererDebugger::Get_String(StringClass& s)
  29. {
  30. if (!Enabled) {
  31. s="";
  32. return;
  33. }
  34. s="\n\n\n\n";
  35. int cnt=0;
  36. HashTemplateIterator<unsigned,MeshClass*> ite(MeshHash);
  37. for (ite.First();!ite.Is_Done();ite.Next()) {
  38. StringClass tmp(0,true);
  39. MeshClass* mesh=ite.Peek_Value();
  40. MeshModelClass* mmc=mesh->Peek_Model();
  41. int polys=0;
  42. int verts=0;
  43. if (mmc) {
  44. polys=mmc->Get_Polygon_Count();
  45. verts=mmc->Get_Vertex_Count();
  46. }
  47. tmp.Format("id: %5.5d mesh: %s %d polys, %d verts",
  48. ite.Peek_Key(),
  49. mesh->Get_Name(),
  50. polys,
  51. verts);
  52. s+=tmp;
  53. if (mesh->Is_Disabled_By_Debugger()) {
  54. s+=" (disabled)\n";
  55. }
  56. else {
  57. s+="\n";
  58. }
  59. cnt++;
  60. if (cnt>20) break;
  61. }
  62. }
  63. void DX8RendererDebugger::Update()
  64. {
  65. // Release references to all meshes and empty the hash
  66. HashTemplateIterator<unsigned,MeshClass*> ite(MeshHash);
  67. for (ite.First();!ite.Is_Done();ite.Next()) {
  68. ite.Peek_Value()->Release_Ref();
  69. }
  70. MeshHash.Remove_All();
  71. // if (!Enabled) return;
  72. }
  73. #ifdef WWDEBUG
  74. void DX8RendererDebugger::Add_Mesh(MeshClass* mesh)
  75. {
  76. if (!Enabled) return;
  77. // Don't insert the same mesh twice
  78. if (MeshHash.Get(mesh->Get_Debug_Id())) return;
  79. mesh->Add_Ref();
  80. MeshHash.Insert(mesh->Get_Debug_Id(),mesh);
  81. }
  82. #endif
  83. void DX8RendererDebugger::Disable_Mesh(unsigned id)
  84. {
  85. if (!Enabled) return;
  86. MeshClass* mesh=MeshHash.Get(id);
  87. if (!mesh) return;
  88. mesh->Set_Debugger_Disable(true);
  89. }
  90. void DX8RendererDebugger::Enable_Mesh(unsigned id)
  91. {
  92. if (!Enabled) return;
  93. MeshClass* mesh=MeshHash.Get(id);
  94. if (!mesh) return;
  95. mesh->Set_Debugger_Disable(false);
  96. }
  97. void DX8RendererDebugger::Disable_All()
  98. {
  99. if (!Enabled) return;
  100. HashTemplateIterator<unsigned,MeshClass*> ite(MeshHash);
  101. for (ite.First();!ite.Is_Done();ite.Next()) {
  102. ite.Peek_Value()->Set_Debugger_Disable(true);
  103. }
  104. }
  105. void DX8RendererDebugger::Enable_All()
  106. {
  107. if (!Enabled) return;
  108. HashTemplateIterator<unsigned,MeshClass*> ite(MeshHash);
  109. for (ite.First();!ite.Is_Done();ite.Next()) {
  110. ite.Peek_Value()->Set_Debugger_Disable(false);
  111. }
  112. }