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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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, 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. template<typename T, typename U>
  111. [[noreturn]] void assertNotEqualImplementation(const char *exp, T a, U b, const char *file, int line, bool print) {
  112. const unsigned int maxSize = 128;
  113. void *callstack[maxSize];
  114. int frames = backtrace(callstack, maxSize);
  115. char **strs = backtrace_symbols(callstack, frames);
  116. std::cout << std::endl << "assertion failed:" << std::endl;
  117. std::cout << "\t" << exp << std::endl;
  118. if (print)
  119. std::cout << "\t (" << a << " == " << b << ")" << std::endl;
  120. std::cout << "in " << file << ":" << line << std::endl << std::endl;
  121. for (int i = 0; i < frames; i++)
  122. std::cout << strs[i] << std::endl;
  123. delete [] strs;
  124. abort();
  125. }
  126. // Evaluating x or y could have side-effects
  127. // So we only do it once!
  128. #define assert(x) { \
  129. auto assertEvalTemp = x; \
  130. if (!assertEvalTemp) \
  131. assertEqualImplementation(#x, assertEvalTemp, true, __FILE__, __LINE__, false); \
  132. }
  133. #define assertEqual(x, y) { \
  134. auto assertEvalTemp = x; \
  135. auto assertEvalTemp2 = y; \
  136. if (assertEvalTemp != assertEvalTemp2) \
  137. assertEqualImplementation(#x " == " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  138. }
  139. #define assertNotEqual(x, y) { \
  140. auto assertEvalTemp = x; \
  141. auto assertEvalTemp2 = y; \
  142. if (assertEvalTemp == assertEvalTemp2) \
  143. assertNotEqualImplementation(#x " != " #y, assertEvalTemp, assertEvalTemp2, __FILE__, __LINE__, true); \
  144. }
  145. #else // NDEBUG
  146. #define assert(x)
  147. #define assertEqual(x, y)
  148. #define assertNotEqual(x, y)
  149. #endif // NDEBUG
  150. #else // EXECINFO
  151. // Fall back to the default C assert
  152. #include <cassert>
  153. #define assertEqual(x, y) assert((x) == (y))
  154. #define assertNotEqual(x, y) assert((x) != (y))
  155. #endif // EXECINFO
  156. #endif // _GLOBAL_H_