endebug.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /**
  2. * \defgroup Debug Debug utilities
  3. * @{
  4. */
  5. /**
  6. \brief Prints current call stack (stack trace)
  7. \return \p void
  8. @code
  9. DumpStack();
  10. @endcode
  11. \verbatim
  12. Output:
  13. -- Stack trace --
  14. SaveFile() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler.c : 51
  15. SaveConfigToFile() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 114
  16. SaveParameterArray() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 133
  17. SetParameterArray() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 231
  18. PresetAdd() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile\ModuleLocalProfileUI.h : 46
  19. OnKeyPress() Scripts/mission/missionGameplay.c : 215
  20. OnKeyPress() Scripts/DayZGame.c : 334
  21. -----------------
  22. \endverbatim
  23. */
  24. proto void DumpStack();
  25. /**
  26. \brief Prints current call stack (stack trace) to given output
  27. \return \p void
  28. @code
  29. string tmp;
  30. DumpStackString(tmp);
  31. Print(tmp);
  32. @endcode
  33. \verbatim
  34. Output:
  35. SaveFile() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler.c : 51
  36. SaveConfigToFile() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 114
  37. SaveParameterArray() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 133
  38. SetParameterArray() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile.c : 231
  39. PresetAdd() Scripts\Entities\Modules\ModuleBase\ModuleFileHandler\ModuleLocalProfile\ModuleLocalProfileUI.h : 46
  40. OnKeyPress() Scripts/mission/missionGameplay.c : 215
  41. OnKeyPress() Scripts/DayZGame.c : 334
  42. \endverbatim
  43. */
  44. proto void DumpStackString(out string stack);
  45. //! Triggers breakpoint in C++ in run time(when app is running in debug enviroment)
  46. proto void DebugBreak(bool condition = true, void param1 = NULL, void param2 = NULL, void param3 = NULL, void param4 = NULL, void param5 = NULL, void param6 = NULL, void param7 = NULL, void param8 = NULL, void param9 = NULL);
  47. //! Triggers breakpoint in C++ in compile time(when app is running in debug enviroment)
  48. void CompileBreak();
  49. //! Prints content of variable to console/log. Should be used for critical messages so it will appear in debug log
  50. proto void DPrint(string var);
  51. enum ErrorExSeverity
  52. {
  53. INFO,
  54. WARNING,
  55. ERROR,
  56. }
  57. /**
  58. \brief Error message, prefixed by method name, above 'INFO' will show a messagebox
  59. \note Format: [%className%::%methodName%] :: [%severity%] :: %errString%
  60. \param \p string Error message to use
  61. @code
  62. class ErrorExTest
  63. {
  64. void ThrowWarning()
  65. {
  66. // [ErrorExTest::ThrowWarning] :: [WARNING] :: This is a warning.
  67. ErrorEx("This is a warning.", ErrorExSeverity.WARNING);
  68. }
  69. }
  70. @endcode
  71. */
  72. proto void ErrorEx(string err, ErrorExSeverity severity = ErrorExSeverity.ERROR);
  73. proto void ErrorExString(string err, out string str, ErrorExSeverity severity = ErrorExSeverity.ERROR);
  74. //! Messagebox with error message
  75. proto native void Error2(string title, string err);
  76. //! Messagebox with error message
  77. void Error(string err)
  78. {
  79. Error2("", err);
  80. }
  81. //!Prints content of variable to console/log
  82. proto void Print(void var);
  83. //!Prints content of variable to RPT file (performance warning - each write means fflush! use with care)
  84. proto void PrintToRPT(void var);
  85. /**
  86. \brief Prints formated text to console/log
  87. @code
  88. string c = "Peter";
  89. PrintFormat("Hello %1, how are you?", c); // prints "Hello 'Peter', how are you?"
  90. @endcode
  91. */
  92. proto void PrintFormat(string fmt, void param1 = NULL, void param2 = NULL, void param3 = NULL, void param4 = NULL, void param5 = NULL, void param6 = NULL, void param7 = NULL, void param8 = NULL, void param9 = NULL);
  93. //------------------------------------------
  94. /**
  95. * \defgroup DebugShape Debug Shape API definition
  96. * @{
  97. */
  98. enum ShapeType
  99. {
  100. BBOX, //< Just box
  101. LINE, //< One or more lines
  102. SPHERE, //< Sphere represented by triangle mesh
  103. CYLINDER, //< Cylinder represented by triangle mesh
  104. DIAMOND, //< Eight faced pyramid. Defined by bound-box, where middle part is equal to horizontal extents of box and top/bottom apogees lies on top/bottom side of box.
  105. PYRAMID //< Four sided pyramid. Defined by bound-box, where base is equal to bottom side of box.
  106. };
  107. enum ShapeFlags
  108. {
  109. NOZBUFFER, //< Do not compare z-buffer when render
  110. NOZWRITE, //< Do not update z-buffer when render
  111. WIREFRAME, //< Render just wire-frame outline. No solid faces
  112. TRANSP, //< Is translucent
  113. DOUBLESIDE, //< Double-sided (do not cull back-faces)
  114. ONCE, //< Rendered just once and then it's automatically destroyed. Do not keep pointer to these!!
  115. NOOUTLINE, //< Render just solid faces. No wire-frame outline.
  116. BACKFACE, //< Render just back faces
  117. NOCULL, //< Do not cull shapes by view frustum
  118. VISIBLE, //< Make it visible. Set by default
  119. ADDITIVE //< Additive blending (works with ShapeFlags.TRANSP)
  120. };
  121. enum CollisionFlags
  122. {
  123. FIRSTCONTACT, //<In many cases only collided=true/false is enough
  124. NEARESTCONTACT //<We want only one, the nearest contact
  125. ONLYSTATIC //<Only static objects
  126. ONLYDYNAMIC //<Only dynamic objects
  127. ONLYWATER //<Only water components (legacy support for "walk on geometry")
  128. ALLOBJECTS //<Valid when CF_FIRST_CONTACT, we get first contact for each object
  129. }
  130. /*!
  131. Instance of created debug visualizer
  132. */
  133. class Shape
  134. {
  135. //!don't call destructor directly. Use Destroy() instead
  136. proto private void ~Shape();
  137. proto native void GetMatrix(out vector mat[4]);
  138. proto native void SetMatrix(vector mat[4]);
  139. proto native void SetDirection(vector direction);
  140. proto native void SetPosition(vector position);
  141. proto native void SetColor(int color);
  142. proto native void SetFlags(ShapeFlags flags);
  143. proto native void Destroy();
  144. proto static native Shape Create(ShapeType type, int color, ShapeFlags flags, vector p1, vector p2);
  145. proto static native Shape CreateLines(int color, ShapeFlags flags, vector p[], int num);
  146. proto static native Shape CreateTris(int color, ShapeFlags flags, vector p[], int num);
  147. proto static native Shape CreateSphere(int color, ShapeFlags flags, vector origin, float radius);
  148. proto static native Shape CreateFrustum(float horizontalAngle, float verticalAngle, float length, int color, ShapeFlags flags);
  149. proto static native Shape CreateCylinder(int color, ShapeFlags flags, vector origin, float radius, float length);
  150. static Shape CreateArrow(vector from, vector to, float size, int color, ShapeFlags flags)
  151. {
  152. vector dir = to - from;
  153. dir.Normalize();
  154. vector dir1 = dir * size;
  155. size = size * 0.5;
  156. vector dir2 = dir.Perpend() * size;
  157. vector pts[5];
  158. pts[0] = from;
  159. pts[1] = to;
  160. pts[2] = to - dir1 - dir2;
  161. pts[3] = to - dir1 + dir2;
  162. pts[4] = to;
  163. return CreateLines(color, flags, pts, 5);
  164. }
  165. static Shape CreateBridgeArrow(vector from, vector to, float size, int color, ShapeFlags flags)
  166. {
  167. vector dir = to - from;
  168. dir.Normalize();
  169. vector dir1 = Vector(0, 0, -size);
  170. size = size * 0.5;
  171. vector dir2 = dir.Perpend() * size;
  172. vector pts[7];
  173. pts[0] = from;
  174. pts[1] = from + "0 0 1";
  175. pts[2] = to + "0 0 1";
  176. pts[3] = to;
  177. pts[4] = to - dir1 - dir2;
  178. pts[5] = to - dir1 + dir2;
  179. pts[6] = to;
  180. return CreateLines(color, flags, pts, 7);
  181. }
  182. static void CreateMatrix(vector mat[4])
  183. {
  184. vector org = mat[3];
  185. int flags = ShapeFlags.NOZWRITE|ShapeFlags.DOUBLESIDE|ShapeFlags.TRANSP|ShapeFlags.ONCE;
  186. Create(ShapeType.LINE, 0xffff0000, flags, org, mat[0] * 0.5 + org);
  187. Create(ShapeType.LINE, 0xff00ff00, flags, org, mat[1] * 0.5 + org);
  188. Create(ShapeType.LINE, 0xff0000ff, flags, org, mat[2] * 0.5 + org);
  189. }
  190. };
  191. //@}
  192. //------------------------------------------
  193. /**
  194. * \defgroup DiagMenu Diag menu API definition
  195. * @{
  196. */
  197. class DiagMenu
  198. {
  199. //! Checks if DiagMenu is initialized
  200. static proto bool IsInitialized();
  201. //! To be used before registering scripted diags
  202. static proto void InitScriptDiags();
  203. //! To be used when scripted diags should not be present
  204. static proto void ClearScriptDiags();
  205. /**
  206. \brief Register a new menu
  207. \param id \p int The unique ID of the menu in the range [0,512]
  208. \param name \p string The name of the menu
  209. \param parent \p int The index of the parent of the menu
  210. */
  211. static proto void RegisterMenu(int id, string name, int parent);
  212. /**
  213. \brief Register a new item
  214. \param id \p int The unique ID of the item in the range [0,512]
  215. \param shortcut \p string The keyboard shortcut of the item
  216. \param name \p string The name of the item
  217. \param parent \p int The index of the parent of the item
  218. \param values \p string The values of the item separated by commas, internally this will be an int starting at 0 for the first item
  219. \param callback \p func Callback to call when the value is changed (OPTIONAL) (Also read BindCallback)
  220. */
  221. static proto void RegisterItem(int id, string shortcut, string name, int parent, string values, func callback = null);
  222. /**
  223. \brief Register a new bool item
  224. \note This is just a RegisterItem with value="true,false" or when reversed value="false,true"
  225. \param id \p int The unique ID of the item in the range [0,512]
  226. \param shortcut \p string The keyboard shortcut of the item
  227. \param name \p string The name of the item
  228. \param parent \p string The index of the parent of the item
  229. \param values \p string The values of the item, separated by commas
  230. \param reverse \p bool Whether to reverse the bool (OPTIONAL)
  231. \param callback \p func Callback to call when the value is changed (OPTIONAL) (Also read BindCallback)
  232. */
  233. static proto void RegisterBool(int id, string shortcut, string name, int parent, bool reverse = false, func callback = null);
  234. /**
  235. \brief Register a new range item
  236. \param id \p int The unique ID of the item in the range [0,512]
  237. \param shortcut \p string The keyboard shortcut of the item
  238. \param name \p string The name of the item
  239. \param parent \p int The index of the parent of the item
  240. \param values \p string Range specification in format "min,max,startValue,step"
  241. \param callback \p func Callback to call when the value is changed (OPTIONAL) (Also read BindCallback)
  242. */
  243. static proto void RegisterRange(int id, string shortcut, string name, int parent, string valuenames, func callback = null);
  244. //! Unregister the item at given id
  245. static proto void Unregister(int id);
  246. //! Check if the item at given id has been registered
  247. static proto bool IsRegistered(int id);
  248. /**
  249. *\brief Bind a callback to the given id
  250. * \note Only one callback can be registered, so when attempting to registering multiple, only the last one will be present
  251. * \note The callbacks are required to have one of following signatures
  252. * - All Register... support:
  253. * o static void Callback();
  254. * - RegisterItem & RegisterBool:
  255. * o static void Callback(int value);
  256. * o static void Callback(int value, int id);
  257. * o static void Callback(bool value);
  258. * o static void Callback(bool value, int id);
  259. * - RegisterRange:
  260. * o static void Callback(float value);
  261. * o static void Callback(float value, int id);
  262. * o static void Callback(int value);
  263. * o static void Callback(int value, int id);
  264. * \note Keep in mind that bool and int are interchangeable, so 'bool value' is possible for RegisterRange too
  265. */
  266. static proto bool BindCallback(int id, func callback);
  267. //! Unbind the callback from the given id
  268. static proto void UnbindCallback(int id);
  269. //! Get value as bool from the given script id
  270. static proto bool GetBool(int id, bool reverse = false);
  271. //! Get value as int from the given script id
  272. static proto int GetValue(int id);
  273. //! Set value at the given script id
  274. static proto void SetValue(int id, int value);
  275. //! Get range value at the given script id
  276. static proto float GetRangeValue(int id);
  277. //! Set range value at the given script id
  278. static proto void SetRangeValue(int id, float value);
  279. //! Get value at the given engine id
  280. static proto int GetEngineValue(int id);
  281. //! Set value at the given engine id
  282. static proto void SetEngineValue(int id, int value);
  283. //! Get range value at the given engine id
  284. static proto float GetEngineRangeValue(int id);
  285. //! Set range value at the given engine id
  286. static proto void SetEngineRangeValue(int id, float value);
  287. //! Check if a menu with supplied name already exists
  288. static proto bool MenuExists(string name);
  289. };
  290. //@}
  291. //@}