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

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