wwdebug.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. *** 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:: 9/03/01 1:59p $*
  29. * *
  30. * $Revision:: 19 $*
  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. void WWDebug_Printf(const char * format,...);
  76. void WWDebug_Printf_Warning(const char * format,...);
  77. void WWDebug_Printf_Error(const char * format,...);
  78. #ifdef WWDEBUG
  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. #ifdef WWDEBUG
  95. #define WWDEBUG_SAY(x) WWDebug_Printf x
  96. #define WWDEBUG_WARNING(x) WWDebug_Printf_Warning x
  97. #define WWDEBUG_ERROR(x) WWDebug_Printf_Error x
  98. #else
  99. #define WWDEBUG_SAY(x)
  100. #define WWDEBUG_WARNING(x)
  101. #define WWDEBUG_ERROR(x)
  102. #endif
  103. #define WWRELEASE_SAY(x) WWDebug_Printf x
  104. #define WWRELEASE_WARNING(x) WWDebug_Printf_Warning x
  105. #define WWRELEASE_ERROR(x) WWDebug_Printf_Error x
  106. /*
  107. ** The WWASSERT and WWASSERT_PRINT macros will send messages to your
  108. ** assert handler.
  109. */
  110. #ifdef WWDEBUG
  111. #define WWASSERT(expr) ((expr)?(void)0:WWDebug_Assert_Fail(#expr,__FILE__,__LINE__))
  112. #define WWASSERT_PRINT( expr, string ) ((expr)?(void)0:WWDebug_Assert_Fail_Print(#expr,__FILE__,__LINE__,string))
  113. #define DIE (WWDebug_Assert_Fail("DIE",__FILE__,__LINE__))
  114. #else
  115. #define WWASSERT( expr )
  116. #define WWASSERT_PRINT( expr, string )
  117. #define DIE
  118. #endif
  119. /*
  120. ** The WWDEBUG_BREAK macro will cause the application to break into
  121. ** the debugger...
  122. */
  123. #ifdef WWDEBUG
  124. #define WWDEBUG_BREAK _asm int 0x03
  125. #else
  126. #define WWDEBUG_BREAK _asm int 0x03
  127. #endif
  128. /*
  129. ** The WWDEBUG_TRIGGER macro can be used to ask the application if
  130. ** a debug trigger is set. We define a couple of generic triggers
  131. ** for casual use.
  132. */
  133. #define WWDEBUG_TRIGGER_GENERIC0 0
  134. #define WWDEBUG_TRIGGER_GENERIC1 1
  135. #ifdef WWDEBUG
  136. #define WWDEBUG_TRIGGER(x) WWDebug_Check_Trigger(x)
  137. #else
  138. #define WWDEBUG_TRIGGER(x) (0)
  139. #endif
  140. /*
  141. ** The WWDEBUG_PROFILE macros can be used to time blocks of code
  142. */
  143. #ifdef WWDEBUG
  144. #define WWDEBUG_PROFILE_START(x) WWDebug_Profile_Start(x)
  145. #define WWDEBUG_PROFILE_STOP(x) WWDebug_Profile_Stop(x)
  146. #else
  147. #define WWDEBUG_PROFILE_START(x)
  148. #define WWDEBUG_PROFILE_STOP(x)
  149. #endif
  150. #endif