Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

165 lignes
4.8KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * Common functions and debugging functions.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #ifndef common_h
  14. #define common_h
  15. #pragma GDCC FIXED_LITERAL ON
  16. #include <ACS_ZDoom.h>
  17. #include <stdarg.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "m_types.h"
  21. #include "m_memory.h"
  22. #include "m_drawing.h"
  23. #include "m_math.h"
  24. #include "m_str.h"
  25. #include "m_stab.h"
  26. #define LineHash ((u32)__LINE__ * FileHash)
  27. #define ifw(decl, ...) __with(decl;) if(__VA_ARGS__)
  28. #define ifauto(type, name, ...) ifw(type name = (__VA_ARGS__), name)
  29. #define countof(a) (sizeof(a) / sizeof(*(a)))
  30. #define swap(t, a, b) do {t _tmp = a; a = b; b = _tmp;} while(0)
  31. #define IsSmallNumber(x) ((x) > -0.001 && (x) < 0.001)
  32. #define CloseEnough(x, y) (IsSmallNumber(x - y))
  33. #ifndef NDEBUG
  34. #define Dbg_Log(level, ...) \
  35. do if(get_bit(dbglevel, level)) Log(c"" #level ": " __VA_ARGS__); while(0)
  36. #else
  37. #define Dbg_Log(...)
  38. #endif
  39. /* !!!FIXME!!! GZDoom doesn't have a way of using PRINT_NONOTIFY yet */
  40. #define ConsoleLog(...) ((void)0)
  41. #define TickerT(t, on, off) ((ACS_Timer() % 35) < (t) ? (on) : (off))
  42. #define Ticker(on, off) (TickerT(17, on, off))
  43. #define FourCCPtr(s) FourCC((s)[0], (s)[1], (s)[2], (s)[3])
  44. #define FourCC(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | (a << 0))
  45. #define SCallI ACS_ScriptCall
  46. #define SCallK ACS_ScriptCallFixed
  47. #define SCallS ACS_ScriptCallString
  48. #define GetMembI ACS_GetUserVariable
  49. #define GetMembK ACS_GetUserVariableFixed
  50. #define GetMembS ACS_GetUserVariableString
  51. #define SetMembI ACS_SetUserVariable
  52. #define SetMembK ACS_SetUserVariableFixed
  53. #define GetPropI ACS_GetActorProperty
  54. #define GetPropK ACS_GetActorPropertyFixed
  55. #define GetPropS ACS_GetActorPropertyString
  56. #define SetPropI ACS_SetActorProperty
  57. #define SetPropK ACS_SetActorPropertyFixed
  58. #define SetPropS ACS_SetActorPropertyString
  59. #define GetX ACS_GetActorX
  60. #define GetY ACS_GetActorY
  61. #define GetZ ACS_GetActorZ
  62. #define Paused ServCallI(sm_GetPaused)
  63. #define PausableTick() do ACS_Delay(1); while(Paused)
  64. #define WaitPause() while(Paused) ACS_Delay(1)
  65. #define Spf s""
  66. #define CVAR "lith_"
  67. #define DCVAR "__lith_"
  68. #define LANG "LITH_"
  69. #define OBJ "Lith_"
  70. #define sCVAR Spf CVAR
  71. #define sDCVAR Spf DCVAR
  72. #define sLANG Spf LANG
  73. #define sOBJ Spf OBJ
  74. #define ServCallI(...) SCallI(so_Serv, __VA_ARGS__)
  75. #define ServCallK(...) SCallK(so_Serv, __VA_ARGS__)
  76. #define ServCallS(...) SCallS(so_Serv, __VA_ARGS__)
  77. #define DrawCallI(...) SCallI(so_Draw, __VA_ARGS__)
  78. #define DrawCallK(...) SCallK(so_Draw, __VA_ARGS__)
  79. #define DrawCallS(...) SCallS(so_Draw, __VA_ARGS__)
  80. #define Dbg_Stat(...) \
  81. (get_bit(dbglevel, log_devh) ? Dbg_Stat_Impl(__VA_ARGS__) : (void)0)
  82. #define Dbg_Note(...) \
  83. (get_bit(dbglevel, log_devh) ? Dbg_Note_Impl(__VA_ARGS__) : (void)0)
  84. #define InvGive ACS_GiveInventory
  85. #define InvMax(arg) ACS_GetMaxInventory(0, arg)
  86. #define InvNum ACS_CheckInventory
  87. #define InvTake ACS_TakeInventory
  88. /* Types ------------------------------------------------------------------- */
  89. enum {
  90. log_none,
  91. log_dev, /* general debug info */
  92. log_devh, /* prints live stats to the HUD (position, angles, etc) */
  93. log_boss, /* debug info for the boss system */
  94. log_dmon, /* debug info for the monster tracker */
  95. log_dmonV, /* verbose debug info for the monster tracker */
  96. log_dlg, /* debug info for the dialogue/terminal compiler */
  97. log_bip, /* debug info for the BIP */
  98. log_sys, /* meta debug info */
  99. log_sysV, /* tick info */
  100. };
  101. enum {
  102. dbgf_bip,
  103. dbgf_items,
  104. dbgf_save,
  105. dbgf_score,
  106. dbgf_upgr,
  107. };
  108. /* Extern Functions -------------------------------------------------------- */
  109. void FadeFlash(i32 r, i32 g, i32 b, k32 amount, k32 seconds);
  110. script optargs(1) i32 PtrTID(i32 tid, i32 ptr);
  111. script optargs(1) i32 PtrPlayerNumber(i32 tid, i32 ptr);
  112. script optargs(1) bool PtrValid(i32 tid, i32 ptr);
  113. script optargs(2) bool PtrSet(i32 tid, i32 ptr, i32 assign, i32 tid2, i32 ptr2, i32 flags);
  114. i32 PtrInvNum(i32 tid, str item);
  115. void PtrInvGive(i32 tid, str item, i32 amount);
  116. void PtrInvTake(i32 tid, str item, i32 amount);
  117. void PtrInvSet (i32 tid, str item, i32 amount);
  118. void Dbg_Stat_Impl(cstr fmt, ...);
  119. void Dbg_Note_Impl(cstr fmt, ...);
  120. void Dbg_PrintMem(void const *data, size_t size);
  121. void Dbg_PrintMemC(void const *data, size_t size);
  122. void Log(cstr fmt, ...);
  123. /* Extern Objects ---------------------------------------------------------- */
  124. extern str dbgstat[], dbgnote[];
  125. extern i32 dbgstatnum, dbgnotenum;
  126. extern i32 lmvar dbglevel;
  127. extern i32 lmvar dbgflag;
  128. #endif