debug.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/debug.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 12/18/01 10:36a $*
  29. * *
  30. * $Revision:: 27 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef DEBUG_H
  36. #define DEBUG_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef WWDEBUG_H
  41. #include "wwdebug.h"
  42. #endif
  43. #ifndef BITTYPE_H
  44. #include "bittype.h"
  45. #endif
  46. #ifndef __WIDESTRING_H
  47. #include "widestring.h"
  48. #endif
  49. #ifndef VECTOR3_H
  50. #include "vector3.h"
  51. #endif
  52. #ifndef VECTOR4_H
  53. #include "vector4.h"
  54. #endif
  55. //#ifndef _CONTEXT
  56. //struct CONTEXT;
  57. //#define TEMP_CONTEXT_DEFINE
  58. //#endif
  59. //int Stack_Walk(unsigned long *return_addresses, int num_addresses, CONTEXT *context = NULL);
  60. //#ifdef TEMP_CONTEXT_DEFINE
  61. //#undef CONTEXT
  62. //#endif
  63. /*
  64. **
  65. */
  66. class DebugDisplayHandlerClass {
  67. public:
  68. virtual void Display_Text( const char * string, const Vector4 & color = Vector4( 1,1,1,1 ) ) = 0;
  69. virtual void Display_Text( const WideStringClass & string, const Vector4 & color = Vector4( 1,1,1,1 ) ) = 0;
  70. };
  71. /*
  72. **
  73. */
  74. class DebugManager {
  75. public:
  76. static void Init( void );
  77. static void Shutdown( void );
  78. static void Update( void );
  79. static void Load_Registry_Settings( const char * sub_key );
  80. static void Save_Registry_Settings( const char * sub_key );
  81. //
  82. // Version number support. The major revision number is stored in the
  83. // hiword of the version, the minor revision number is stored in the loword.
  84. //
  85. static int Get_Version_Number (void) { return VersionNumber; }
  86. static void Set_Version_Number (int number) { VersionNumber = number; }
  87. /*
  88. ** Debug Displaying
  89. */
  90. enum DebugDevice {
  91. DEBUG_DEVICE_SCREEN = 1<<0,
  92. DEBUG_DEVICE_MONO = 1<<1,
  93. DEBUG_DEVICE_SRDEBUG = 1<<2, // OBSOLETE!
  94. DEBUG_DEVICE_DBWIN32 = 1<<3,
  95. DEBUG_DEVICE_LOG = 1<<4,
  96. DEBUG_DEVICE_WINDOWS = 1<<5,
  97. };
  98. static void Enable_Device( DebugDevice device ) { EnabledDevices |= device; }
  99. static void Disable_Device( DebugDevice device ) { EnabledDevices &= ~device; }
  100. static void Toggle_Device_Enabled( DebugDevice device ) { EnabledDevices ^= device; }
  101. static bool Is_Device_Enabled( DebugDevice device ) { return (EnabledDevices & device) != 0; }
  102. enum DebugType {
  103. DEBUG_TYPE_INFORMATION = 1<<WWDEBUG_TYPE_INFORMATION,
  104. DEBUG_TYPE_WARNING = 1<<WWDEBUG_TYPE_WARNING,
  105. DEBUG_TYPE_ERROR = 1<<WWDEBUG_TYPE_ERROR,
  106. DEBUG_TYPE_SCRIPT = 1<<(WWDEBUG_TYPE_USER+1),
  107. DEBUG_TYPE_NETWORK_ADMIN = 1<<(WWDEBUG_TYPE_USER+2),
  108. DEBUG_TYPE_NETWORK_BASIC = 1<<(WWDEBUG_TYPE_USER+3),
  109. DEBUG_TYPE_NETWORK_PROLIFIC = 1<<(WWDEBUG_TYPE_USER+4),
  110. };
  111. static void Enable_Type( DebugType type ) { EnabledTypes |= type; }
  112. static void Disable_Type( DebugType type ) { EnabledTypes &= ~type; }
  113. static void Toggle_Type_Enabled( DebugType type ) { EnabledTypes ^= type; }
  114. static bool Is_Type_Enabled( DebugType type ) { return (EnabledTypes & type) != 0; }
  115. static void Display( char const *buffer );
  116. static void Display_Script( char const *text, ... );
  117. static void Display_Network_Admin( char const *text, ... );
  118. static void Display_Network_Basic( char const *text, ... );
  119. static void Display_Network_Prolific( char const *text, ... );
  120. /*
  121. ** Debug Options
  122. ** (gth) Enable and disable debug options and triggers. Now that we've
  123. ** moved more functions to the console (rather than 10 billion key combinations)
  124. ** we need an interface for turning on and off some of the debug triggers.
  125. */
  126. enum DebugOption {
  127. DEBUG_INVERT_VIS = 1<<0,
  128. DEBUG_DISABLE_VIS = 1<<1,
  129. DEBUG_COLLISION_MESSAGES = 1<<2,
  130. DEBUG_COLLISION_DISPLAY = 1<<3,
  131. DEBUG_DISABLE_LIGHTS = 1<<4,
  132. DEBUG_PROCESS_STATS = 1<<5,
  133. DEBUG_SURFACE_CACHE = 1<<6,
  134. };
  135. static void Option_Enable( DebugOption option, bool onoff )
  136. { if ( onoff ) EnabledOptions |= option; else EnabledOptions &= ~option; }
  137. static bool Option_Is_Enabled( DebugOption option ) { return (EnabledOptions & option) != 0; }
  138. static void Option_Toggle( DebugOption option ) { EnabledOptions ^= option; }
  139. // Misc Debug Functions
  140. static void Measure_Frame_Textures( void );
  141. // Outside handler display
  142. static void Set_Display_Handler( DebugDisplayHandlerClass * handler ) { DisplayHandler = handler; }
  143. static void Display_Text(const char * string, const Vector4 & color );
  144. static void Display_Text(const char * string, const Vector3 & color = Vector3( 1,1,1 ) );
  145. static void Display_Text(const WideStringClass & string, const Vector4 & color );
  146. static void Display_Text(const WideStringClass & string, const Vector3 & color = Vector3( 1,1,1 ) );
  147. static void Init_Logfile(void);
  148. static void Write_To_File(LPCSTR str);
  149. static LPCSTR Logfile_Name(void) {return LOGFILE;}
  150. static void Enable_Memory_Logging( bool enable );
  151. static bool Is_File_Logging_Enabled( void ) { return EnableFileLogging; }
  152. static bool Is_Diag_Logging_Enabled( void ) { return EnableDiagLogging; }
  153. static bool Load_Debug_Scripts( void ) { return LoadDebugScripts; }
  154. static void Set_Is_Slave(bool isslave) {IsSlave = isslave;}
  155. static bool Allow_Cinematic_Keys( void ) { return AllowCinematicKeys; };
  156. private:
  157. static int EnabledDevices;
  158. static int EnabledTypes;
  159. static int EnabledOptions;
  160. static bool EnableFileLogging;
  161. static bool EnableDiagLogging;
  162. static bool LoadDebugScripts;
  163. static int VersionNumber;
  164. static bool AllowCinematicKeys;
  165. static DebugDisplayHandlerClass * DisplayHandler;
  166. static LPSTR LOGFILE;
  167. static char LogfileNameBuffer[256];
  168. static bool IsSlave;
  169. /*
  170. ** Thread safety
  171. */
  172. static CriticalSectionClass CriticalSection;
  173. };
  174. // macro to print
  175. #define Debug_Say WWDEBUG_SAY
  176. #define Debug_Warning WWDEBUG_WARNING
  177. #define Debug_Error WWDEBUG_ERROR
  178. #define Debug_Script(x) DebugManager::Display_Script x
  179. #define Debug_Network_Basic(x) DebugManager::Display_Network_Basic x
  180. #define Debug_Network_Prolific(x) DebugManager::Display_Network_Prolific x
  181. #endif // DEBUG_H
  182. //#define Debug_Network_Admin(x) DebugManager::Display_Network_Admin x