Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

global.h 6.0KB

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