Open Source Tomb Raider Engine
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.

global.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*!
  2. * \file include/global.h
  3. * \brief Included everywhere
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _GLOBAL_H_
  8. #define _GLOBAL_H_
  9. #include "config.h"
  10. void renderFrame();
  11. // Actions that can be bound to a key and sent to the game engine
  12. typedef enum {
  13. menuAction = 0,
  14. debugAction,
  15. consoleAction,
  16. forwardAction,
  17. backwardAction,
  18. leftAction,
  19. rightAction,
  20. jumpAction,
  21. crouchAction,
  22. useAction,
  23. holsterAction,
  24. walkAction,
  25. ActionEventCount // Should always be at the end
  26. } ActionEvents;
  27. // Keys available for binding
  28. typedef enum {
  29. // Keyboard
  30. zeroKey = '0', oneKey = '1', twoKey = '2',
  31. threeKey = '3', fourKey = '4', fiveKey = '5',
  32. sixKey = '6', sevenKey = '7', eightKey = '8',
  33. nineKey = '9', aKey = 'a', bKey = 'b',
  34. cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
  35. gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
  36. kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
  37. oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
  38. sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
  39. wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
  40. quoteKey, backslashKey, backspaceKey, capslockKey,
  41. commaKey, delKey, upKey, downKey, leftKey, rightKey,
  42. endKey, equalsKey, escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key,
  43. f6Key, f7Key, f8Key, f9Key, f10Key, f11Key, f12Key, backquoteKey,
  44. homeKey, insertKey, leftaltKey, leftctrlKey, leftbracketKey,
  45. leftguiKey, leftshiftKey, minusKey, numlockKey, pagedownKey,
  46. pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
  47. rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
  48. semicolonKey, slashKey, spaceKey, tabKey,
  49. // Mouse
  50. leftmouseKey, middlemouseKey, rightmouseKey,
  51. fourthmouseKey, fifthmouseKey,
  52. // Game Controller
  53. aButton, bButton, xButton, yButton, backButton, startButton,
  54. guideButton, leftStick, rightStick, leftShoulder, rightShoulder,
  55. padUp, padDown, padLeft, padRight,
  56. leftXAxis, leftYAxis, rightXAxis, rightYAxis, leftTrigger, rightTrigger,
  57. unknownKey // Should always be at the end
  58. } KeyboardButton;
  59. #include <glm/vec2.hpp>
  60. #include <glm/vec3.hpp>
  61. #include <glm/vec4.hpp>
  62. #include <glm/mat4x4.hpp>
  63. // If available, use our own assert that prints the call stack
  64. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  65. #ifndef NDEBUG
  66. #include <iostream>
  67. #include <execinfo.h>
  68. template<typename T, typename U>
  69. [[noreturn]] void orAssertImplementation(const char* exp, T a, U b, const char* file, int line,
  70. const char* str = nullptr) {
  71. const unsigned int maxSize = 128;
  72. void* callstack[maxSize];
  73. int frames = backtrace(callstack, maxSize);
  74. char** strs = backtrace_symbols(callstack, frames);
  75. std::cout << std::endl << "assertion failed:" << std::endl;
  76. std::cout << "\t" << exp << std::endl;
  77. if (str != nullptr)
  78. std::cout << "\t(" << a << " " << str << " " << b << ")" << std::endl;
  79. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  80. for (int i = 0; i < frames; i++)
  81. std::cout << strs[i] << std::endl;
  82. delete [] strs;
  83. abort();
  84. }
  85. #define orAssert(x) do { \
  86. auto assertEvalTemp = x; \
  87. if (!assertEvalTemp) \
  88. orAssertImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
  89. } while (0)
  90. #define orAssertEqual(x, y) do { \
  91. auto assertEvalTemp = x; \
  92. auto assertEvalTemp2 = y; \
  93. if (assertEvalTemp != assertEvalTemp2) \
  94. orAssertImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
  95. __FILE__, __LINE__, "!="); \
  96. } while (0)
  97. #define orAssertNotEqual(x, y) do { \
  98. auto assertEvalTemp = x; \
  99. auto assertEvalTemp2 = y; \
  100. if (assertEvalTemp == assertEvalTemp2) \
  101. orAssertImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
  102. __FILE__, __LINE__, "=="); \
  103. } while (0)
  104. #define orAssertLessThan(x, y) do { \
  105. auto assertEvalTemp = x; \
  106. auto assertEvalTemp2 = y; \
  107. if (assertEvalTemp >= assertEvalTemp2) \
  108. orAssertImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \
  109. __FILE__, __LINE__, ">="); \
  110. } while (0)
  111. #define orAssertLessThanEqual(x, y) do { \
  112. auto assertEvalTemp = x; \
  113. auto assertEvalTemp2 = y; \
  114. if (assertEvalTemp > assertEvalTemp2) \
  115. orAssertImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \
  116. __FILE__, __LINE__, ">"); \
  117. } while (0)
  118. #define orAssertGreaterThan(x, y) do { \
  119. auto assertEvalTemp = x; \
  120. auto assertEvalTemp2 = y; \
  121. if (assertEvalTemp <= assertEvalTemp2) \
  122. orAssertImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \
  123. __FILE__, __LINE__, "<="); \
  124. } while (0)
  125. #define orAssertGreaterThanEqual(x, y) do { \
  126. auto assertEvalTemp = x; \
  127. auto assertEvalTemp2 = y; \
  128. if (assertEvalTemp < assertEvalTemp2) \
  129. orAssertImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \
  130. __FILE__, __LINE__, "<"); \
  131. } while (0)
  132. #else // NDEBUG
  133. #define orAssert(x)
  134. #define orAssertEqual(x, y)
  135. #define orAssertNotEqual(x, y)
  136. #define orAssertLessThan(x, y)
  137. #define orAssertLessThanEqual(x, y)
  138. #define orAssertGreaterThan(x, y)
  139. #define orAssertGreaterThanEqual(x, y)
  140. #endif // NDEBUG
  141. #else // EXECINFO
  142. // Fall back to the default C assert
  143. #include <cassert>
  144. #define orAssert(x) assert(x)
  145. #define orAssertEqual(x, y) assert((x) == (y))
  146. #define orAssertNotEqual(x, y) assert((x) != (y))
  147. #define orAssertLessThan(x, y) assert((x) < (y))
  148. #define orAssertLessThanEqual(x, y) assert((x) <= (y))
  149. #define orAssertGreaterThan(x, y) assert((x) > (y))
  150. #define orAssertGreaterThanEqual(x, y) assert((x) >= (y))
  151. #endif // EXECINFO
  152. #endif // _GLOBAL_H_