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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. // Globally include OpenGL header
  60. #ifdef __APPLE__
  61. #include <OpenGL/gl3.h>
  62. #else // __APPLE__
  63. #ifdef _WIN32
  64. #include <GL/glew.h>
  65. #include <GL/wglew.h>
  66. #pragma comment(lib, "glew32.lib")
  67. #else // _WIN32
  68. //! \fixme gl3 header?
  69. #include <GL/gl.h>
  70. #include <GL/glext.h>
  71. #endif // _WIN32
  72. #endif // __APPLE__
  73. /*! \fixme Is there a better way to handle this?
  74. * We wan't to use our own assert(). Unfortunately, glm includes
  75. * cassert in its headers. So we need to define NDEBUG here.
  76. * To avoid a conflict, our flag is now called NODEBUG instead.
  77. */
  78. #define NDEBUG
  79. #include <glm/glm.hpp>
  80. // If available, use our own assert that prints the call stack
  81. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  82. #ifndef NODEBUG
  83. #include <iostream>
  84. #include <execinfo.h>
  85. template<typename T, typename U>
  86. [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  87. const char* str = nullptr) {
  88. const unsigned int maxSize = 128;
  89. void* callstack[maxSize];
  90. int frames = backtrace(callstack, maxSize);
  91. char** strs = backtrace_symbols(callstack, frames);
  92. std::cout << std::endl << "assertion failed:" << std::endl;
  93. std::cout << "\t" << exp << std::endl;
  94. if (str != nullptr)
  95. std::cout << "\t(" << a << " " << str << " " << b << ")" << std::endl;
  96. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  97. for (int i = 0; i < frames; i++)
  98. std::cout << strs[i] << std::endl;
  99. delete [] strs;
  100. abort();
  101. }
  102. // Evaluating x or y could have side-effects
  103. // So we only do it once!
  104. #define assert(x) { \
  105. auto assertEvalTemp = x; \
  106. if (!assertEvalTemp) \
  107. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
  108. }
  109. #define assertEqual(x, y) { \
  110. auto assertEvalTemp = x; \
  111. auto assertEvalTemp2 = y; \
  112. if (assertEvalTemp != assertEvalTemp2) \
  113. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
  114. __FILE__, __LINE__, "!="); \
  115. }
  116. #define assertNotEqual(x, y) { \
  117. auto assertEvalTemp = x; \
  118. auto assertEvalTemp2 = y; \
  119. if (assertEvalTemp == assertEvalTemp2) \
  120. assertEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
  121. __FILE__, __LINE__, "=="); \
  122. }
  123. #define assertLessThan(x, y) { \
  124. auto assertEvalTemp = x; \
  125. auto assertEvalTemp2 = y; \
  126. if (assertEvalTemp >= assertEvalTemp2) \
  127. assertEqualImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \
  128. __FILE__, __LINE__, ">="); \
  129. }
  130. #define assertLessThanEqual(x, y) { \
  131. auto assertEvalTemp = x; \
  132. auto assertEvalTemp2 = y; \
  133. if (assertEvalTemp > assertEvalTemp2) \
  134. assertEqualImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \
  135. __FILE__, __LINE__, ">"); \
  136. }
  137. #define assertGreaterThan(x, y) { \
  138. auto assertEvalTemp = x; \
  139. auto assertEvalTemp2 = y; \
  140. if (assertEvalTemp <= assertEvalTemp2) \
  141. assertEqualImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \
  142. __FILE__, __LINE__, "<="); \
  143. }
  144. #define assertGreaterThanEqual(x, y) { \
  145. auto assertEvalTemp = x; \
  146. auto assertEvalTemp2 = y; \
  147. if (assertEvalTemp < assertEvalTemp2) \
  148. assertEqualImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \
  149. __FILE__, __LINE__, "<"); \
  150. }
  151. #else // NODEBUG
  152. #define assert(x)
  153. #define assertEqual(x, y)
  154. #define assertNotEqual(x, y)
  155. #define assertLessThan(x, y)
  156. #define assertLessThanEqual(x, y)
  157. #define assertGreaterThan(x, y)
  158. #define assertGreaterThanEqual(x, y)
  159. #endif // NODEBUG
  160. #else // EXECINFO
  161. // Fall back to the default C assert
  162. #include <cassert>
  163. #define assertEqual(x, y) assert((x) == (y))
  164. #define assertNotEqual(x, y) assert((x) != (y))
  165. #define assertLessThan(x, y) assert((x) < (y))
  166. #define assertLessThanEqual(x, y) assert((x) <= (y))
  167. #define assertGreaterThan(x, y) assert((x) > (y))
  168. #define assertGreaterThanEqual(x, y) assert((x) >= (y))
  169. #endif // EXECINFO
  170. #endif // _GLOBAL_H_