Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

global.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 // __APPLE__
  66. #ifdef _WIN32
  67. #include <windows.h>
  68. #endif // _WIN32
  69. //! \todo gl3 header?
  70. #include <GL/gl.h>
  71. #include <GL/glext.h>
  72. #endif // __APPLE__
  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 assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  80. bool print) {
  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 (print)
  88. std::cout << "\t (" << a << " != " << 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. template<typename T, typename U>
  96. [[noreturn]] void assertNotEqualImplementation(const char* exp, T a, U b, const char* file,
  97. int line, bool print) {
  98. const unsigned int maxSize = 128;
  99. void* callstack[maxSize];
  100. int frames = backtrace(callstack, maxSize);
  101. char** strs = backtrace_symbols(callstack, frames);
  102. std::cout << std::endl << "assertion failed:" << std::endl;
  103. std::cout << "\t" << exp << std::endl;
  104. if (print)
  105. std::cout << "\t (" << a << " == " << b << ")" << std::endl;
  106. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  107. for (int i = 0; i < frames; i++)
  108. std::cout << strs[i] << std::endl;
  109. delete [] strs;
  110. abort();
  111. }
  112. // Evaluating x or y could have side-effects
  113. // So we only do it once!
  114. #define assert(x) { \
  115. auto assertEvalTemp = x; \
  116. if (!assertEvalTemp) \
  117. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__, false); \
  118. }
  119. #define assertEqual(x, y) { \
  120. auto assertEvalTemp = x; \
  121. auto assertEvalTemp2 = y; \
  122. if (assertEvalTemp != assertEvalTemp2) \
  123. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  124. }
  125. #define assertNotEqual(x, y) { \
  126. auto assertEvalTemp = x; \
  127. auto assertEvalTemp2 = y; \
  128. if (assertEvalTemp == assertEvalTemp2) \
  129. assertNotEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  130. }
  131. #else // NDEBUG
  132. #define assert(x)
  133. #define assertEqual(x, y)
  134. #define assertNotEqual(x, y)
  135. #endif // NDEBUG
  136. #else // EXECINFO
  137. // Fall back to the default C assert
  138. #include <cassert>
  139. #define assertEqual(x, y) assert((x) == (y))
  140. #define assertNotEqual(x, y) assert((x) != (y))
  141. #endif // EXECINFO
  142. #endif // _GLOBAL_H_