assetstatus.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "assetstatus.h"
  19. #include "hashtemplate.h"
  20. #include "wwstring.h"
  21. #include "rawfile.h"
  22. AssetStatusClass AssetStatusClass::Instance;
  23. const char* ReportCategoryNames[AssetStatusClass::REPORT_COUNT]={
  24. "LOAD_ON_DEMAND_ROBJ",
  25. "LOAD_ON_DEMAND_HANIM",
  26. "LOAD_ON_DEMAND_HTREE",
  27. "MISSING_ROBJ",
  28. "MISSING_HANIM",
  29. "MISSING_HTREE"
  30. };
  31. AssetStatusClass::AssetStatusClass()
  32. :
  33. Reporting (true),
  34. LoadOnDemandReporting(false)
  35. {
  36. }
  37. AssetStatusClass::~AssetStatusClass()
  38. {
  39. #ifdef WWDEBUG
  40. if (Reporting) {
  41. StringClass report("Load-on-demand and missing assets report\r\n\r\n");
  42. for (int i=0;i<REPORT_COUNT;++i) {
  43. report+="Category: ";
  44. report+=ReportCategoryNames[i];
  45. report+="\r\n\r\n";
  46. HashTemplateIterator<StringClass,int> ite(ReportHashTables[i]);
  47. for (ite.First();!ite.Is_Done();ite.Next()) {
  48. report+=ite.Peek_Key();
  49. int count=ite.Peek_Value();
  50. if (count>1) {
  51. StringClass tmp(0,true);
  52. tmp.Format("\t(reported %d times)",count);
  53. report+=tmp;
  54. }
  55. report+="\r\n";
  56. }
  57. report+="\r\n";
  58. }
  59. if (report.Get_Length()) {
  60. RawFileClass raw_log_file("asset_report.txt");
  61. raw_log_file.Create();
  62. raw_log_file.Open(RawFileClass::WRITE);
  63. raw_log_file.Write(report,report.Get_Length());
  64. raw_log_file.Close();
  65. }
  66. }
  67. #endif
  68. }
  69. void AssetStatusClass::Add_To_Report(int index, const char* name)
  70. {
  71. StringClass lower_case_name(name,true);
  72. _strlwr(lower_case_name.Peek_Buffer());
  73. // This is a bit slow - two accesses to the same member, but currently there's no better way to do it.
  74. int count=ReportHashTables[index].Get(lower_case_name);
  75. count++;
  76. ReportHashTables[index].Set_Value(lower_case_name,count);
  77. }
  78. void AssetStatusClass::Report_Load_On_Demand_RObj(const char* name)
  79. {
  80. if (LoadOnDemandReporting) Add_To_Report(REPORT_LOAD_ON_DEMAND_ROBJ,name);
  81. }
  82. void AssetStatusClass::Report_Load_On_Demand_HAnim(const char* name)
  83. {
  84. if (LoadOnDemandReporting) Add_To_Report(REPORT_LOAD_ON_DEMAND_HANIM,name);
  85. }
  86. void AssetStatusClass::Report_Load_On_Demand_HTree(const char* name)
  87. {
  88. if (LoadOnDemandReporting) Add_To_Report(REPORT_LOAD_ON_DEMAND_HTREE,name);
  89. }
  90. void AssetStatusClass::Report_Missing_RObj(const char* name)
  91. {
  92. Add_To_Report(REPORT_MISSING_ROBJ,name);
  93. }
  94. void AssetStatusClass::Report_Missing_HAnim(const char* name)
  95. {
  96. Add_To_Report(REPORT_MISSING_HANIM,name);
  97. }
  98. void AssetStatusClass::Report_Missing_HTree(const char* name)
  99. {
  100. Add_To_Report(REPORT_MISSING_HTREE,name);
  101. }