Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

global.h 5.2KB

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. consoleAction,
  27. forwardAction,
  28. backwardAction,
  29. leftAction,
  30. rightAction,
  31. jumpAction,
  32. crouchAction,
  33. useAction,
  34. holsterAction,
  35. walkAction,
  36. ActionEventCount // Should always be at the end
  37. } ActionEvents;
  38. // Keys available for binding
  39. typedef enum {
  40. // Keyboard
  41. zeroKey = '0', oneKey = '1', twoKey = '2',
  42. threeKey = '3', fourKey = '4', fiveKey = '5',
  43. sixKey = '6', sevenKey = '7', eightKey = '8',
  44. nineKey = '9', aKey = 'a', bKey = 'b',
  45. cKey = 'c', dKey = 'd', eKey = 'e', fKey = 'f',
  46. gKey = 'g', hKey = 'h', iKey = 'i', jKey = 'j',
  47. kKey = 'k', lKey = 'l', mKey = 'm', nKey = 'n',
  48. oKey = 'o', pKey = 'p', qKey = 'q', rKey = 'r',
  49. sKey = 's', tKey = 't', uKey = 'u', vKey = 'v',
  50. wKey = 'w', xKey = 'x', yKey = 'y', zKey = 'z',
  51. quoteKey, backslashKey, backspaceKey, capslockKey,
  52. commaKey, delKey, upKey, downKey, leftKey, rightKey,
  53. endKey, equalsKey, escapeKey, f1Key, f2Key, f3Key, f4Key, f5Key,
  54. f6Key, f7Key, f8Key, f9Key, f10Key, f11Key, f12Key, backquoteKey,
  55. homeKey, insertKey, leftaltKey, leftctrlKey, leftbracketKey,
  56. leftguiKey, leftshiftKey, minusKey, numlockKey, pagedownKey,
  57. pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
  58. rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
  59. semicolonKey, slashKey, spaceKey, tabKey,
  60. leftmouseKey, middlemouseKey, rightmouseKey,
  61. fourthmouseKey, fifthmouseKey,
  62. // Game Controller
  63. aButton, bButton, xButton, yButton, backButton, startButton,
  64. guideButton, leftStick, rightStick, leftShoulder, rightShoulder,
  65. padUp, padDown, padLeft, padRight,
  66. leftXAxis, leftYAxis, rightXAxis, rightYAxis, leftTrigger, rightTrigger,
  67. unknownKey // Should always be at the end
  68. } KeyboardButton;
  69. // Globally include OpenGL header
  70. #ifdef __APPLE__
  71. #include <OpenGL/gl3.h>
  72. #else // __APPLE__
  73. #ifdef _WIN32
  74. #include <windows.h>
  75. #endif // _WIN32
  76. //! \todo gl3 header?
  77. #include <GL/gl.h>
  78. #include <GL/glext.h>
  79. #endif // __APPLE__
  80. /*! \todo Is there a better way to handle this?
  81. * We wan't to use our own assert(). Unfortunately, glm includes
  82. * <cassert> in its headers. So we need to define NDEBUG here.
  83. * To avoid a conflict, our flag is now called NODEBUG instead.
  84. */
  85. #define NDEBUG
  86. #include <glm/glm.hpp>
  87. // If available, use our own assert that prints the call stack
  88. #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
  89. #ifndef NODEBUG
  90. #include <iostream>
  91. #include <execinfo.h>
  92. template<typename T, typename U>
  93. [[noreturn]] void assertEqualImplementation(const char* exp, T a, U b, const char* file, int line,
  94. bool print = false, const char* str = nullptr) {
  95. const unsigned int maxSize = 128;
  96. void* callstack[maxSize];
  97. int frames = backtrace(callstack, maxSize);
  98. char** strs = backtrace_symbols(callstack, frames);
  99. std::cout << std::endl << "assertion failed:" << std::endl;
  100. std::cout << "\t" << exp << std::endl;
  101. if (print)
  102. std::cout << "\t (" << a << " " << str << " " << b << ")" << std::endl;
  103. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  104. for (int i = 0; i < frames; i++)
  105. std::cout << strs[i] << std::endl;
  106. delete [] strs;
  107. abort();
  108. }
  109. // Evaluating x or y could have side-effects
  110. // So we only do it once!
  111. #define assert(x) { \
  112. auto assertEvalTemp = x; \
  113. if (!assertEvalTemp) \
  114. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__); \
  115. }
  116. #define assertEqual(x, y) { \
  117. auto assertEvalTemp = x; \
  118. auto assertEvalTemp2 = y; \
  119. if (assertEvalTemp != assertEvalTemp2) \
  120. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, \
  121. __FILE__, __LINE__, true, "!="); \
  122. }
  123. #define assertNotEqual(x, y) { \
  124. auto assertEvalTemp = x; \
  125. auto assertEvalTemp2 = y; \
  126. if (assertEvalTemp == assertEvalTemp2) \
  127. assertEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, \
  128. __FILE__, __LINE__, true, "=="); \
  129. }
  130. #else // NODEBUG
  131. #define assert(x)
  132. #define assertEqual(x, y)
  133. #define assertNotEqual(x, y)
  134. #endif // NODEBUG
  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_