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

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