/indra/llcommon/lldefs.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 248 lines · 148 code · 31 blank · 69 comment · 3 complexity · 42708ced1149179dd14ef6d4463b124f MD5 · raw file

  1. /**
  2. * @file lldefs.h
  3. * @brief Various generic constant definitions.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLDEFS_H
  27. #define LL_LLDEFS_H
  28. #include "stdtypes.h"
  29. // Often used array indices
  30. const U32 VX = 0;
  31. const U32 VY = 1;
  32. const U32 VZ = 2;
  33. const U32 VW = 3;
  34. const U32 VS = 3;
  35. const U32 VRED = 0;
  36. const U32 VGREEN = 1;
  37. const U32 VBLUE = 2;
  38. const U32 VALPHA = 3;
  39. const U32 INVALID_DIRECTION = 0xFFFFFFFF;
  40. const U32 EAST = 0;
  41. const U32 NORTH = 1;
  42. const U32 WEST = 2;
  43. const U32 SOUTH = 3;
  44. const U32 NORTHEAST = 4;
  45. const U32 NORTHWEST = 5;
  46. const U32 SOUTHWEST = 6;
  47. const U32 SOUTHEAST = 7;
  48. const U32 MIDDLE = 8;
  49. const U8 EAST_MASK = 0x1<<EAST;
  50. const U8 NORTH_MASK = 0x1<<NORTH;
  51. const U8 WEST_MASK = 0x1<<WEST;
  52. const U8 SOUTH_MASK = 0x1<<SOUTH;
  53. const U8 NORTHEAST_MASK = NORTH_MASK | EAST_MASK;
  54. const U8 NORTHWEST_MASK = NORTH_MASK | WEST_MASK;
  55. const U8 SOUTHWEST_MASK = SOUTH_MASK | WEST_MASK;
  56. const U8 SOUTHEAST_MASK = SOUTH_MASK | EAST_MASK;
  57. const U32 gDirOpposite[8] = {2, 3, 0, 1, 6, 7, 4, 5};
  58. const U32 gDirAdjacent[8][2] = {
  59. {4, 7},
  60. {4, 5},
  61. {5, 6},
  62. {6, 7},
  63. {0, 1},
  64. {1, 2},
  65. {2, 3},
  66. {0, 3}
  67. };
  68. // Magnitude along the x and y axis
  69. const S32 gDirAxes[8][2] = {
  70. { 1, 0}, // east
  71. { 0, 1}, // north
  72. {-1, 0}, // west
  73. { 0,-1}, // south
  74. { 1, 1}, // ne
  75. {-1, 1}, // nw
  76. {-1,-1}, // sw
  77. { 1,-1}, // se
  78. };
  79. const S32 gDirMasks[8] = {
  80. EAST_MASK,
  81. NORTH_MASK,
  82. WEST_MASK,
  83. SOUTH_MASK,
  84. NORTHEAST_MASK,
  85. NORTHWEST_MASK,
  86. SOUTHWEST_MASK,
  87. SOUTHEAST_MASK
  88. };
  89. // Sides of a box...
  90. // . Z __.Y
  91. // /|\ /| 0 = NO_SIDE
  92. // | / 1 = FRONT_SIDE = +x
  93. // +------|-----------+ 2 = BACK_SIDE = -x
  94. // /| |/ / /| 3 = LEFT_SIDE = +y
  95. // / | -5- |/ / | 4 = RIGHT_SIDE = -y
  96. // / | /| -3- / | 5 = TOP_SIDE = +z
  97. // +------------------+ | 6 = BOTTOM_SIDE = -z
  98. // | | | / | |
  99. // | |/| | / | |/|
  100. // | 2 | | *-------|-1--------> X
  101. // |/| | -4- |/| |
  102. // | +----|---------|---+
  103. // | / / | /
  104. // | / -6- | /
  105. // |/ / |/
  106. // +------------------+
  107. const U32 NO_SIDE = 0;
  108. const U32 FRONT_SIDE = 1;
  109. const U32 BACK_SIDE = 2;
  110. const U32 LEFT_SIDE = 3;
  111. const U32 RIGHT_SIDE = 4;
  112. const U32 TOP_SIDE = 5;
  113. const U32 BOTTOM_SIDE = 6;
  114. const U8 LL_SOUND_FLAG_NONE = 0x0;
  115. const U8 LL_SOUND_FLAG_LOOP = 1<<0;
  116. const U8 LL_SOUND_FLAG_SYNC_MASTER = 1<<1;
  117. const U8 LL_SOUND_FLAG_SYNC_SLAVE = 1<<2;
  118. const U8 LL_SOUND_FLAG_SYNC_PENDING = 1<<3;
  119. const U8 LL_SOUND_FLAG_QUEUE = 1<<4;
  120. const U8 LL_SOUND_FLAG_STOP = 1<<5;
  121. const U8 LL_SOUND_FLAG_SYNC_MASK = LL_SOUND_FLAG_SYNC_MASTER | LL_SOUND_FLAG_SYNC_SLAVE | LL_SOUND_FLAG_SYNC_PENDING;
  122. //
  123. // *NOTE: These values may be used as hard-coded numbers in scanf() variants.
  124. //
  125. // --------------
  126. // DO NOT CHANGE.
  127. // --------------
  128. //
  129. const U32 LL_MAX_PATH = 1024; // buffer size of maximum path + filename string length
  130. // For strings we send in messages
  131. const U32 STD_STRING_BUF_SIZE = 255; // Buffer size
  132. const U32 STD_STRING_STR_LEN = 254; // Length of the string (not including \0)
  133. // *NOTE: This value is used as hard-coded numbers in scanf() variants.
  134. // DO NOT CHANGE.
  135. const U32 MAX_STRING = STD_STRING_BUF_SIZE; // Buffer size
  136. const U32 MAXADDRSTR = 17; // 123.567.901.345 = 15 chars + \0 + 1 for good luck
  137. // C++ is our friend. . . use template functions to make life easier!
  138. // specific inlines for basic types
  139. //
  140. // defined for all:
  141. // llmin(a,b)
  142. // llmax(a,b)
  143. // llclamp(a,minimum,maximum)
  144. //
  145. // defined for F32, F64:
  146. // llclampf(a) // clamps a to [0.0 .. 1.0]
  147. //
  148. // defined for U16, U32, U64, S16, S32, S64, :
  149. // llclampb(a) // clamps a to [0 .. 255]
  150. //
  151. template <class LLDATATYPE>
  152. inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2)
  153. {
  154. return (d1 > d2) ? d1 : d2;
  155. }
  156. template <class LLDATATYPE>
  157. inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
  158. {
  159. LLDATATYPE r = llmax(d1,d2);
  160. return llmax(r, d3);
  161. }
  162. template <class LLDATATYPE>
  163. inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
  164. {
  165. LLDATATYPE r1 = llmax(d1,d2);
  166. LLDATATYPE r2 = llmax(d3,d4);
  167. return llmax(r1, r2);
  168. }
  169. template <class LLDATATYPE>
  170. inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2)
  171. {
  172. return (d1 < d2) ? d1 : d2;
  173. }
  174. template <class LLDATATYPE>
  175. inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
  176. {
  177. LLDATATYPE r = llmin(d1,d2);
  178. return (r < d3 ? r : d3);
  179. }
  180. template <class LLDATATYPE>
  181. inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
  182. {
  183. LLDATATYPE r1 = llmin(d1,d2);
  184. LLDATATYPE r2 = llmin(d3,d4);
  185. return llmin(r1, r2);
  186. }
  187. template <class LLDATATYPE>
  188. inline LLDATATYPE llclamp(const LLDATATYPE& a, const LLDATATYPE& minval, const LLDATATYPE& maxval)
  189. {
  190. if ( a < minval )
  191. {
  192. return minval;
  193. }
  194. else if ( a > maxval )
  195. {
  196. return maxval;
  197. }
  198. return a;
  199. }
  200. template <class LLDATATYPE>
  201. inline LLDATATYPE llclampf(const LLDATATYPE& a)
  202. {
  203. return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)1);
  204. }
  205. template <class LLDATATYPE>
  206. inline LLDATATYPE llclampb(const LLDATATYPE& a)
  207. {
  208. return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)255);
  209. }
  210. template <class LLDATATYPE>
  211. inline void llswap(LLDATATYPE& lhs, LLDATATYPE& rhs)
  212. {
  213. LLDATATYPE tmp = lhs;
  214. lhs = rhs;
  215. rhs = tmp;
  216. }
  217. #endif // LL_LLDEFS_H