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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*!
  2. * \file include/global.h
  3. * \brief Global typedefs
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _GLOBAL_H_
  8. #define _GLOBAL_H_
  9. #include "config.h"
  10. void renderFrame();
  11. // Colors used where ever needed
  12. const unsigned char BLACK[] = { 0, 0, 0, 255 };
  13. const unsigned char GREY[] = { 128, 128, 128, 255 };
  14. const unsigned char WHITE[] = { 255, 255, 255, 255 };
  15. const unsigned char RED[] = { 255, 0, 0, 255 };
  16. const unsigned char GREEN[] = { 0, 255, 0, 255 };
  17. const unsigned char PURPLE[] = { 77, 77, 128, 255 };
  18. const unsigned char BLUE[] = { 128, 179, 255, 255 };
  19. const unsigned char PINK[] = { 255, 0, 255, 255 };
  20. const unsigned char YELLOW[] = { 255, 255, 0, 255 };
  21. const unsigned char CYAN[] = { 0, 255, 255, 255 };
  22. // Actions that can be bound to a key and sent to the game engine
  23. typedef enum {
  24. menuAction = 0,
  25. debugAction,
  26. consoleAction,
  27. forwardAction,
  28. backwardAction,
  29. leftAction,
  30. rightAction,
  31. jumpAction,
  32. crouchAction,
  33. useAction,
  34. holsterAction,
  35. walkAction,
  36. ActionEventCount // Should always be at the end
  37. } ActionEvents;
  38. // Keys available for binding
  39. typedef enum {
  40. // Keyboard
  41. zeroKey = '0', oneKey = '1', twoKey = '2',
  42. threeKey = '3', fourKey = '4', fiveKey = '5',
  43. sixKey = '6', sevenKey = '7', eightKey = '8',
  44. nineKey = '9', aKey = 'a', bKey = 'b',
  45. cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
  46. gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
  47. kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
  48. oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
  49. sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
  50. wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
  51. quoteKey, backslashKey, backspaceKey, capslockKey,
  52. commaKey, delKey, upKey, downKey, leftKey, rightKey,
  53. endKey, equalsKey, escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key,
  54. f6Key, f7Key, f8Key, f9Key, f10Key, f11Key, f12Key, backquoteKey,
  55. homeKey, insertKey, leftaltKey, leftctrlKey, leftbracketKey,
  56. leftguiKey, leftshiftKey, minusKey, numlockKey, pagedownKey,
  57. pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
  58. rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
  59. semicolonKey, slashKey, spaceKey, tabKey,
  60. leftmouseKey, middlemouseKey, rightmouseKey,
  61. fourthmouseKey, fifthmouseKey,
  62. // Game Controller
  63. aButton, bButton, xButton, yButton, backButton, startButton,
  64. guideButton, leftStick, rightStick, leftShoulder, rightShoulder,
  65. padUp, padDown, padLeft, padRight,
  66. leftXAxis, leftYAxis, rightXAxis, rightYAxis, leftTrigger, rightTrigger,
  67. unknownKey // Should always be at the end
  68. } KeyboardButton;
  69. // Globally include OpenGL header
  70. #ifdef __APPLE__
  71. #include <OpenGL/gl3.h>
  72. #else // __APPLE__
  73. #ifdef _WIN32
  74. #include <GL/glew.h>
  75. #include <GL/wglew.h>
  76. #pragma comment(lib, "glew32.lib")
  77. #else // _WIN32
  78. //! \todo gl3 header?
  79. #include <GL/gl.h>
  80. #include <GL/glext.h>
  81. #endif // _WIN32
  82. #endif // __APPLE__
  83. /*! \todo Is there a better way to handle this?
  84. * We wan't to use our own assert(). Unfortunately, glm includes
  85. * <cassert> in its headers. So we need to define NDEBUG here.
  86. * To avoid a conflict, our flag is now called NODEBUG instead.
  87. */
  88. #define NDEBUG
  89. #include <glm/glm.hpp>
  90. // If available, use our own assert that prints the call stack
  91. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  92. #ifndef NODEBUG
  93. #include <iostream>
  94. #include <execinfo.h>
  95. template<typename T, typename U>
  96. [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  97. const char* str = nullptr) {
  98. const unsigned int maxSize = 128;
  99. void* callstack[maxSize];
  100. int frames = backtrace(callstack, maxSize);
  101. char** strs = backtrace_symbols(callstack, frames);
  102. std::cout << std::endl << "assertion failed:" << std::endl;
  103. std::cout << "\t" << exp << std::endl;
  104. if (str != nullptr)
  105. std::cout << "\t(" << a << " " << str << " " << b << ")" << std::endl;
  106. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  107. for (int i = 0; i < frames; i++)
  108. std::cout << strs[i] << std::endl;
  109. delete [] strs;
  110. abort();
  111. }
  112. // Evaluating x or y could have side-effects
  113. // So we only do it once!
  114. #define assert(x) { \
  115. auto assertEvalTemp = x; \
  116. if (!assertEvalTemp) \
  117. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
  118. }
  119. #define assertEqual(x, y) { \
  120. auto assertEvalTemp = x; \
  121. auto assertEvalTemp2 = y; \
  122. if (assertEvalTemp != assertEvalTemp2) \
  123. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
  124. __FILE__, __LINE__, "!="); \
  125. }
  126. #define assertNotEqual(x, y) { \
  127. auto assertEvalTemp = x; \
  128. auto assertEvalTemp2 = y; \
  129. if (assertEvalTemp == assertEvalTemp2) \
  130. assertEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
  131. __FILE__, __LINE__, "=="); \
  132. }
  133. #define assertLessThan(x, y) { \
  134. auto assertEvalTemp = x; \
  135. auto assertEvalTemp2 = y; \
  136. if (assertEvalTemp >= assertEvalTemp2) \
  137. assertEqualImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \
  138. __FILE__, __LINE__, ">="); \
  139. }
  140. #define assertLessThanEqual(x, y) { \
  141. auto assertEvalTemp = x; \
  142. auto assertEvalTemp2 = y; \
  143. if (assertEvalTemp > assertEvalTemp2) \
  144. assertEqualImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \
  145. __FILE__, __LINE__, ">"); \
  146. }
  147. #define assertGreaterThan(x, y) { \
  148. auto assertEvalTemp = x; \
  149. auto assertEvalTemp2 = y; \
  150. if (assertEvalTemp <= assertEvalTemp2) \
  151. assertEqualImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \
  152. __FILE__, __LINE__, "<="); \
  153. }
  154. #define assertGreaterThanEqual(x, y) { \
  155. auto assertEvalTemp = x; \
  156. auto assertEvalTemp2 = y; \
  157. if (assertEvalTemp < assertEvalTemp2) \
  158. assertEqualImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \
  159. __FILE__, __LINE__, "<"); \
  160. }
  161. #else // NODEBUG
  162. #define assert(x)
  163. #define assertEqual(x, y)
  164. #define assertNotEqual(x, y)
  165. #define assertLessThan(x, y)
  166. #define assertLessThanEqual(x, y)
  167. #define assertGreaterThan(x, y)
  168. #define assertGreaterThanEqual(x, y)
  169. #endif // NODEBUG
  170. #else // EXECINFO
  171. // Fall back to the default C assert
  172. #include <cassert>
  173. #define assertEqual(x, y) assert((x) == (y))
  174. #define assertNotEqual(x, y) assert((x) != (y))
  175. #define assertLessThan(x, y) assert((x) < (y))
  176. #define assertLessThanEqual(x, y) assert((x) <= (y))
  177. #define assertGreaterThan(x, y) assert((x) > (y))
  178. #define assertGreaterThanEqual(x, y) assert((x) >= (y))
  179. #endif // EXECINFO
  180. #endif // _GLOBAL_H_