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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. // If available, use our own assert that prints the call stack
  80. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  81. #ifndef NDEBUG
  82. #include <iostream>
  83. #include <execinfo.h>
  84. template<typename T, typename U>
  85. [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  86. bool print) {
  87. const unsigned int maxSize = 128;
  88. void* callstack[maxSize];
  89. int frames = backtrace(callstack, maxSize);
  90. char** strs = backtrace_symbols(callstack, frames);
  91. std::cout << std::endl << "assertion failed:" << std::endl;
  92. std::cout << "\t" << exp << std::endl;
  93. if (print)
  94. std::cout << "\t (" << a << " != " << b << ")" << std::endl;
  95. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  96. for (int i = 0; i < frames; i++)
  97. std::cout << strs[i] << std::endl;
  98. delete [] strs;
  99. abort();
  100. }
  101. template<typename T, typename U>
  102. [[noreturn]] void assertNotEqualImplementation(const char* exp, T a, U b, const char* file,
  103. int line, bool print) {
  104. const unsigned int maxSize = 128;
  105. void* callstack[maxSize];
  106. int frames = backtrace(callstack, maxSize);
  107. char** strs = backtrace_symbols(callstack, frames);
  108. std::cout << std::endl << "assertion failed:" << std::endl;
  109. std::cout << "\t" << exp << std::endl;
  110. if (print)
  111. std::cout << "\t (" << a << " == " << b << ")" << std::endl;
  112. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  113. for (int i = 0; i < frames; i++)
  114. std::cout << strs[i] << std::endl;
  115. delete [] strs;
  116. abort();
  117. }
  118. // Evaluating x or y could have side-effects
  119. // So we only do it once!
  120. #define assert(x) { \
  121. auto assertEvalTemp = x; \
  122. if (!assertEvalTemp) \
  123. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__, false); \
  124. }
  125. #define assertEqual(x, y) { \
  126. auto assertEvalTemp = x; \
  127. auto assertEvalTemp2 = y; \
  128. if (assertEvalTemp != assertEvalTemp2) \
  129. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  130. }
  131. #define assertNotEqual(x, y) { \
  132. auto assertEvalTemp = x; \
  133. auto assertEvalTemp2 = y; \
  134. if (assertEvalTemp == assertEvalTemp2) \
  135. assertNotEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  136. }
  137. #else // NDEBUG
  138. #define assert(x)
  139. #define assertEqual(x, y)
  140. #define assertNotEqual(x, y)
  141. #endif // NDEBUG
  142. #else // EXECINFO
  143. // Fall back to the default C assert
  144. #include <cassert>
  145. #define assertEqual(x, y) assert((x) == (y))
  146. #define assertNotEqual(x, y) assert((x) != (y))
  147. #endif // EXECINFO
  148. #endif // _GLOBAL_H_