Open Source Tomb Raider Engine
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // Supported pixelmap color formats
  12. enum ColorMode {
  13. GREYSCALE,
  14. RGB,
  15. RGBA,
  16. ARGB,
  17. BGR,
  18. BGRA
  19. };
  20. // Colors used where ever needed
  21. const unsigned char BLACK[] = { 0, 0, 0, 255 };
  22. const unsigned char GREY[] = { 128, 128, 128, 255 };
  23. const unsigned char WHITE[] = { 255, 255, 255, 255 };
  24. const unsigned char RED[] = { 255, 0, 0, 255 };
  25. const unsigned char GREEN[] = { 0, 255, 0, 255 };
  26. const unsigned char PURPLE[] = { 77, 77, 128, 255 };
  27. const unsigned char BLUE[] = { 128, 179, 255, 255 };
  28. const unsigned char PINK[] = { 255, 0, 255, 255 };
  29. const unsigned char YELLOW[] = { 255, 255, 0, 255 };
  30. const unsigned char CYAN[] = { 0, 255, 255, 255 };
  31. // Actions that can be bound to a key and sent to the game engine
  32. typedef enum {
  33. menuAction = 0,
  34. debugAction,
  35. forwardAction,
  36. backwardAction,
  37. leftAction,
  38. rightAction,
  39. jumpAction,
  40. crouchAction,
  41. useAction,
  42. holsterAction,
  43. walkAction,
  44. ActionEventCount // Should always be at the end
  45. } ActionEvents;
  46. // Keys available for binding
  47. typedef enum {
  48. zeroKey = '0', oneKey = '1', twoKey = '2',
  49. threeKey = '3', fourKey = '4', fiveKey = '5',
  50. sixKey = '6', sevenKey = '7', eightKey = '8',
  51. nineKey = '9', aKey = 'a', bKey = 'b',
  52. cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
  53. gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
  54. kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
  55. oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
  56. sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
  57. wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
  58. quoteKey, backslashKey, backspaceKey, capslockKey,
  59. commaKey, delKey, upKey, downKey, leftKey, rightKey,
  60. endKey, equalsKey, escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key,
  61. f6Key, f7Key, f8Key, f9Key, f10Key, f11Key, f12Key, backquoteKey,
  62. homeKey, insertKey, leftaltKey, leftctrlKey, leftbracketKey,
  63. leftguiKey, leftshiftKey, minusKey, numlockKey, pagedownKey,
  64. pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
  65. rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
  66. semicolonKey, slashKey, spaceKey, tabKey,
  67. leftmouseKey, middlemouseKey, rightmouseKey,
  68. fourthmouseKey, fifthmouseKey,
  69. unknownKey // Should always be at the end
  70. } KeyboardButton;
  71. // Visual C++ does not understand __attribute__
  72. #ifdef _MSC_VER
  73. #define __attribute__(x)
  74. #endif
  75. //! \todo Replace NULL usage with nullptr
  76. #ifndef NULL
  77. #define NULL nullptr
  78. #endif
  79. // Globally include OpenGL header
  80. #ifdef __APPLE__
  81. #include <OpenGL/gl.h>
  82. #else
  83. #ifdef _WIN32
  84. #include <windows.h>
  85. #endif
  86. #include <GL/gl.h>
  87. #include <GL/glext.h>
  88. #endif
  89. // If available, use our own assert that prints the call stack
  90. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  91. #ifndef NDEBUG
  92. #include <iostream>
  93. #include <execinfo.h>
  94. template<typename T, typename U>
  95. [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  96. bool print) {
  97. const unsigned int maxSize = 128;
  98. void* callstack[maxSize];
  99. int frames = backtrace(callstack, maxSize);
  100. char** strs = backtrace_symbols(callstack, frames);
  101. std::cout << std::endl << "assertion failed:" << std::endl;
  102. std::cout << "\t" << exp << std::endl;
  103. if (print)
  104. std::cout << "\t (" << a << " != " << b << ")" << std::endl;
  105. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  106. for (int i = 0; i < frames; i++)
  107. std::cout << strs[i] << std::endl;
  108. delete [] strs;
  109. abort();
  110. }
  111. template<typename T, typename U>
  112. [[noreturn]] void assertNotEqualImplementation(const char* exp, T a, U b, const char* file,
  113. int line, bool print) {
  114. const unsigned int maxSize = 128;
  115. void* callstack[maxSize];
  116. int frames = backtrace(callstack, maxSize);
  117. char** strs = backtrace_symbols(callstack, frames);
  118. std::cout << std::endl << "assertion failed:" << std::endl;
  119. std::cout << "\t" << exp << std::endl;
  120. if (print)
  121. std::cout << "\t (" << a << " == " << b << ")" << std::endl;
  122. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  123. for (int i = 0; i < frames; i++)
  124. std::cout << strs[i] << std::endl;
  125. delete [] strs;
  126. abort();
  127. }
  128. // Evaluating x or y could have side-effects
  129. // So we only do it once!
  130. #define assert(x) { \
  131. auto assertEvalTemp = x; \
  132. if (!assertEvalTemp) \
  133. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__, false); \
  134. }
  135. #define assertEqual(x, y) { \
  136. auto assertEvalTemp = x; \
  137. auto assertEvalTemp2 = y; \
  138. if (assertEvalTemp != assertEvalTemp2) \
  139. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  140. }
  141. #define assertNotEqual(x, y) { \
  142. auto assertEvalTemp = x; \
  143. auto assertEvalTemp2 = y; \
  144. if (assertEvalTemp == assertEvalTemp2) \
  145. assertNotEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  146. }
  147. #else // NDEBUG
  148. #define assert(x)
  149. #define assertEqual(x, y)
  150. #define assertNotEqual(x, y)
  151. #endif // NDEBUG
  152. #else // EXECINFO
  153. // Fall back to the default C assert
  154. #include <cassert>
  155. #define assertEqual(x, y) assert((x) == (y))
  156. #define assertNotEqual(x, y) assert((x) != (y))
  157. #endif // EXECINFO
  158. #endif // _GLOBAL_H_