Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

global.h 5.1KB

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