systeminfolog.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. #include "systeminfolog.h"
  19. #include "registry.h"
  20. #include "timemgr.h"
  21. #include "debug.h"
  22. #include "playerdata.h"
  23. #include "combat.h"
  24. #include "cheatmgr.h"
  25. #include "objectives.h"
  26. #include "ffactory.h"
  27. #include "savegame.h"
  28. //#pragma warning (disable : 4201) // nonstandard extension - nameless struct
  29. //#include "systimer.h"
  30. #include "systimer.h"
  31. #include "specialbuilds.h"
  32. const unsigned NUM_GAMES_LOGGED=10;
  33. //#define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\Renegade\\Debug"
  34. #if defined(FREEDEDICATEDSERVER)
  35. #define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\RenegadeFDS\\Debug"
  36. #elif defined(MULTIPLAYERDEMO)
  37. #define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\RenegadeMPDemo\\Debug"
  38. #elif defined(BETACLIENT)
  39. #define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\RenegadeBeta\\Debug"
  40. #elif defined(BETASERVER)
  41. #define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\RenegadeBeta\\Debug"
  42. #else
  43. #define COMBAT_SUB_KEY_NAME_DEBUG "Software\\Westwood\\Renegade\\Debug"
  44. #endif
  45. #define SYSTEM_INFO_LOG_CURRENT_STATE "SystemInfoLog_CurrentState"
  46. #define SYSTEM_INFO_LOG_LATEST_GAME "SystemInfoLog_LatestGame"
  47. static int Team0TotalSizes;
  48. static int Team0SizeReported;
  49. static int Team1TotalSizes;
  50. static int Team1SizeReported;
  51. static unsigned AvgFPS;
  52. static unsigned MinFPS;
  53. static unsigned VeryMinFPS;
  54. static unsigned MaxFPS;
  55. static unsigned VeryMaxFPS;
  56. static unsigned CurrentTotalFPS;
  57. static unsigned CurrentFPSCount;
  58. static unsigned CurrentLoadingTime;
  59. static unsigned PlayingStartTime;
  60. static unsigned TotalPlayingTime;
  61. static StringClass CurrentLevel;
  62. static StringClass CurrentString;
  63. static void Get_Latest_Game_String(RegistryClass& reg, int i, StringClass& string)
  64. {
  65. StringClass keyname(0,true);
  66. keyname.Format("%s%d",SYSTEM_INFO_LOG_LATEST_GAME,i+1);
  67. reg.Get_String(keyname, string);
  68. }
  69. static void Set_Latest_Game_String(RegistryClass& reg, int i, const StringClass& string)
  70. {
  71. StringClass keyname(0,true);
  72. keyname.Format("%s%d",SYSTEM_INFO_LOG_LATEST_GAME,i+1);
  73. reg.Set_String(keyname, string);
  74. }
  75. void SystemInfoLog::Set_State_Loading()
  76. {
  77. VeryMinFPS=1000;
  78. MinFPS=1000;
  79. VeryMaxFPS=0;
  80. MaxFPS=0;
  81. CurrentTotalFPS=0;
  82. CurrentFPSCount=0;
  83. CurrentLoadingTime=0;
  84. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  85. if ( registry.Is_Valid() ) {
  86. registry.Set_Int( SYSTEM_INFO_LOG_CURRENT_STATE, 1 );
  87. StringClass string(0,true);
  88. for (int i=NUM_GAMES_LOGGED-1;i>0;--i) {
  89. Get_Latest_Game_String(registry,i-1,string);
  90. Set_Latest_Game_String(registry,i,string);
  91. }
  92. Get_Final_String(CurrentString);
  93. CurrentString+="Crashed while loading";
  94. Set_Latest_Game_String(registry, 0, CurrentString );
  95. }
  96. }
  97. void SystemInfoLog::Set_Current_Level(const char* level_name)
  98. {
  99. CurrentLevel=level_name;
  100. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  101. if ( registry.Is_Valid() ) {
  102. Get_Final_String(CurrentString);
  103. CurrentString+="Crashed while loading";
  104. Set_Latest_Game_String(registry,0,CurrentString );
  105. }
  106. }
  107. void SystemInfoLog::Set_State_Playing()
  108. {
  109. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  110. if ( registry.Is_Valid() ) {
  111. registry.Set_Int( SYSTEM_INFO_LOG_CURRENT_STATE, 2 );
  112. Get_Final_String(CurrentString);
  113. CurrentString+="Crashed while playing";
  114. Set_Latest_Game_String(registry,0,CurrentString );
  115. }
  116. PlayingStartTime=TIMEGETTIME();
  117. }
  118. void SystemInfoLog::Get_Final_String(StringClass& string)
  119. {
  120. StringClass vnum(0,true);
  121. StringClass ptime(0,true);
  122. StringClass avgfps(0,true);
  123. vnum.Format("%d.%2.2d",DebugManager::Get_Version_Number()>>16,DebugManager::Get_Version_Number()&0xffff);
  124. ptime.Format("%2.2d:%2.2d",TotalPlayingTime/60,TotalPlayingTime%60);
  125. avgfps.Format("%d.%1.1d",AvgFPS/10,AvgFPS%10);
  126. string.Format(
  127. "%5s %16s %6s %6d %6d %6s %8d ",
  128. vnum,
  129. CurrentLevel,
  130. ptime,
  131. MinFPS!=1000 ? MinFPS : 0,
  132. MaxFPS,
  133. avgfps,
  134. CurrentLoadingTime);
  135. }
  136. void SystemInfoLog::Set_State_Exiting()
  137. {
  138. TotalPlayingTime=(TIMEGETTIME()-PlayingStartTime)/1000;
  139. AvgFPS=0;
  140. if (CurrentFPSCount) {
  141. AvgFPS=CurrentTotalFPS*10/CurrentFPSCount;
  142. }
  143. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  144. if ( registry.Is_Valid() ) {
  145. registry.Set_Int( SYSTEM_INFO_LOG_CURRENT_STATE, 3 );
  146. Get_Final_String(CurrentString);
  147. CurrentString+="Crashed while exiting.";
  148. Set_Latest_Game_String(registry,0,CurrentString);
  149. }
  150. }
  151. void SystemInfoLog::Reset_State()
  152. {
  153. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  154. if ( registry.Is_Valid() ) {
  155. int old_state=registry.Get_Int( SYSTEM_INFO_LOG_CURRENT_STATE);
  156. registry.Set_Int( SYSTEM_INFO_LOG_CURRENT_STATE, 0 );
  157. // If was exiting...
  158. if (old_state==3) {
  159. Get_Final_String(CurrentString);
  160. CurrentString+="OK";
  161. Set_Latest_Game_String(registry,0,CurrentString);
  162. }
  163. }
  164. CurrentLevel="";
  165. }
  166. void SystemInfoLog::Record_Loading_Time(unsigned loading_time)
  167. {
  168. CurrentLoadingTime=loading_time;
  169. }
  170. void SystemInfoLog::Record_Frame()
  171. {
  172. unsigned fps=TimeManager::Get_Average_Frame_Rate();
  173. CurrentTotalFPS+=fps;
  174. CurrentFPSCount++;
  175. if (fps<VeryMinFPS) {
  176. VeryMinFPS=fps;
  177. }
  178. else if (fps<MinFPS) {
  179. MinFPS=fps;
  180. }
  181. if (fps>VeryMaxFPS) {
  182. VeryMaxFPS=fps;
  183. }
  184. else if (fps>MaxFPS) {
  185. MaxFPS=fps;
  186. }
  187. }
  188. void SystemInfoLog::Get_Log(StringClass& string)
  189. {
  190. RegistryClass registry( COMBAT_SUB_KEY_NAME_DEBUG );
  191. if ( registry.Is_Valid() ) {
  192. string.Format(
  193. "Ten latest levels played:\r\n"
  194. "%3s %5s %16s %6s %6s %6s %6s %8s %s\r\n",
  195. "#",
  196. "Build",
  197. "Level",
  198. "Length",
  199. "MinFPS",
  200. "MaxFPS",
  201. "AvgFPS",
  202. "LoadTime",
  203. "Status");
  204. StringClass tmp_string(0,true);
  205. for (int i=0;i<NUM_GAMES_LOGGED;++i) {
  206. Get_Latest_Game_String(registry,i,tmp_string);
  207. StringClass tmp_string2(0,true);
  208. tmp_string2.Format("%2d. ",i+1);
  209. string+=tmp_string2;
  210. string+=tmp_string;
  211. string+="\r\n";
  212. }
  213. }
  214. }
  215. void SystemInfoLog::Get_Compact_Log(StringClass& string)
  216. {
  217. int fps=0;
  218. if (CurrentFPSCount) {
  219. fps=CurrentTotalFPS*10/CurrentFPSCount;
  220. }
  221. string.Format("%d.%d\t",fps/10,fps%10);
  222. }
  223. // This stuff should go to the playerinfolog...
  224. static StringClass CurrentMapName;
  225. void PlayerInfoLog::Set_Current_Map_Name(const char* map_name)
  226. {
  227. CurrentMapName=map_name;
  228. StringClass tmp_name(0,true);
  229. if (SaveGameManager::Peek_Map_Name (CurrentMapName, tmp_name)) {
  230. CurrentMapName = tmp_name;
  231. }
  232. }
  233. #define ADD_HISTORY(n) work.Format n; tmp+=work;
  234. void PlayerInfoLog::Append_To_Log(PlayerDataClass* data)
  235. {
  236. if (data->Get_Game_Time()==0.0f) return;
  237. #ifdef WWDEBUG
  238. StringClass tmp;
  239. StringClass work(0,true);
  240. ADD_HISTORY(("Map name: %s\r\n",CurrentMapName));
  241. ADD_HISTORY(("Game time: %2.2f\r\n",data->Get_Game_Time()));
  242. ADD_HISTORY(("Session time: %2.2f\r\n",data->Get_Session_Time()));
  243. ADD_HISTORY(("Enemies killed: %d\r\n",data->Get_Enemies_Killed()));
  244. ADD_HISTORY(("Allies killed: %d\r\n",data->Get_Allies_Killed()));
  245. ADD_HISTORY(("Shots fired: %d\r\n",data->Get_Shots_Fired()));
  246. ADD_HISTORY(("Powerups collected: %d\r\n",data->Get_Powerups_Collected()));
  247. ADD_HISTORY(("Vehicles destroyed: %d\r\n",data->Get_Vehiclies_Destroyed()));
  248. ADD_HISTORY(("Buildings destroyed: %d\r\n",data->Get_Building_Destroyed()));
  249. ADD_HISTORY(("Time in vehicles: %d\r\n",data->Get_Vehicle_Time()));
  250. ADD_HISTORY(("Kills from vehicles: %d\r\n",data->Get_Kills_From_Vehicle()));
  251. ADD_HISTORY(("Squishes: %d\r\n",data->Get_Squishes()));
  252. ADD_HISTORY(("Credits granted: %d\r\n",data->Get_Credit_Grant()));
  253. ADD_HISTORY(("Times reloaded: %d\r\n",CombatManager::Get_Reload_Count()));
  254. ADD_HISTORY(("Cheats used: %s\r\n",CheatMgrClass::Get_Instance()->Was_Cheat_Used( CheatMgrClass::ALL_CHEATS ) ? "Yes" : "No"));
  255. ADD_HISTORY(("Secondary objectives completed: %d\r\n",ObjectiveManager::Get_Num_Completed_Objectives( ObjectiveManager::TYPE_SECONDARY )));
  256. ADD_HISTORY(("Tertiary objectives completed: %d\r\n",ObjectiveManager::Get_Num_Completed_Objectives( ObjectiveManager::TYPE_TERTIARY )));
  257. tmp+="\r\n";
  258. DWORD written;
  259. HANDLE file = CreateFile("history.txt", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
  260. FILE_ATTRIBUTE_NORMAL, NULL);
  261. if (INVALID_HANDLE_VALUE != file) {
  262. SetFilePointer(file, 0, NULL, FILE_END);
  263. WriteFile(file, tmp, strlen(tmp), &written, NULL);
  264. CloseHandle(file);
  265. }
  266. #endif // WWDEBUG
  267. }
  268. void PlayerInfoLog::Get_Compact_Log(StringClass& string)
  269. {
  270. int team0size=0;
  271. int team1size=0;
  272. if (Team0SizeReported) {
  273. team0size=10*Team0TotalSizes/Team0SizeReported;
  274. }
  275. if (Team1SizeReported) {
  276. team1size=10*Team1TotalSizes/Team1SizeReported;
  277. }
  278. string.Format("%s\t%d.%d\t%d.%d\t",CurrentMapName,team0size/10,team0size%10,team1size/10,team1size%10);
  279. Team0SizeReported=0;
  280. Team1SizeReported=0;
  281. Team0TotalSizes=0;
  282. Team1TotalSizes=0;
  283. }
  284. void PlayerInfoLog::Report_Tally_Size(int type, int size)
  285. {
  286. if (type==0) {
  287. Team0TotalSizes+=size;
  288. Team0SizeReported++;
  289. }
  290. else if (type==1) {
  291. Team1TotalSizes+=size;
  292. Team1SizeReported++;
  293. }
  294. }