Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

global.h 6.0KB

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