Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

global.h 5.7KB

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. // 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. ActionEvents stringToActionEvent(const char *action);
  76. KeyboardButton stringToKeyboardButton(const char *key);
  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_