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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. zeroKey = '0', oneKey = '1', twoKey = '2',
  40. threeKey = '3', fourKey = '4', fiveKey = '5',
  41. sixKey = '6', sevenKey = '7', eightKey = '8',
  42. nineKey = '9', aKey = 'a', bKey = 'b',
  43. cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
  44. gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
  45. kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
  46. oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
  47. sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
  48. wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
  49. quoteKey, backslashKey, backspaceKey, capslockKey,
  50. commaKey, delKey, upKey, downKey, leftKey, rightKey,
  51. endKey, equalsKey, escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key,
  52. f6Key, f7Key, f8Key, f9Key, f10Key, f11Key, f12Key, backquoteKey,
  53. homeKey, insertKey, leftaltKey, leftctrlKey, leftbracketKey,
  54. leftguiKey, leftshiftKey, minusKey, numlockKey, pagedownKey,
  55. pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
  56. rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
  57. semicolonKey, slashKey, spaceKey, tabKey,
  58. leftmouseKey, middlemouseKey, rightmouseKey,
  59. fourthmouseKey, fifthmouseKey,
  60. unknownKey // Should always be at the end
  61. } KeyboardButton;
  62. // Globally include OpenGL header
  63. #ifdef __APPLE__
  64. #include <OpenGL/gl3.h>
  65. #else
  66. #ifdef _WIN32
  67. #include <windows.h>
  68. #endif
  69. #include <GL/gl3.h>
  70. #endif
  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 NDEBUG
  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. bool print) {
  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 (print)
  86. std::cout << "\t (" << a << " != " << 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. template<typename T, typename U>
  94. [[noreturn]] void assertNotEqualImplementation(const char* exp, T a, U b, const char* file,
  95. int line, bool print) {
  96. const unsigned int maxSize = 128;
  97. void* callstack[maxSize];
  98. int frames = backtrace(callstack, maxSize);
  99. char** strs = backtrace_symbols(callstack, frames);
  100. std::cout << std::endl << "assertion failed:" << std::endl;
  101. std::cout << "\t" << exp << std::endl;
  102. if (print)
  103. std::cout << "\t (" << a << " == " << b << ")" << std::endl;
  104. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  105. for (int i = 0; i < frames; i++)
  106. std::cout << strs[i] << std::endl;
  107. delete [] strs;
  108. abort();
  109. }
  110. // Evaluating x or y could have side-effects
  111. // So we only do it once!
  112. #define assert(x) { \
  113. auto assertEvalTemp = x; \
  114. if (!assertEvalTemp) \
  115. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__, false); \
  116. }
  117. #define assertEqual(x, y) { \
  118. auto assertEvalTemp = x; \
  119. auto assertEvalTemp2 = y; \
  120. if (assertEvalTemp != assertEvalTemp2) \
  121. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  122. }
  123. #define assertNotEqual(x, y) { \
  124. auto assertEvalTemp = x; \
  125. auto assertEvalTemp2 = y; \
  126. if (assertEvalTemp == assertEvalTemp2) \
  127. assertNotEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  128. }
  129. #else // NDEBUG
  130. #define assert(x)
  131. #define assertEqual(x, y)
  132. #define assertNotEqual(x, y)
  133. #endif // NDEBUG
  134. #else // EXECINFO
  135. // Fall back to the default C assert
  136. #include <cassert>
  137. #define assertEqual(x, y) assert((x) == (y))
  138. #define assertNotEqual(x, y) assert((x) != (y))
  139. #endif // EXECINFO
  140. #endif // _GLOBAL_H_