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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. typedef enum {
  12. geometryObject = 0,
  13. roomSpriteObject,
  14. roomModelObject,
  15. spriteObject,
  16. meshObject,
  17. modelObject,
  18. entityObject,
  19. WorldObjectCount // Should always be at the end
  20. } WorldObjects;
  21. // Actions that can be bound to a key and sent to the game engine
  22. typedef enum {
  23. menuAction = 0,
  24. debugAction,
  25. consoleAction,
  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. // Mouse
  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. #include <glm/vec2.hpp>
  70. #include <glm/vec3.hpp>
  71. #include <glm/vec4.hpp>
  72. #include <glm/mat4x4.hpp>
  73. // If available, use our own assert that prints the call stack
  74. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  75. #ifndef NDEBUG
  76. #include <iostream>
  77. #include <execinfo.h>
  78. template<typename T, typename U>
  79. [[noreturn]] void orAssertImplementation(const char* exp, T a, U b, const char* file, int line,
  80. const char* str = nullptr) {
  81. const unsigned int maxSize = 128;
  82. void* callstack[maxSize];
  83. int frames = backtrace(callstack, maxSize);
  84. char** strs = backtrace_symbols(callstack, frames);
  85. std::cout << std::endl << "assertion failed:" << std::endl;
  86. std::cout << "\t" << exp << std::endl;
  87. if (str != nullptr)
  88. std::cout << "\t(" << a << " " << str << " " << b << ")" << std::endl;
  89. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  90. for (int i = 0; i < frames; i++)
  91. std::cout << strs[i] << std::endl;
  92. delete [] strs;
  93. abort();
  94. }
  95. #define orAssert(x) do { \
  96. auto assertEvalTemp = x; \
  97. if (!assertEvalTemp) \
  98. orAssertImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
  99. } while (0)
  100. #define orAssertEqual(x, y) do { \
  101. auto assertEvalTemp = x; \
  102. auto assertEvalTemp2 = y; \
  103. if (assertEvalTemp != assertEvalTemp2) \
  104. orAssertImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
  105. __FILE__, __LINE__, "!="); \
  106. } while (0)
  107. #define orAssertNotEqual(x, y) do { \
  108. auto assertEvalTemp = x; \
  109. auto assertEvalTemp2 = y; \
  110. if (assertEvalTemp == assertEvalTemp2) \
  111. orAssertImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
  112. __FILE__, __LINE__, "=="); \
  113. } while (0)
  114. #define orAssertLessThan(x, y) do { \
  115. auto assertEvalTemp = x; \
  116. auto assertEvalTemp2 = y; \
  117. if (assertEvalTemp >= assertEvalTemp2) \
  118. orAssertImplementation(#x " < " #y, assertEvalTemp, assertEvalTemp2, \
  119. __FILE__, __LINE__, ">="); \
  120. } while (0)
  121. #define orAssertLessThanEqual(x, y) do { \
  122. auto assertEvalTemp = x; \
  123. auto assertEvalTemp2 = y; \
  124. if (assertEvalTemp > assertEvalTemp2) \
  125. orAssertImplementation(#x " <= " #y, assertEvalTemp, assertEvalTemp2, \
  126. __FILE__, __LINE__, ">"); \
  127. } while (0)
  128. #define orAssertGreaterThan(x, y) do { \
  129. auto assertEvalTemp = x; \
  130. auto assertEvalTemp2 = y; \
  131. if (assertEvalTemp <= assertEvalTemp2) \
  132. orAssertImplementation(#x " > " #y, assertEvalTemp, assertEvalTemp2, \
  133. __FILE__, __LINE__, "<="); \
  134. } while (0)
  135. #define orAssertGreaterThanEqual(x, y) do { \
  136. auto assertEvalTemp = x; \
  137. auto assertEvalTemp2 = y; \
  138. if (assertEvalTemp < assertEvalTemp2) \
  139. orAssertImplementation(#x " >= " #y, assertEvalTemp, assertEvalTemp2, \
  140. __FILE__, __LINE__, "<"); \
  141. } while (0)
  142. #else // NDEBUG
  143. #define orAssert(x)
  144. #define orAssertEqual(x, y)
  145. #define orAssertNotEqual(x, y)
  146. #define orAssertLessThan(x, y)
  147. #define orAssertLessThanEqual(x, y)
  148. #define orAssertGreaterThan(x, y)
  149. #define orAssertGreaterThanEqual(x, y)
  150. #endif // NDEBUG
  151. #else // EXECINFO
  152. // Fall back to the default C assert
  153. #include <cassert>
  154. #define orAssert(x) assert(x)
  155. #define orAssertEqual(x, y) assert((x) == (y))
  156. #define orAssertNotEqual(x, y) assert((x) != (y))
  157. #define orAssertLessThan(x, y) assert((x) < (y))
  158. #define orAssertLessThanEqual(x, y) assert((x) <= (y))
  159. #define orAssertGreaterThan(x, y) assert((x) > (y))
  160. #define orAssertGreaterThanEqual(x, y) assert((x) >= (y))
  161. #endif // EXECINFO
  162. #endif // _GLOBAL_H_