wwdebug.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. ** Command & Conquer Generals(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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWDebug *
  23. * *
  24. * $Archive:: /Commando/Code/wwdebug/wwdebug.h $*
  25. * *
  26. * $Author:: Jani_p $*
  27. * *
  28. * $Modtime:: 5/04/01 7:43p $*
  29. * *
  30. * $Revision:: 18 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef WWDEBUG_H
  39. #define WWDEBUG_H
  40. // The macro MESSAGE allows user to put:
  41. // #pragma MESSAGE("Hello world")
  42. // anywhere in a source file. The message:
  43. // sourcefname.cpp (123) : Hello world
  44. // would be printed if put in sourcefname.cpp on line 123 in compile window like an error.
  45. // You can then use next/prev error hot keys to see where comment is. It is not an error and
  46. // will be printed everytime it is compiled. Very useful to put comments in code that cannot
  47. // be forgoten.
  48. #define STRING_IT(a) #a
  49. #define TOKEN_IT(a) STRING_IT(,##a)
  50. #define MESSAGE(a) message (__FILE__ "(" TOKEN_IT(__LINE__) ") : " a)
  51. void Convert_System_Error_To_String(int error_id, char* buffer, int buf_len);
  52. int Get_Last_System_Error();
  53. /*
  54. ** If 'WWDEBUG' is turned off, all WWDEBUG_xxx macros will
  55. ** be discarded.
  56. */
  57. typedef enum {
  58. WWDEBUG_TYPE_INFORMATION,
  59. WWDEBUG_TYPE_WARNING,
  60. WWDEBUG_TYPE_ERROR,
  61. WWDEBUG_TYPE_USER
  62. } DebugType;
  63. typedef void (*PrintFunc)(DebugType type, const char * message);
  64. typedef void (*AssertPrintFunc)(const char * message);
  65. typedef bool (*TriggerFunc)(int trigger_num);
  66. typedef void (*ProfileFunc)(const char * title);
  67. PrintFunc WWDebug_Install_Message_Handler(PrintFunc func);
  68. AssertPrintFunc WWDebug_Install_Assert_Handler(AssertPrintFunc func);
  69. TriggerFunc WWDebug_Install_Trigger_Handler(TriggerFunc func);
  70. ProfileFunc WWDebug_Install_Profile_Start_Handler(ProfileFunc func);
  71. ProfileFunc WWDebug_Install_Profile_Stop_Handler(ProfileFunc func);
  72. /*
  73. ** Users should not call the following three functions directly! Use the macros below instead...
  74. */
  75. #ifdef WWDEBUG
  76. void WWDebug_Printf(const char * format,...);
  77. void WWDebug_Printf_Warning(const char * format,...);
  78. void WWDebug_Printf_Error(const char * format,...);
  79. void WWDebug_Assert_Fail(const char * expr,const char * file, int line);
  80. void WWDebug_Assert_Fail_Print(const char * expr,const char * file, int line,const char * string);
  81. bool WWDebug_Check_Trigger(int trigger_num);
  82. void WWDebug_Profile_Start( const char * title);
  83. void WWDebug_Profile_Stop( const char * title);
  84. /*
  85. ** A message handler to display to DBWIN32
  86. */
  87. void WWDebug_DBWin32_Message_Handler( const char * message);
  88. #endif
  89. /*
  90. ** Use the following #define so that all of the debugging messages
  91. ** and strings go away when the release version is built.
  92. ** WWDEBUG_SAY(("dir = %f\n",dir));
  93. */
  94. #include "..\..\..\..\gameengine\include\common\debug.h"
  95. #ifdef DEBUG_LOGGING
  96. #define WWDEBUG_SAY(x) DEBUG_LOG(x)
  97. #define WWDEBUG_WARNING(x) DEBUG_LOG(x)
  98. #else
  99. #define WWDEBUG_SAY(x)
  100. #define WWDEBUG_WARNING(x)
  101. #endif
  102. // WW3d is compiled at warning level 4, causes DEBUG_ASSERTCRASH to generate
  103. // the 4127 warning (constant conditional expression)
  104. #pragma warning(disable:4127)
  105. /*
  106. ** The WWASSERT and WWASSERT_PRINT macros will send messages to your
  107. ** assert handler.
  108. */
  109. #ifdef DEBUG_CRASHING
  110. #define WWASSERT(expr) DEBUG_ASSERTCRASH(expr, ("%s, %s, %d", #expr,__FILE__,__LINE__))
  111. #define WWASSERT_PRINT( expr, string ) DEBUG_ASSERTCRASH(expr, ("%s, %s, %d - %s", #expr,__FILE__,__LINE__,string))
  112. #define W3D_DIE DEBUG_CRASH(("DIE!, %s, %d", __FILE__,__LINE__))
  113. #define WWDEBUG_ERROR(x) DEBUG_CRASH(x)
  114. #else
  115. #define WWASSERT( expr )
  116. #define WWASSERT_PRINT( expr, string )
  117. #define W3D_DIE
  118. #define WWDEBUG_ERROR(x)
  119. #endif
  120. /*
  121. ** The WWDEBUG_BREAK macro will cause the application to break into
  122. ** the debugger...
  123. */
  124. #ifdef WWDEBUG
  125. #define WWDEBUG_BREAK _asm int 0x03
  126. #else
  127. #define WWDEBUG_BREAK _asm int 0x03
  128. #endif
  129. /*
  130. ** The WWDEBUG_TRIGGER macro can be used to ask the application if
  131. ** a debug trigger is set. We define a couple of generic triggers
  132. ** for casual use.
  133. */
  134. #define WWDEBUG_TRIGGER_GENERIC0 0
  135. #define WWDEBUG_TRIGGER_GENERIC1 1
  136. #ifdef WWDEBUG
  137. #define WWDEBUG_TRIGGER(x) WWDebug_Check_Trigger(x)
  138. #else
  139. #define WWDEBUG_TRIGGER(x) (0)
  140. #endif
  141. /*
  142. ** The WWDEBUG_PROFILE macros can be used to time blocks of code
  143. */
  144. #ifdef WWDEBUG
  145. #define WWDEBUG_PROFILE_START(x) WWDebug_Profile_Start(x)
  146. #define WWDEBUG_PROFILE_STOP(x) WWDebug_Profile_Stop(x)
  147. #else
  148. #define WWDEBUG_PROFILE_START(x)
  149. #define WWDEBUG_PROFILE_STOP(x)
  150. #endif
  151. #endif