Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

global.h 5.6KB

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