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

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