PageRenderTime 26ms CodeModel.GetById 9ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 27#ifndef LL_LLDEFS_H
 28#define LL_LLDEFS_H
 29
 30#include "stdtypes.h"
 31
 32// Often used array indices
 33const U32	VX			= 0;
 34const U32	VY			= 1;
 35const U32	VZ			= 2;
 36const U32	VW			= 3;
 37const U32	VS			= 3;
 38
 39const U32	VRED		= 0;
 40const U32	VGREEN		= 1;
 41const U32	VBLUE		= 2;
 42const U32	VALPHA		= 3;
 43
 44const U32	INVALID_DIRECTION = 0xFFFFFFFF;
 45const U32	EAST		= 0;
 46const U32	NORTH		= 1;
 47const U32	WEST		= 2;
 48const U32	SOUTH		= 3;
 49
 50const U32	NORTHEAST	= 4;
 51const U32	NORTHWEST	= 5;
 52const U32	SOUTHWEST	= 6;
 53const U32	SOUTHEAST	= 7;
 54const U32	MIDDLE		= 8;
 55
 56const U8	EAST_MASK		= 0x1<<EAST;
 57const U8	NORTH_MASK		= 0x1<<NORTH;
 58const U8	WEST_MASK		= 0x1<<WEST;
 59const U8	SOUTH_MASK		= 0x1<<SOUTH;
 60
 61const U8	NORTHEAST_MASK	= NORTH_MASK | EAST_MASK;
 62const U8	NORTHWEST_MASK	= NORTH_MASK | WEST_MASK;
 63const U8	SOUTHWEST_MASK	= SOUTH_MASK | WEST_MASK;
 64const U8	SOUTHEAST_MASK	= SOUTH_MASK | EAST_MASK;
 65
 66const U32 gDirOpposite[8] = {2, 3, 0, 1, 6, 7, 4, 5};
 67const U32 gDirAdjacent[8][2] =  {
 68								{4, 7},
 69								{4, 5},
 70								{5, 6},
 71								{6, 7},
 72								{0, 1},
 73								{1, 2},
 74								{2, 3},
 75								{0, 3}
 76								};
 77
 78// Magnitude along the x and y axis
 79const S32 gDirAxes[8][2] = {
 80							{ 1, 0}, // east
 81							{ 0, 1}, // north
 82							{-1, 0}, // west
 83							{ 0,-1}, // south
 84							{ 1, 1}, // ne
 85							{-1, 1}, // nw
 86							{-1,-1}, // sw
 87							{ 1,-1}, // se
 88							};
 89
 90const S32 gDirMasks[8] = { 
 91							EAST_MASK,
 92							NORTH_MASK,
 93							WEST_MASK,
 94							SOUTH_MASK,
 95							NORTHEAST_MASK,
 96							NORTHWEST_MASK,
 97							SOUTHWEST_MASK,
 98							SOUTHEAST_MASK
 99							};
100
101// Sides of a box...
102//                  . Z      __.Y
103//                 /|\        /|       0 = NO_SIDE
104//                  |        /         1 = FRONT_SIDE   = +x
105//           +------|-----------+      2 = BACK_SIDE    = -x
106//          /|      |/     /   /|      3 = LEFT_SIDE    = +y
107//         / |     -5-   |/   / |      4 = RIGHT_SIDE   = -y
108//        /  |     /|   -3-  /  |      5 = TOP_SIDE     = +z
109//       +------------------+   |      6 = BOTTOM_SIDE  = -z
110//       |   |      |  /    |   |
111//       | |/|      | /     | |/|                   
112//       | 2 |    | *-------|-1--------> X           
113//       |/| |   -4-        |/| |                  
114//       |   +----|---------|---+
115//       |  /        /      |  /
116//       | /       -6-      | /
117//       |/        /        |/ 
118//       +------------------+
119const U32 NO_SIDE 		= 0;
120const U32 FRONT_SIDE 	= 1;
121const U32 BACK_SIDE 	= 2;
122const U32 LEFT_SIDE 	= 3;
123const U32 RIGHT_SIDE 	= 4;
124const U32 TOP_SIDE 		= 5;
125const U32 BOTTOM_SIDE 	= 6;
126
127const U8 LL_SOUND_FLAG_NONE =         0x0;
128const U8 LL_SOUND_FLAG_LOOP =         1<<0;
129const U8 LL_SOUND_FLAG_SYNC_MASTER =  1<<1;
130const U8 LL_SOUND_FLAG_SYNC_SLAVE =   1<<2;
131const U8 LL_SOUND_FLAG_SYNC_PENDING = 1<<3;
132const U8 LL_SOUND_FLAG_QUEUE =        1<<4;
133const U8 LL_SOUND_FLAG_STOP =         1<<5;
134const U8 LL_SOUND_FLAG_SYNC_MASK = LL_SOUND_FLAG_SYNC_MASTER | LL_SOUND_FLAG_SYNC_SLAVE | LL_SOUND_FLAG_SYNC_PENDING;
135
136//
137// *NOTE: These values may be used as hard-coded numbers in scanf() variants.
138//
139// --------------
140// DO NOT CHANGE.
141// --------------
142//
143const U32	LL_MAX_PATH		= 1024;		// buffer size of maximum path + filename string length
144
145// For strings we send in messages
146const U32	STD_STRING_BUF_SIZE	= 255;	// Buffer size
147const U32	STD_STRING_STR_LEN	= 254;	// Length of the string (not including \0)
148
149// *NOTE: This value is used as hard-coded numbers in scanf() variants.
150// DO NOT CHANGE.
151const U32	MAX_STRING			= STD_STRING_BUF_SIZE;	// Buffer size
152
153const U32	MAXADDRSTR		= 17;		// 123.567.901.345 = 15 chars + \0 + 1 for good luck
154
155// C++ is our friend. . . use template functions to make life easier!
156
157// specific inlines for basic types
158//
159// defined for all:
160//   llmin(a,b)
161//   llmax(a,b)
162//   llclamp(a,minimum,maximum)
163//
164// defined for F32, F64:
165//   llclampf(a)     // clamps a to [0.0 .. 1.0]
166//
167// defined for U16, U32, U64, S16, S32, S64, :
168//   llclampb(a)     // clamps a to [0 .. 255]
169//   				   
170
171template <class LLDATATYPE> 
172inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2)
173{
174	return (d1 > d2) ? d1 : d2;
175}
176
177template <class LLDATATYPE> 
178inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
179{
180	LLDATATYPE r = llmax(d1,d2);
181	return llmax(r, d3);
182}
183
184template <class LLDATATYPE> 
185inline LLDATATYPE llmax(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
186{
187	LLDATATYPE r1 = llmax(d1,d2);
188	LLDATATYPE r2 = llmax(d3,d4);
189	return llmax(r1, r2);
190}
191
192template <class LLDATATYPE> 
193inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2)
194{
195	return (d1 < d2) ? d1 : d2;
196}
197
198template <class LLDATATYPE> 
199inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3)
200{
201	LLDATATYPE r = llmin(d1,d2);
202	return (r < d3 ? r : d3);
203}
204
205template <class LLDATATYPE> 
206inline LLDATATYPE llmin(const LLDATATYPE& d1, const LLDATATYPE& d2, const LLDATATYPE& d3, const LLDATATYPE& d4)
207{
208	LLDATATYPE r1 = llmin(d1,d2);
209	LLDATATYPE r2 = llmin(d3,d4);
210	return llmin(r1, r2);
211}
212
213template <class LLDATATYPE> 
214inline LLDATATYPE llclamp(const LLDATATYPE& a, const LLDATATYPE& minval, const LLDATATYPE& maxval)
215{
216	if ( a < minval )
217	{
218		return minval;
219	}
220	else if ( a > maxval )
221	{
222		return maxval;
223	}
224	return a;
225}
226
227template <class LLDATATYPE> 
228inline LLDATATYPE llclampf(const LLDATATYPE& a)
229{
230	return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)1);
231}
232
233template <class LLDATATYPE> 
234inline LLDATATYPE llclampb(const LLDATATYPE& a)
235{
236	return llmin(llmax(a, (LLDATATYPE)0), (LLDATATYPE)255);
237}
238
239template <class LLDATATYPE> 
240inline void llswap(LLDATATYPE& lhs, LLDATATYPE& rhs)
241{
242	LLDATATYPE tmp = lhs;
243	lhs = rhs;
244	rhs = tmp;
245}
246
247#endif // LL_LLDEFS_H
248