aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmath
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmath')
-rw-r--r--linden/indra/llmath/CMakeLists.txt81
-rw-r--r--linden/indra/llmath/files.lst25
-rw-r--r--linden/indra/llmath/llcamera.h5
-rw-r--r--linden/indra/llmath/llcrc.cpp224
-rw-r--r--linden/indra/llmath/llcrc.h73
-rw-r--r--linden/indra/llmath/llline.cpp2
-rw-r--r--linden/indra/llmath/llmath.h52
-rw-r--r--linden/indra/llmath/llmath.vcproj348
-rw-r--r--linden/indra/llmath/llmath_vc8.vcproj488
-rw-r--r--linden/indra/llmath/llmath_vc9.vcproj489
-rw-r--r--linden/indra/llmath/llmd5.cpp531
-rw-r--r--linden/indra/llmath/llmd5.h133
-rw-r--r--linden/indra/llmath/lloctree.h2
-rw-r--r--linden/indra/llmath/llquaternion.cpp8
-rw-r--r--linden/indra/llmath/llquaternion.h2
-rw-r--r--linden/indra/llmath/llrand.cpp176
-rw-r--r--linden/indra/llmath/llrand.h132
-rw-r--r--linden/indra/llmath/llrect.h5
-rw-r--r--linden/indra/llmath/llsdutil_math.cpp172
-rw-r--r--linden/indra/llmath/llsphere.cpp2
-rw-r--r--linden/indra/llmath/lluuid.cpp923
-rw-r--r--linden/indra/llmath/lluuid.h330
-rw-r--r--linden/indra/llmath/llvolume.cpp420
-rw-r--r--linden/indra/llmath/llvolume.h100
-rw-r--r--linden/indra/llmath/llvolumemgr.cpp7
-rw-r--r--linden/indra/llmath/llvolumemgr.h2
-rw-r--r--linden/indra/llmath/v2math.cpp1
-rw-r--r--linden/indra/llmath/v2math.h14
-rw-r--r--linden/indra/llmath/v3color.h4
-rw-r--r--linden/indra/llmath/v3dmath.cpp6
-rw-r--r--linden/indra/llmath/v3dmath.h48
-rw-r--r--linden/indra/llmath/v3math.cpp80
-rw-r--r--linden/indra/llmath/v3math.h5
-rw-r--r--linden/indra/llmath/v4color.cpp28
-rw-r--r--linden/indra/llmath/v4color.h4
-rw-r--r--linden/indra/llmath/v4coloru.cpp8
-rw-r--r--linden/indra/llmath/v4coloru.h2
37 files changed, 841 insertions, 4091 deletions
diff --git a/linden/indra/llmath/CMakeLists.txt b/linden/indra/llmath/CMakeLists.txt
new file mode 100644
index 0000000..6a329fa
--- /dev/null
+++ b/linden/indra/llmath/CMakeLists.txt
@@ -0,0 +1,81 @@
1# -*- cmake -*-
2
3project(llmath)
4
5include(00-Common)
6include(LLCommon)
7
8include_directories(
9 ${LLCOMMON_INCLUDE_DIRS}
10 )
11
12set(llmath_SOURCE_FILES
13 llbboxlocal.cpp
14 llcamera.cpp
15 llcoordframe.cpp
16 llline.cpp
17 llperlin.cpp
18 llquaternion.cpp
19 llrect.cpp
20 llsphere.cpp
21 llvolume.cpp
22 llvolumemgr.cpp
23 llsdutil_math.cpp
24 m3math.cpp
25 m4math.cpp
26 raytrace.cpp
27 v2math.cpp
28 v3color.cpp
29 v3dmath.cpp
30 v3math.cpp
31 v4color.cpp
32 v4coloru.cpp
33 v4math.cpp
34 xform.cpp
35 )
36
37set(llmath_HEADER_FILES
38 CMakeLists.txt
39
40 camera.h
41 coordframe.h
42 llbboxlocal.h
43 llcamera.h
44 llcoord.h
45 llcoordframe.h
46 llinterp.h
47 llline.h
48 llmath.h
49 lloctree.h
50 llperlin.h
51 llplane.h
52 llquantize.h
53 llquaternion.h
54 llrect.h
55 llsphere.h
56 lltreenode.h
57 llv4math.h
58 llv4matrix3.h
59 llv4matrix4.h
60 llv4vector3.h
61 llvolume.h
62 llvolumemgr.h
63 m3math.h
64 m4math.h
65 raytrace.h
66 v2math.h
67 v3color.h
68 v3dmath.h
69 v3math.h
70 v4color.h
71 v4coloru.h
72 v4math.h
73 xform.h
74 )
75
76set_source_files_properties(${llmath_HEADER_FILES}
77 PROPERTIES HEADER_FILE_ONLY TRUE)
78
79list(APPEND llmath_SOURCE_FILES ${llmath_HEADER_FILES})
80
81add_library (llmath ${llmath_SOURCE_FILES})
diff --git a/linden/indra/llmath/files.lst b/linden/indra/llmath/files.lst
deleted file mode 100644
index 1001a6d..0000000
--- a/linden/indra/llmath/files.lst
+++ /dev/null
@@ -1,25 +0,0 @@
1llmath/llbboxlocal.cpp
2llmath/llcamera.cpp
3llmath/llcoordframe.cpp
4llmath/llcrc.cpp
5llmath/llline.cpp
6llmath/llmd5.cpp
7llmath/llperlin.cpp
8llmath/llquaternion.cpp
9llmath/llrand.cpp
10llmath/llrect.cpp
11llmath/llsphere.cpp
12llmath/lluuid.cpp
13llmath/llvolume.cpp
14llmath/llvolumemgr.cpp
15llmath/m3math.cpp
16llmath/m4math.cpp
17llmath/raytrace.cpp
18llmath/v2math.cpp
19llmath/v3color.cpp
20llmath/v3dmath.cpp
21llmath/v3math.cpp
22llmath/v4color.cpp
23llmath/v4coloru.cpp
24llmath/v4math.cpp
25llmath/xform.cpp
diff --git a/linden/indra/llmath/llcamera.h b/linden/indra/llmath/llcamera.h
index 7066b9f..2884338 100644
--- a/linden/indra/llmath/llcamera.h
+++ b/linden/indra/llmath/llcamera.h
@@ -115,11 +115,12 @@ protected:
115 LLPlane mWorldPlanes[PLANE_NUM]; 115 LLPlane mWorldPlanes[PLANE_NUM];
116 LLPlane mHorizPlanes[HORIZ_PLANE_NUM]; 116 LLPlane mHorizPlanes[HORIZ_PLANE_NUM];
117 117
118 typedef struct 118 struct frustum_plane
119 { 119 {
120 frustum_plane() : mask(0) {}
120 LLPlane p; 121 LLPlane p;
121 U8 mask; 122 U8 mask;
122 } frustum_plane; 123 };
123 frustum_plane mAgentPlanes[7]; //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP 124 frustum_plane mAgentPlanes[7]; //frustum planes in agent space a la gluUnproject (I'm a bastard, I know) - DaveP
124 125
125 U32 mPlaneCount; //defaults to 6, if setUserClipPlane is called, uses user supplied clip plane in 126 U32 mPlaneCount; //defaults to 6, if setUserClipPlane is called, uses user supplied clip plane in
diff --git a/linden/indra/llmath/llcrc.cpp b/linden/indra/llmath/llcrc.cpp
deleted file mode 100644
index 447521a..0000000
--- a/linden/indra/llmath/llcrc.cpp
+++ /dev/null
@@ -1,224 +0,0 @@
1/**
2 * @file llcrc.cpp
3 * @brief implementation of the crc class.
4 *
5 * $LicenseInfo:firstyear=2002&license=viewergpl$
6 *
7 * Copyright (c) 2002-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "linden_common.h"
33
34#include "llcrc.h"
35#include "llerror.h"
36
37/* Copyright (C) 1986 Gary S. Brown. You may use this program, or
38 code or tables extracted from it, as desired without restriction.*/
39
40/* First, the polynomial itself and its table of feedback terms. The */
41/* polynomial is */
42/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
43/* Note that we take it "backwards" and put the highest-order term in */
44/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
45/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
46/* the MSB being 1. */
47
48/* Note that the usual hardware shift register implementation, which */
49/* is what we're using (we're merely optimizing it by doing eight-bit */
50/* chunks at a time) shifts bits into the lowest-order term. In our */
51/* implementation, that means shifting towards the right. Why do we */
52/* do it this way? Because the calculated CRC must be transmitted in */
53/* order from highest-order term to lowest-order term. UARTs transmit */
54/* characters in order from LSB to MSB. By storing the CRC this way, */
55/* we hand it to the UART in the order low-byte to high-byte; the UART */
56/* sends each low-bit to hight-bit; and the result is transmission bit */
57/* by bit from highest- to lowest-order term without requiring any bit */
58/* shuffling on our part. Reception works similarly. */
59
60/* The feedback terms table consists of 256, 32-bit entries. Notes: */
61/* */
62/* 1. The table can be generated at runtime if desired; code to do so */
63/* is shown later. It might not be obvious, but the feedback */
64/* terms simply represent the results of eight shift/xor opera- */
65/* tions for all combinations of data and CRC register values. */
66/* */
67/* 2. The CRC accumulation logic is the same for all CRC polynomials, */
68/* be they sixteen or thirty-two bits wide. You simply choose the */
69/* appropriate table. Alternatively, because the table can be */
70/* generated at runtime, you can start by generating the table for */
71/* the polynomial in question and use exactly the same "updcrc", */
72/* if your application needn't simultaneously handle two CRC */
73/* polynomials. (Note, however, that XMODEM is strange.) */
74/* */
75/* 3. For 16-bit CRCs, the table entries need be only 16 bits wide; */
76/* of course, 32-bit entries work OK if the high 16 bits are zero. */
77/* */
78/* 4. The values must be right-shifted by eight bits by the "updcrc" */
79/* logic; the shift must be unsigned (bring in zeroes). On some */
80/* hardware you could probably optimize the shift in assembler by */
81/* using byte-swap instructions. */
82
83///----------------------------------------------------------------------------
84/// Local function declarations, constants, enums, and typedefs
85///----------------------------------------------------------------------------
86
87#define UPDC32(octet,crc) (crc_32_tab[((crc) \
88 ^ ((U8)octet)) & 0xff] ^ ((crc) >> 8))
89
90
91static U32 crc_32_tab[] = { /* CRC polynomial 0xedb88320 */
920x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
930xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
940x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
950xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
960x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
970xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
980x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
990xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
1000x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
1010xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
1020x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
1030x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
1040x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
1050x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
1060x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
1070x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
1080x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
1090xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
1100x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
1110xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
1120x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
1130xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
1140xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
1150x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
1160xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
1170x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
1180xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
1190x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
1200xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
1210x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
1220xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
1230x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
1240x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
1250x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
1260x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
1270x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
1280x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
1290x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
1300xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
1310x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
1320xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
1330x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
1340xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
135};
136
137
138///----------------------------------------------------------------------------
139/// Class llcrc
140///----------------------------------------------------------------------------
141
142// Default constructor
143LLCRC::LLCRC() : mCurrent(0xffffffff)
144{
145}
146
147
148U32 LLCRC::getCRC() const
149{
150 return ~mCurrent;
151}
152
153void LLCRC::update(U8 next_byte)
154{
155 mCurrent = UPDC32(next_byte, mCurrent);
156}
157
158void LLCRC::update(const U8* buffer, size_t buffer_size)
159{
160 for (size_t i = 0; i < buffer_size; i++)
161 {
162 mCurrent = UPDC32(buffer[i], mCurrent);
163 }
164}
165
166void LLCRC::update(const char* filename)
167{
168 if (!filename)
169 {
170 llerrs << "No filename specified" << llendl;
171 return;
172 }
173
174 LLFILE* fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */
175
176 if (fp)
177 {
178 fseek(fp, 0, SEEK_END);
179 long size = ftell(fp);
180
181 fseek(fp, 0, SEEK_SET);
182
183 if (size > 0)
184 {
185 U8* data = new U8[size];
186 size_t nread;
187
188 nread = fread(data, 1, size, fp);
189 fclose(fp);
190
191 if (nread < (size_t) size)
192 {
193 llwarns << "Short read on " << filename << llendl;
194 }
195
196 update(data, nread);
197 delete[] data;
198 }
199 }
200}
201
202
203#ifdef _DEBUG
204BOOL LLCRC::testHarness()
205{
206 const S32 TEST_BUFFER_SIZE = 16;
207 const char TEST_BUFFER[TEST_BUFFER_SIZE] = "hello &#$)$&Nd0"; /* Flawfinder: ignore */
208 LLCRC c1, c2;
209 c1.update((U8*)TEST_BUFFER, TEST_BUFFER_SIZE - 1);
210 char* rh = (char*)TEST_BUFFER;
211 while(*rh != '\0')
212 {
213 c2.update(*rh);
214 ++rh;
215 }
216 return(c1.getCRC() == c2.getCRC());
217}
218#endif
219
220
221
222///----------------------------------------------------------------------------
223/// Local function definitions
224///----------------------------------------------------------------------------
diff --git a/linden/indra/llmath/llcrc.h b/linden/indra/llmath/llcrc.h
deleted file mode 100644
index 59f58ce..0000000
--- a/linden/indra/llmath/llcrc.h
+++ /dev/null
@@ -1,73 +0,0 @@
1/**
2 * @file llcrc.h
3 * @brief LLCRC class header file.
4 *
5 * $LicenseInfo:firstyear=2002&license=viewergpl$
6 *
7 * Copyright (c) 2002-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#ifndef LL_LLCRC_H
33#define LL_LLCRC_H
34
35//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36// Class llcrc
37//
38// Simple 32 bit crc. To use, instantiate an LLCRC instance and feed
39// it the bytes you want to check. It will update the internal crc as
40// you go, and you can qery it at the end. As a horribly inefficient
41// example (don't try this at work kids):
42//
43// LLCRC crc;
44// LLFILE* fp = LLFile::fopen(filename,"rb");
45// while(!feof(fp)) {
46// crc.update(fgetc(fp));
47// }
48// fclose(fp);
49// llinfos << "File crc: " << crc.getCRC() << llendl;
50//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
52class LLCRC
53{
54protected:
55 U32 mCurrent;
56
57public:
58 LLCRC();
59
60 U32 getCRC() const;
61 void update(U8 next_byte);
62 void update(const U8* buffer, size_t buffer_size);
63 void update(const char *filename);
64
65#ifdef _DEBUG
66 // This function runs tests to make sure the crc is
67 // working. Returns TRUE if it is.
68 static BOOL testHarness();
69#endif
70};
71
72
73#endif // LL_LLCRC_H
diff --git a/linden/indra/llmath/llline.cpp b/linden/indra/llmath/llline.cpp
index 9c41efb..cfd3f56 100644
--- a/linden/indra/llmath/llline.cpp
+++ b/linden/indra/llmath/llline.cpp
@@ -20,6 +20,8 @@
20 * $/LicenseInfo$ 20 * $/LicenseInfo$
21 */ 21 */
22 22
23#include "linden_common.h"
24
23#include "llline.h" 25#include "llline.h"
24#include "llrand.h" 26#include "llrand.h"
25 27
diff --git a/linden/indra/llmath/llmath.h b/linden/indra/llmath/llmath.h
index 4a6358d..82ab197 100644
--- a/linden/indra/llmath/llmath.h
+++ b/linden/indra/llmath/llmath.h
@@ -33,9 +33,10 @@
33#define LLMATH_H 33#define LLMATH_H
34 34
35#include <cmath> 35#include <cmath>
36//#include <math.h> 36#include <cstdlib>
37//#include <stdlib.h>
38#include "lldefs.h" 37#include "lldefs.h"
38#include "llstl.h" // *TODO: Remove when LLString is gone
39#include "llstring.h" // *TODO: Remove when LLString is gone
39 40
40// work around for Windows & older gcc non-standard function names. 41// work around for Windows & older gcc non-standard function names.
41#if LL_WINDOWS 42#if LL_WINDOWS
@@ -93,6 +94,9 @@ const F32 F_APPROXIMATELY_ZERO = 0.00001f;
93const F32 F_LN2 = 0.69314718056f; 94const F32 F_LN2 = 0.69314718056f;
94const F32 OO_LN2 = 1.4426950408889634073599246810019f; 95const F32 OO_LN2 = 1.4426950408889634073599246810019f;
95 96
97const F32 F_ALMOST_ZERO = 0.0001f;
98const F32 F_ALMOST_ONE = 1.0f - F_ALMOST_ZERO;
99
96// BUG: Eliminate in favor of F_APPROXIMATELY_ZERO above? 100// BUG: Eliminate in favor of F_APPROXIMATELY_ZERO above?
97const F32 FP_MAG_THRESHOLD = 0.0000001f; 101const F32 FP_MAG_THRESHOLD = 0.0000001f;
98 102
@@ -102,13 +106,13 @@ inline BOOL is_approx_zero( F32 f ) { return (-F_APPROXIMATELY_ZERO < f) && (f <
102inline BOOL is_approx_equal(F32 x, F32 y) 106inline BOOL is_approx_equal(F32 x, F32 y)
103{ 107{
104 const S32 COMPARE_MANTISSA_UP_TO_BIT = 0x02; 108 const S32 COMPARE_MANTISSA_UP_TO_BIT = 0x02;
105 return (abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); 109 return (std::abs((S32) ((U32&)x - (U32&)y) ) < COMPARE_MANTISSA_UP_TO_BIT);
106} 110}
107 111
108inline BOOL is_approx_equal(F64 x, F64 y) 112inline BOOL is_approx_equal(F64 x, F64 y)
109{ 113{
110 const S64 COMPARE_MANTISSA_UP_TO_BIT = 0x02; 114 const S64 COMPARE_MANTISSA_UP_TO_BIT = 0x02;
111 return (abs((S32) ((U64&)x - (U64&)y) ) < COMPARE_MANTISSA_UP_TO_BIT); 115 return (std::abs((S32) ((U64&)x - (U64&)y) ) < COMPARE_MANTISSA_UP_TO_BIT);
112} 116}
113 117
114inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits) 118inline BOOL is_approx_equal_fraction(F32 x, F32 y, U32 frac_bits)
@@ -155,17 +159,17 @@ inline BOOL is_approx_equal_fraction(F64 x, F64 y, U32 frac_bits)
155 159
156inline S32 llabs(const S32 a) 160inline S32 llabs(const S32 a)
157{ 161{
158 return S32(labs(a)); 162 return S32(std::labs(a));
159} 163}
160 164
161inline F32 llabs(const F32 a) 165inline F32 llabs(const F32 a)
162{ 166{
163 return F32(fabs(a)); 167 return F32(std::fabs(a));
164} 168}
165 169
166inline F64 llabs(const F64 a) 170inline F64 llabs(const F64 a)
167{ 171{
168 return F64(fabs(a)); 172 return F64(std::fabs(a));
169} 173}
170 174
171inline S32 lltrunc( F32 f ) 175inline S32 lltrunc( F32 f )
@@ -473,8 +477,8 @@ inline F32 llsimple_angle(F32 angle)
473 return angle; 477 return angle;
474} 478}
475 479
476//calculate the nearesr power of two number for val, bounded by max_power_two 480//SDK - Renamed this to get_lower_power_two, since this is what this actually does.
477inline U32 get_nearest_power_two(U32 val, U32 max_power_two) 481inline U32 get_lower_power_two(U32 val, U32 max_power_two)
478{ 482{
479 if(!max_power_two) 483 if(!max_power_two)
480 { 484 {
@@ -489,4 +493,34 @@ inline U32 get_nearest_power_two(U32 val, U32 max_power_two)
489 493
490 return max_power_two ; 494 return max_power_two ;
491} 495}
496
497// calculate next highest power of two, limited by max_power_two
498// This is taken from a brilliant little code snipped on http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
499// Basically we convert the binary to a solid string of 1's with the same
500// number of digits, then add one. We subtract 1 initially to handle
501// the case where the number passed in is actually a power of two.
502// WARNING: this only works with 32 bit ints.
503inline U32 get_next_power_two(U32 val, U32 max_power_two)
504{
505 if(!max_power_two)
506 {
507 max_power_two = 1 << 31 ;
508 }
509
510 if(val >= max_power_two)
511 {
512 return max_power_two;
513 }
514
515 val--;
516 val = (val >> 1) | val;
517 val = (val >> 2) | val;
518 val = (val >> 4) | val;
519 val = (val >> 8) | val;
520 val = (val >> 16) | val;
521 val++;
522
523 return val;
524}
525
492#endif 526#endif
diff --git a/linden/indra/llmath/llmath.vcproj b/linden/indra/llmath/llmath.vcproj
deleted file mode 100644
index d05505e..0000000
--- a/linden/indra/llmath/llmath.vcproj
+++ /dev/null
@@ -1,348 +0,0 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.10"
5 Name="llmath"
6 ProjectGUID="{E87FD9BE-BE42-4EA3-BF4D-D992223046D9}"
7 Keyword="Win32Proj">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
16 IntermediateDirectory="$(ConfigurationName)"
17 ConfigurationType="4"
18 CharacterSet="1">
19 <Tool
20 Name="VCCLCompilerTool"
21 Optimization="0"
22 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
23 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;LL_DEBUG"
24 MinimalRebuild="TRUE"
25 BasicRuntimeChecks="3"
26 RuntimeLibrary="1"
27 StructMemberAlignment="4"
28 ForceConformanceInForLoopScope="TRUE"
29 UsePrecompiledHeader="0"
30 WarningLevel="3"
31 WarnAsError="TRUE"
32 Detect64BitPortabilityProblems="FALSE"
33 DebugInformationFormat="4"/>
34 <Tool
35 Name="VCCustomBuildTool"/>
36 <Tool
37 Name="VCLibrarianTool"
38 OutputFile="$(OutDir)/llmath.lib"/>
39 <Tool
40 Name="VCMIDLTool"/>
41 <Tool
42 Name="VCPostBuildEventTool"/>
43 <Tool
44 Name="VCPreBuildEventTool"/>
45 <Tool
46 Name="VCPreLinkEventTool"/>
47 <Tool
48 Name="VCResourceCompilerTool"/>
49 <Tool
50 Name="VCWebServiceProxyGeneratorTool"/>
51 <Tool
52 Name="VCXMLDataGeneratorTool"/>
53 <Tool
54 Name="VCManagedWrapperGeneratorTool"/>
55 <Tool
56 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
57 </Configuration>
58 <Configuration
59 Name="Release|Win32"
60 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
61 IntermediateDirectory="$(ConfigurationName)"
62 ConfigurationType="4"
63 CharacterSet="1">
64 <Tool
65 Name="VCCLCompilerTool"
66 AdditionalOptions="/Oy-"
67 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
68 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE"
69 RuntimeLibrary="0"
70 StructMemberAlignment="0"
71 ForceConformanceInForLoopScope="TRUE"
72 UsePrecompiledHeader="0"
73 WarningLevel="3"
74 WarnAsError="TRUE"
75 Detect64BitPortabilityProblems="FALSE"
76 DebugInformationFormat="3"/>
77 <Tool
78 Name="VCCustomBuildTool"/>
79 <Tool
80 Name="VCLibrarianTool"
81 OutputFile="$(OutDir)/llmath.lib"/>
82 <Tool
83 Name="VCMIDLTool"/>
84 <Tool
85 Name="VCPostBuildEventTool"/>
86 <Tool
87 Name="VCPreBuildEventTool"/>
88 <Tool
89 Name="VCPreLinkEventTool"/>
90 <Tool
91 Name="VCResourceCompilerTool"/>
92 <Tool
93 Name="VCWebServiceProxyGeneratorTool"/>
94 <Tool
95 Name="VCXMLDataGeneratorTool"/>
96 <Tool
97 Name="VCManagedWrapperGeneratorTool"/>
98 <Tool
99 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
100 </Configuration>
101 <Configuration
102 Name="ReleaseNoOpt|Win32"
103 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
104 IntermediateDirectory="$(ConfigurationName)"
105 ConfigurationType="4"
106 CharacterSet="1">
107 <Tool
108 Name="VCCLCompilerTool"
109 AdditionalOptions="/Oy-"
110 Optimization="0"
111 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
112 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;LL_RELEASE"
113 RuntimeLibrary="0"
114 StructMemberAlignment="0"
115 ForceConformanceInForLoopScope="TRUE"
116 UsePrecompiledHeader="0"
117 BrowseInformation="0"
118 WarningLevel="3"
119 WarnAsError="TRUE"
120 Detect64BitPortabilityProblems="FALSE"
121 DebugInformationFormat="3"/>
122 <Tool
123 Name="VCCustomBuildTool"/>
124 <Tool
125 Name="VCLibrarianTool"
126 OutputFile="$(OutDir)/llmath.lib"/>
127 <Tool
128 Name="VCMIDLTool"/>
129 <Tool
130 Name="VCPostBuildEventTool"/>
131 <Tool
132 Name="VCPreBuildEventTool"/>
133 <Tool
134 Name="VCPreLinkEventTool"/>
135 <Tool
136 Name="VCResourceCompilerTool"/>
137 <Tool
138 Name="VCWebServiceProxyGeneratorTool"/>
139 <Tool
140 Name="VCXMLDataGeneratorTool"/>
141 <Tool
142 Name="VCManagedWrapperGeneratorTool"/>
143 <Tool
144 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
145 </Configuration>
146 </Configurations>
147 <References>
148 </References>
149 <Files>
150 <Filter
151 Name="Source Files"
152 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
153 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
154 <File
155 RelativePath=".\llbboxlocal.cpp">
156 </File>
157 <File
158 RelativePath=".\llcamera.cpp">
159 </File>
160 <File
161 RelativePath=".\llcoordframe.cpp">
162 </File>
163 <File
164 RelativePath=".\llcrc.cpp">
165 </File>
166 <File
167 RelativePath=".\llline.cpp">
168 </File>
169 <File
170 RelativePath=".\llmd5.cpp">
171 </File>
172 <File
173 RelativePath=".\llperlin.cpp">
174 </File>
175 <File
176 RelativePath=".\llquaternion.cpp">
177 </File>
178 <File
179 RelativePath=".\llrand.cpp">
180 </File>
181 <File
182 RelativePath=".\llrect.cpp">
183 </File>
184 <File
185 RelativePath=".\llsphere.cpp">
186 </File>
187 <File
188 RelativePath=".\lluuid.cpp">
189 </File>
190 <File
191 RelativePath=".\llvolume.cpp">
192 </File>
193 <File
194 RelativePath=".\llvolumemgr.cpp">
195 </File>
196 <File
197 RelativePath=".\m3math.cpp">
198 </File>
199 <File
200 RelativePath=".\m4math.cpp">
201 </File>
202 <File
203 RelativePath=".\raytrace.cpp">
204 </File>
205 <File
206 RelativePath=".\v2math.cpp">
207 </File>
208 <File
209 RelativePath=".\v3color.cpp">
210 </File>
211 <File
212 RelativePath=".\v3dmath.cpp">
213 </File>
214 <File
215 RelativePath=".\v3math.cpp">
216 </File>
217 <File
218 RelativePath=".\v4color.cpp">
219 </File>
220 <File
221 RelativePath=".\v4coloru.cpp">
222 </File>
223 <File
224 RelativePath=".\v4math.cpp">
225 </File>
226 <File
227 RelativePath=".\xform.cpp">
228 </File>
229 </Filter>
230 <Filter
231 Name="Header Files"
232 Filter="h;hpp;hxx;hm;inl;inc;xsd"
233 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
234 <File
235 RelativePath=".\llbboxlocal.h">
236 </File>
237 <File
238 RelativePath=".\llcamera.h">
239 </File>
240 <File
241 RelativePath=".\llcoord.h">
242 </File>
243 <File
244 RelativePath=".\llcoordframe.h">
245 </File>
246 <File
247 RelativePath=".\llcrc.h">
248 </File>
249 <File
250 RelativePath=".\llinterp.h">
251 </File>
252 <File
253 RelativePath=".\llline.h">
254 </File>
255 <File
256 RelativePath=".\llmath.h">
257 </File>
258 <File
259 RelativePath=".\llmd5.h">
260 </File>
261 <File
262 RelativePath=".\lloctree.h">
263 </File>
264 <File
265 RelativePath=".\llperlin.h">
266 </File>
267 <File
268 RelativePath=".\llquantize.h">
269 </File>
270 <File
271 RelativePath=".\llquaternion.h">
272 </File>
273 <File
274 RelativePath=".\llrand.h">
275 </File>
276 <File
277 RelativePath=".\llrect.h">
278 </File>
279 <File
280 RelativePath=".\llsphere.h">
281 </File>
282 <File
283 RelativePath=".\lltreenode.h">
284 </File>
285 <File
286 RelativePath=".\lluuid.h">
287 </File>
288 <File
289 RelativePath=".\llv4math.h">
290 </File>
291 <File
292 RelativePath=".\llv4matrix3.h">
293 </File>
294 <File
295 RelativePath=".\llv4matrix4.h">
296 </File>
297 <File
298 RelativePath=".\llv4vector3.h">
299 </File>
300 <File
301 RelativePath=".\llvolume.h">
302 </File>
303 <File
304 RelativePath=".\llvolumemgr.h">
305 </File>
306 <File
307 RelativePath=".\m3math.h">
308 </File>
309 <File
310 RelativePath=".\m4math.h">
311 </File>
312 <File
313 RelativePath=".\raytrace.h">
314 </File>
315 <File
316 RelativePath=".\v2math.h">
317 </File>
318 <File
319 RelativePath=".\v3color.h">
320 </File>
321 <File
322 RelativePath=".\v3dmath.h">
323 </File>
324 <File
325 RelativePath=".\v3math.h">
326 </File>
327 <File
328 RelativePath=".\v4color.h">
329 </File>
330 <File
331 RelativePath=".\v4coloru.h">
332 </File>
333 <File
334 RelativePath=".\v4math.h">
335 </File>
336 <File
337 RelativePath=".\xform.h">
338 </File>
339 </Filter>
340 <Filter
341 Name="Resource Files"
342 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
343 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
344 </Filter>
345 </Files>
346 <Globals>
347 </Globals>
348</VisualStudioProject>
diff --git a/linden/indra/llmath/llmath_vc8.vcproj b/linden/indra/llmath/llmath_vc8.vcproj
deleted file mode 100644
index 3b4413a..0000000
--- a/linden/indra/llmath/llmath_vc8.vcproj
+++ /dev/null
@@ -1,488 +0,0 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="8.00"
5 Name="llmath"
6 ProjectGUID="{E87FD9BE-BE42-4EA3-BF4D-D992223046D9}"
7 RootNamespace="llmath"
8 Keyword="Win32Proj"
9 >
10 <Platforms>
11 <Platform
12 Name="Win32"
13 />
14 </Platforms>
15 <ToolFiles>
16 </ToolFiles>
17 <Configurations>
18 <Configuration
19 Name="Debug|Win32"
20 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
21 IntermediateDirectory="$(ConfigurationName)"
22 ConfigurationType="4"
23 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
24 CharacterSet="1"
25 >
26 <Tool
27 Name="VCPreBuildEventTool"
28 />
29 <Tool
30 Name="VCCustomBuildTool"
31 />
32 <Tool
33 Name="VCXMLDataGeneratorTool"
34 />
35 <Tool
36 Name="VCWebServiceProxyGeneratorTool"
37 />
38 <Tool
39 Name="VCMIDLTool"
40 />
41 <Tool
42 Name="VCCLCompilerTool"
43 Optimization="0"
44 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
45 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_DEBUG"
46 MinimalRebuild="true"
47 BasicRuntimeChecks="3"
48 RuntimeLibrary="1"
49 StructMemberAlignment="4"
50 TreatWChar_tAsBuiltInType="false"
51 ForceConformanceInForLoopScope="true"
52 UsePrecompiledHeader="0"
53 WarningLevel="3"
54 WarnAsError="true"
55 Detect64BitPortabilityProblems="false"
56 DebugInformationFormat="4"
57 />
58 <Tool
59 Name="VCManagedResourceCompilerTool"
60 />
61 <Tool
62 Name="VCResourceCompilerTool"
63 />
64 <Tool
65 Name="VCPreLinkEventTool"
66 />
67 <Tool
68 Name="VCLibrarianTool"
69 OutputFile="$(OutDir)/llmath.lib"
70 />
71 <Tool
72 Name="VCALinkTool"
73 />
74 <Tool
75 Name="VCXDCMakeTool"
76 />
77 <Tool
78 Name="VCBscMakeTool"
79 />
80 <Tool
81 Name="VCFxCopTool"
82 />
83 <Tool
84 Name="VCPostBuildEventTool"
85 />
86 </Configuration>
87 <Configuration
88 Name="Release|Win32"
89 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
90 IntermediateDirectory="$(ConfigurationName)"
91 ConfigurationType="4"
92 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
93 CharacterSet="1"
94 >
95 <Tool
96 Name="VCPreBuildEventTool"
97 />
98 <Tool
99 Name="VCCustomBuildTool"
100 />
101 <Tool
102 Name="VCXMLDataGeneratorTool"
103 />
104 <Tool
105 Name="VCWebServiceProxyGeneratorTool"
106 />
107 <Tool
108 Name="VCMIDLTool"
109 />
110 <Tool
111 Name="VCCLCompilerTool"
112 AdditionalOptions="/Oy-"
113 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
114 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
115 RuntimeLibrary="0"
116 StructMemberAlignment="0"
117 TreatWChar_tAsBuiltInType="false"
118 ForceConformanceInForLoopScope="true"
119 UsePrecompiledHeader="0"
120 WarningLevel="3"
121 WarnAsError="true"
122 Detect64BitPortabilityProblems="false"
123 DebugInformationFormat="3"
124 />
125 <Tool
126 Name="VCManagedResourceCompilerTool"
127 />
128 <Tool
129 Name="VCResourceCompilerTool"
130 />
131 <Tool
132 Name="VCPreLinkEventTool"
133 />
134 <Tool
135 Name="VCLibrarianTool"
136 OutputFile="$(OutDir)/llmath.lib"
137 />
138 <Tool
139 Name="VCALinkTool"
140 />
141 <Tool
142 Name="VCXDCMakeTool"
143 />
144 <Tool
145 Name="VCBscMakeTool"
146 />
147 <Tool
148 Name="VCFxCopTool"
149 />
150 <Tool
151 Name="VCPostBuildEventTool"
152 />
153 </Configuration>
154 <Configuration
155 Name="ReleaseNoOpt|Win32"
156 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
157 IntermediateDirectory="$(ConfigurationName)"
158 ConfigurationType="4"
159 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
160 CharacterSet="1"
161 >
162 <Tool
163 Name="VCPreBuildEventTool"
164 />
165 <Tool
166 Name="VCCustomBuildTool"
167 />
168 <Tool
169 Name="VCXMLDataGeneratorTool"
170 />
171 <Tool
172 Name="VCWebServiceProxyGeneratorTool"
173 />
174 <Tool
175 Name="VCMIDLTool"
176 />
177 <Tool
178 Name="VCCLCompilerTool"
179 AdditionalOptions="/Oy-"
180 Optimization="0"
181 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
182 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
183 RuntimeLibrary="0"
184 StructMemberAlignment="0"
185 TreatWChar_tAsBuiltInType="false"
186 ForceConformanceInForLoopScope="true"
187 UsePrecompiledHeader="0"
188 BrowseInformation="0"
189 WarningLevel="3"
190 WarnAsError="true"
191 Detect64BitPortabilityProblems="false"
192 DebugInformationFormat="3"
193 />
194 <Tool
195 Name="VCManagedResourceCompilerTool"
196 />
197 <Tool
198 Name="VCResourceCompilerTool"
199 />
200 <Tool
201 Name="VCPreLinkEventTool"
202 />
203 <Tool
204 Name="VCLibrarianTool"
205 OutputFile="$(OutDir)/llmath.lib"
206 />
207 <Tool
208 Name="VCALinkTool"
209 />
210 <Tool
211 Name="VCXDCMakeTool"
212 />
213 <Tool
214 Name="VCBscMakeTool"
215 />
216 <Tool
217 Name="VCFxCopTool"
218 />
219 <Tool
220 Name="VCPostBuildEventTool"
221 />
222 </Configuration>
223 </Configurations>
224 <References>
225 </References>
226 <Files>
227 <Filter
228 Name="Source Files"
229 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
230 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
231 >
232 <File
233 RelativePath=".\llbboxlocal.cpp"
234 >
235 </File>
236 <File
237 RelativePath=".\llcamera.cpp"
238 >
239 </File>
240 <File
241 RelativePath=".\llcoordframe.cpp"
242 >
243 </File>
244 <File
245 RelativePath=".\llcrc.cpp"
246 >
247 </File>
248 <File
249 RelativePath=".\llline.cpp"
250 >
251 </File>
252 <File
253 RelativePath=".\llmd5.cpp"
254 >
255 </File>
256 <File
257 RelativePath=".\llperlin.cpp"
258 >
259 </File>
260 <File
261 RelativePath=".\llquaternion.cpp"
262 >
263 </File>
264 <File
265 RelativePath=".\llrand.cpp"
266 >
267 </File>
268 <File
269 RelativePath=".\llrect.cpp"
270 >
271 </File>
272 <File
273 RelativePath=".\llsphere.cpp"
274 >
275 </File>
276 <File
277 RelativePath=".\lluuid.cpp"
278 >
279 </File>
280 <File
281 RelativePath=".\llvolume.cpp"
282 >
283 </File>
284 <File
285 RelativePath=".\llvolumemgr.cpp"
286 >
287 </File>
288 <File
289 RelativePath=".\m3math.cpp"
290 >
291 </File>
292 <File
293 RelativePath=".\m4math.cpp"
294 >
295 </File>
296 <File
297 RelativePath=".\raytrace.cpp"
298 >
299 </File>
300 <File
301 RelativePath=".\v2math.cpp"
302 >
303 </File>
304 <File
305 RelativePath=".\v3color.cpp"
306 >
307 </File>
308 <File
309 RelativePath=".\v3dmath.cpp"
310 >
311 </File>
312 <File
313 RelativePath=".\v3math.cpp"
314 >
315 </File>
316 <File
317 RelativePath=".\v4color.cpp"
318 >
319 </File>
320 <File
321 RelativePath=".\v4coloru.cpp"
322 >
323 </File>
324 <File
325 RelativePath=".\v4math.cpp"
326 >
327 </File>
328 <File
329 RelativePath=".\xform.cpp"
330 >
331 </File>
332 </Filter>
333 <Filter
334 Name="Header Files"
335 Filter="h;hpp;hxx;hm;inl;inc;xsd"
336 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
337 >
338 <File
339 RelativePath=".\llbboxlocal.h"
340 >
341 </File>
342 <File
343 RelativePath=".\llcamera.h"
344 >
345 </File>
346 <File
347 RelativePath=".\llcoord.h"
348 >
349 </File>
350 <File
351 RelativePath=".\llcoordframe.h"
352 >
353 </File>
354 <File
355 RelativePath=".\llcrc.h"
356 >
357 </File>
358 <File
359 RelativePath=".\llinterp.h"
360 >
361 </File>
362 <File
363 RelativePath=".\llline.h"
364 >
365 </File>
366 <File
367 RelativePath=".\llmath.h"
368 >
369 </File>
370 <File
371 RelativePath=".\llmd5.h"
372 >
373 </File>
374 <File
375 RelativePath=".\lloctree.h"
376 >
377 </File>
378 <File
379 RelativePath=".\llperlin.h"
380 >
381 </File>
382 <File
383 RelativePath=".\llquantize.h"
384 >
385 </File>
386 <File
387 RelativePath=".\llquaternion.h"
388 >
389 </File>
390 <File
391 RelativePath=".\llrand.h"
392 >
393 </File>
394 <File
395 RelativePath=".\llrect.h"
396 >
397 </File>
398 <File
399 RelativePath=".\llsphere.h"
400 >
401 </File>
402 <File
403 RelativePath=".\lltreenode.h"
404 >
405 </File>
406 <File
407 RelativePath=".\lluuid.h"
408 >
409 </File>
410 <File
411 RelativePath=".\llv4math.h"
412 >
413 </File>
414 <File
415 RelativePath=".\llv4matrix3.h"
416 >
417 </File>
418 <File
419 RelativePath=".\llv4matrix4.h"
420 >
421 </File>
422 <File
423 RelativePath=".\llv4vector3.h"
424 >
425 </File>
426 <File
427 RelativePath=".\llvolume.h"
428 >
429 </File>
430 <File
431 RelativePath=".\llvolumemgr.h"
432 >
433 </File>
434 <File
435 RelativePath=".\m3math.h"
436 >
437 </File>
438 <File
439 RelativePath=".\m4math.h"
440 >
441 </File>
442 <File
443 RelativePath=".\raytrace.h"
444 >
445 </File>
446 <File
447 RelativePath=".\v2math.h"
448 >
449 </File>
450 <File
451 RelativePath=".\v3color.h"
452 >
453 </File>
454 <File
455 RelativePath=".\v3dmath.h"
456 >
457 </File>
458 <File
459 RelativePath=".\v3math.h"
460 >
461 </File>
462 <File
463 RelativePath=".\v4color.h"
464 >
465 </File>
466 <File
467 RelativePath=".\v4coloru.h"
468 >
469 </File>
470 <File
471 RelativePath=".\v4math.h"
472 >
473 </File>
474 <File
475 RelativePath=".\xform.h"
476 >
477 </File>
478 </Filter>
479 <Filter
480 Name="Resource Files"
481 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
482 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
483 >
484 </Filter>
485 </Files>
486 <Globals>
487 </Globals>
488</VisualStudioProject>
diff --git a/linden/indra/llmath/llmath_vc9.vcproj b/linden/indra/llmath/llmath_vc9.vcproj
deleted file mode 100644
index 03bc780..0000000
--- a/linden/indra/llmath/llmath_vc9.vcproj
+++ /dev/null
@@ -1,489 +0,0 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="9.00"
5 Name="llmath"
6 ProjectGUID="{E87FD9BE-BE42-4EA3-BF4D-D992223046D9}"
7 RootNamespace="llmath"
8 Keyword="Win32Proj"
9 TargetFrameworkVersion="131072"
10 >
11 <Platforms>
12 <Platform
13 Name="Win32"
14 />
15 </Platforms>
16 <ToolFiles>
17 </ToolFiles>
18 <Configurations>
19 <Configuration
20 Name="Debug|Win32"
21 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
22 IntermediateDirectory="$(ConfigurationName)"
23 ConfigurationType="4"
24 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
25 CharacterSet="1"
26 >
27 <Tool
28 Name="VCPreBuildEventTool"
29 />
30 <Tool
31 Name="VCCustomBuildTool"
32 />
33 <Tool
34 Name="VCXMLDataGeneratorTool"
35 />
36 <Tool
37 Name="VCWebServiceProxyGeneratorTool"
38 />
39 <Tool
40 Name="VCMIDLTool"
41 />
42 <Tool
43 Name="VCCLCompilerTool"
44 Optimization="0"
45 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
46 PreprocessorDefinitions="WIN32;_DEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_DEBUG"
47 MinimalRebuild="true"
48 BasicRuntimeChecks="3"
49 RuntimeLibrary="1"
50 StructMemberAlignment="4"
51 TreatWChar_tAsBuiltInType="false"
52 ForceConformanceInForLoopScope="true"
53 UsePrecompiledHeader="0"
54 WarningLevel="3"
55 WarnAsError="true"
56 Detect64BitPortabilityProblems="false"
57 DebugInformationFormat="4"
58 />
59 <Tool
60 Name="VCManagedResourceCompilerTool"
61 />
62 <Tool
63 Name="VCResourceCompilerTool"
64 />
65 <Tool
66 Name="VCPreLinkEventTool"
67 />
68 <Tool
69 Name="VCLibrarianTool"
70 OutputFile="$(OutDir)/llmath.lib"
71 />
72 <Tool
73 Name="VCALinkTool"
74 />
75 <Tool
76 Name="VCXDCMakeTool"
77 />
78 <Tool
79 Name="VCBscMakeTool"
80 />
81 <Tool
82 Name="VCFxCopTool"
83 />
84 <Tool
85 Name="VCPostBuildEventTool"
86 />
87 </Configuration>
88 <Configuration
89 Name="Release|Win32"
90 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
91 IntermediateDirectory="$(ConfigurationName)"
92 ConfigurationType="4"
93 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
94 CharacterSet="1"
95 >
96 <Tool
97 Name="VCPreBuildEventTool"
98 />
99 <Tool
100 Name="VCCustomBuildTool"
101 />
102 <Tool
103 Name="VCXMLDataGeneratorTool"
104 />
105 <Tool
106 Name="VCWebServiceProxyGeneratorTool"
107 />
108 <Tool
109 Name="VCMIDLTool"
110 />
111 <Tool
112 Name="VCCLCompilerTool"
113 AdditionalOptions="/Oy-"
114 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
115 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
116 RuntimeLibrary="0"
117 StructMemberAlignment="0"
118 TreatWChar_tAsBuiltInType="false"
119 ForceConformanceInForLoopScope="true"
120 UsePrecompiledHeader="0"
121 WarningLevel="3"
122 WarnAsError="true"
123 Detect64BitPortabilityProblems="false"
124 DebugInformationFormat="3"
125 />
126 <Tool
127 Name="VCManagedResourceCompilerTool"
128 />
129 <Tool
130 Name="VCResourceCompilerTool"
131 />
132 <Tool
133 Name="VCPreLinkEventTool"
134 />
135 <Tool
136 Name="VCLibrarianTool"
137 OutputFile="$(OutDir)/llmath.lib"
138 />
139 <Tool
140 Name="VCALinkTool"
141 />
142 <Tool
143 Name="VCXDCMakeTool"
144 />
145 <Tool
146 Name="VCBscMakeTool"
147 />
148 <Tool
149 Name="VCFxCopTool"
150 />
151 <Tool
152 Name="VCPostBuildEventTool"
153 />
154 </Configuration>
155 <Configuration
156 Name="ReleaseNoOpt|Win32"
157 OutputDirectory="../lib_$(ConfigurationName)/i686-win32"
158 IntermediateDirectory="$(ConfigurationName)"
159 ConfigurationType="4"
160 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
161 CharacterSet="1"
162 >
163 <Tool
164 Name="VCPreBuildEventTool"
165 />
166 <Tool
167 Name="VCCustomBuildTool"
168 />
169 <Tool
170 Name="VCXMLDataGeneratorTool"
171 />
172 <Tool
173 Name="VCWebServiceProxyGeneratorTool"
174 />
175 <Tool
176 Name="VCMIDLTool"
177 />
178 <Tool
179 Name="VCCLCompilerTool"
180 AdditionalOptions="/Oy-"
181 Optimization="0"
182 AdditionalIncludeDirectories="..\llcommon;..\..\libraries\i686-win32\include;..\..\libraries\include\"
183 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;LL_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T;LL_RELEASE"
184 RuntimeLibrary="0"
185 StructMemberAlignment="0"
186 TreatWChar_tAsBuiltInType="false"
187 ForceConformanceInForLoopScope="true"
188 UsePrecompiledHeader="0"
189 BrowseInformation="0"
190 WarningLevel="3"
191 WarnAsError="true"
192 Detect64BitPortabilityProblems="false"
193 DebugInformationFormat="3"
194 />
195 <Tool
196 Name="VCManagedResourceCompilerTool"
197 />
198 <Tool
199 Name="VCResourceCompilerTool"
200 />
201 <Tool
202 Name="VCPreLinkEventTool"
203 />
204 <Tool
205 Name="VCLibrarianTool"
206 OutputFile="$(OutDir)/llmath.lib"
207 />
208 <Tool
209 Name="VCALinkTool"
210 />
211 <Tool
212 Name="VCXDCMakeTool"
213 />
214 <Tool
215 Name="VCBscMakeTool"
216 />
217 <Tool
218 Name="VCFxCopTool"
219 />
220 <Tool
221 Name="VCPostBuildEventTool"
222 />
223 </Configuration>
224 </Configurations>
225 <References>
226 </References>
227 <Files>
228 <Filter
229 Name="Source Files"
230 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
231 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
232 >
233 <File
234 RelativePath=".\llbboxlocal.cpp"
235 >
236 </File>
237 <File
238 RelativePath=".\llcamera.cpp"
239 >
240 </File>
241 <File
242 RelativePath=".\llcoordframe.cpp"
243 >
244 </File>
245 <File
246 RelativePath=".\llcrc.cpp"
247 >
248 </File>
249 <File
250 RelativePath=".\llline.cpp"
251 >
252 </File>
253 <File
254 RelativePath=".\llmd5.cpp"
255 >
256 </File>
257 <File
258 RelativePath=".\llperlin.cpp"
259 >
260 </File>
261 <File
262 RelativePath=".\llquaternion.cpp"
263 >
264 </File>
265 <File
266 RelativePath=".\llrand.cpp"
267 >
268 </File>
269 <File
270 RelativePath=".\llrect.cpp"
271 >
272 </File>
273 <File
274 RelativePath=".\llsphere.cpp"
275 >
276 </File>
277 <File
278 RelativePath=".\lluuid.cpp"
279 >
280 </File>
281 <File
282 RelativePath=".\llvolume.cpp"
283 >
284 </File>
285 <File
286 RelativePath=".\llvolumemgr.cpp"
287 >
288 </File>
289 <File
290 RelativePath=".\m3math.cpp"
291 >
292 </File>
293 <File
294 RelativePath=".\m4math.cpp"
295 >
296 </File>
297 <File
298 RelativePath=".\raytrace.cpp"
299 >
300 </File>
301 <File
302 RelativePath=".\v2math.cpp"
303 >
304 </File>
305 <File
306 RelativePath=".\v3color.cpp"
307 >
308 </File>
309 <File
310 RelativePath=".\v3dmath.cpp"
311 >
312 </File>
313 <File
314 RelativePath=".\v3math.cpp"
315 >
316 </File>
317 <File
318 RelativePath=".\v4color.cpp"
319 >
320 </File>
321 <File
322 RelativePath=".\v4coloru.cpp"
323 >
324 </File>
325 <File
326 RelativePath=".\v4math.cpp"
327 >
328 </File>
329 <File
330 RelativePath=".\xform.cpp"
331 >
332 </File>
333 </Filter>
334 <Filter
335 Name="Header Files"
336 Filter="h;hpp;hxx;hm;inl;inc;xsd"
337 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
338 >
339 <File
340 RelativePath=".\llbboxlocal.h"
341 >
342 </File>
343 <File
344 RelativePath=".\llcamera.h"
345 >
346 </File>
347 <File
348 RelativePath=".\llcoord.h"
349 >
350 </File>
351 <File
352 RelativePath=".\llcoordframe.h"
353 >
354 </File>
355 <File
356 RelativePath=".\llcrc.h"
357 >
358 </File>
359 <File
360 RelativePath=".\llinterp.h"
361 >
362 </File>
363 <File
364 RelativePath=".\llline.h"
365 >
366 </File>
367 <File
368 RelativePath=".\llmath.h"
369 >
370 </File>
371 <File
372 RelativePath=".\llmd5.h"
373 >
374 </File>
375 <File
376 RelativePath=".\lloctree.h"
377 >
378 </File>
379 <File
380 RelativePath=".\llperlin.h"
381 >
382 </File>
383 <File
384 RelativePath=".\llquantize.h"
385 >
386 </File>
387 <File
388 RelativePath=".\llquaternion.h"
389 >
390 </File>
391 <File
392 RelativePath=".\llrand.h"
393 >
394 </File>
395 <File
396 RelativePath=".\llrect.h"
397 >
398 </File>
399 <File
400 RelativePath=".\llsphere.h"
401 >
402 </File>
403 <File
404 RelativePath=".\lltreenode.h"
405 >
406 </File>
407 <File
408 RelativePath=".\lluuid.h"
409 >
410 </File>
411 <File
412 RelativePath=".\llv4math.h"
413 >
414 </File>
415 <File
416 RelativePath=".\llv4matrix3.h"
417 >
418 </File>
419 <File
420 RelativePath=".\llv4matrix4.h"
421 >
422 </File>
423 <File
424 RelativePath=".\llv4vector3.h"
425 >
426 </File>
427 <File
428 RelativePath=".\llvolume.h"
429 >
430 </File>
431 <File
432 RelativePath=".\llvolumemgr.h"
433 >
434 </File>
435 <File
436 RelativePath=".\m3math.h"
437 >
438 </File>
439 <File
440 RelativePath=".\m4math.h"
441 >
442 </File>
443 <File
444 RelativePath=".\raytrace.h"
445 >
446 </File>
447 <File
448 RelativePath=".\v2math.h"
449 >
450 </File>
451 <File
452 RelativePath=".\v3color.h"
453 >
454 </File>
455 <File
456 RelativePath=".\v3dmath.h"
457 >
458 </File>
459 <File
460 RelativePath=".\v3math.h"
461 >
462 </File>
463 <File
464 RelativePath=".\v4color.h"
465 >
466 </File>
467 <File
468 RelativePath=".\v4coloru.h"
469 >
470 </File>
471 <File
472 RelativePath=".\v4math.h"
473 >
474 </File>
475 <File
476 RelativePath=".\xform.h"
477 >
478 </File>
479 </Filter>
480 <Filter
481 Name="Resource Files"
482 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
483 UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
484 >
485 </Filter>
486 </Files>
487 <Globals>
488 </Globals>
489</VisualStudioProject>
diff --git a/linden/indra/llmath/llmd5.cpp b/linden/indra/llmath/llmd5.cpp
deleted file mode 100644
index ea69002..0000000
--- a/linden/indra/llmath/llmd5.cpp
+++ /dev/null
@@ -1,531 +0,0 @@
1/**
2 * @file llmd5.cpp
3 *
4 * $LicenseInfo:firstyear=2001&license=viewergpl$
5 *
6 * Copyright (c) 2001-2008, Linden Research, Inc.
7 *
8 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 * $/LicenseInfo$
29 */
30
31// llMD5.CC - source code for the C++/object oriented translation and
32// modification of MD5.
33//
34// Adapted to Linden Lab by Frank Filipanits, 6/25/2002
35// Fixed potential memory leak, James Cook, 6/27/2002
36
37// Translation and modification (c) 1995 by Mordechai T. Abzug
38
39// This translation/ modification is provided "as is," without express or
40// implied warranty of any kind.
41
42// The translator/ modifier does not claim (1) that MD5 will do what you think
43// it does; (2) that this translation/ modification is accurate; or (3) that
44// this software is "merchantible." (Language for this disclaimer partially
45// copied from the disclaimer below).
46
47/* based on:
48
49 MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
50 MDDRIVER.C - test driver for MD2, MD4 and MD5
51
52
53 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
54rights reserved.
55
56License to copy and use this software is granted provided that it
57is identified as the "RSA Data Security, Inc. MD5 Message-Digest
58Algorithm" in all material mentioning or referencing this software
59or this function.
60
61License is also granted to make and use derivative works provided
62that such works are identified as "derived from the RSA Data
63Security, Inc. MD5 Message-Digest Algorithm" in all material
64mentioning or referencing the derived work.
65
66RSA Data Security, Inc. makes no representations concerning either
67the merchantability of this software or the suitability of this
68software for any particular purpose. It is provided "as is"
69without express or implied warranty of any kind.
70
71These notices must be retained in any copies of any part of this
72documentation and/or software.
73
74 */
75
76
77
78
79
80#include "linden_common.h"
81
82#include "llmd5.h"
83
84#include <cassert>
85
86// how many bytes to grab at a time when checking files
87const int LLMD5::BLOCK_LEN = 4096;
88
89
90// LLMD5 simple initialization method
91
92LLMD5::LLMD5()
93{
94 init();
95}
96
97
98
99
100// MD5 block update operation. Continues an MD5 message-digest
101// operation, processing another message block, and updating the
102// context.
103
104void LLMD5::update (const uint1 *input, const uint4 input_length) {
105
106 uint4 input_index, buffer_index;
107 uint4 buffer_space; // how much space is left in buffer
108
109 if (finalized){ // so we can't update!
110 std::cerr << "LLMD5::update: Can't update a finalized digest!" << std::endl;
111 return;
112 }
113
114 // Compute number of bytes mod 64
115 buffer_index = (unsigned int)((count[0] >> 3) & 0x3F);
116
117 // Update number of bits
118 if ( (count[0] += ((uint4) input_length << 3))<((uint4) input_length << 3) )
119 count[1]++;
120
121 count[1] += ((uint4)input_length >> 29);
122
123
124 buffer_space = 64 - buffer_index; // how much space is left in buffer
125
126 // Transform as many times as possible.
127 if (input_length >= buffer_space) { // ie. we have enough to fill the buffer
128 // fill the rest of the buffer and transform
129 memcpy( /* Flawfinder: ignore */
130 buffer + buffer_index,
131 input,
132 buffer_space);
133 transform (buffer);
134
135 // now, transform each 64-byte piece of the input, bypassing the buffer
136 if (input == NULL || input_length == 0){
137 std::cerr << "LLMD5::update: Invalid input!" << std::endl;
138 return;
139 }
140
141 for (input_index = buffer_space; input_index + 63 < input_length;
142 input_index += 64)
143 transform (input+input_index);
144
145 buffer_index = 0; // so we can buffer remaining
146 }
147 else
148 input_index=0; // so we can buffer the whole input
149
150
151 // and here we do the buffering:
152 memcpy(buffer+buffer_index, input+input_index, input_length-input_index); /* Flawfinder: ignore */
153}
154
155
156
157// MD5 update for files.
158// Like above, except that it works on files (and uses above as a primitive.)
159
160void LLMD5::update(LLFILE* file){
161
162 unsigned char buffer[BLOCK_LEN]; /* Flawfinder: ignore */
163 int len;
164
165 while ( (len=(int)fread(buffer, 1, BLOCK_LEN, file)) )
166 update(buffer, len);
167
168 fclose (file);
169
170}
171
172
173
174
175
176
177// MD5 update for istreams.
178// Like update for files; see above.
179
180void LLMD5::update(std::istream& stream){
181
182 unsigned char buffer[BLOCK_LEN]; /* Flawfinder: ignore */
183 int len;
184
185 while (stream.good()){
186 stream.read( (char*)buffer, BLOCK_LEN); /* Flawfinder: ignore */ // note that return value of read is unusable.
187 len=stream.gcount();
188 update(buffer, len);
189 }
190
191}
192
193
194
195
196
197// MD5 finalization. Ends an MD5 message-digest operation, writing the
198// the message digest and zeroizing the context.
199
200
201void LLMD5::finalize (){
202
203 unsigned char bits[8]; /* Flawfinder: ignore */
204 unsigned int index, padLen;
205 static uint1 PADDING[64]={
206 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
209 };
210
211 if (finalized){
212 std::cerr << "LLMD5::finalize: Already finalized this digest!" << std::endl;
213 return;
214 }
215
216 // Save number of bits
217 encode (bits, count, 8);
218
219 // Pad out to 56 mod 64.
220 index = (uint4) ((count[0] >> 3) & 0x3f);
221 padLen = (index < 56) ? (56 - index) : (120 - index);
222 update (PADDING, padLen);
223
224 // Append length (before padding)
225 update (bits, 8);
226
227 // Store state in digest
228 encode (digest, state, 16);
229
230 // Zeroize sensitive information
231 memset (buffer, 0, sizeof(*buffer));
232
233 finalized=1;
234
235}
236
237
238
239
240LLMD5::LLMD5(LLFILE *file){
241
242 init(); // must be called be all constructors
243 update(file);
244 finalize ();
245}
246
247
248
249
250LLMD5::LLMD5(std::istream& stream){
251
252 init(); // must called by all constructors
253 update (stream);
254 finalize();
255}
256
257// Digest a string of the format ("%s:%i" % (s, number))
258LLMD5::LLMD5(const unsigned char *string, const unsigned int number)
259{
260 const char *colon = ":";
261 char tbuf[16]; /* Flawfinder: ignore */
262 init();
263 update(string, (U32)strlen((const char *) string)); /* Flawfinder: ignore */
264 update((const unsigned char *) colon, (U32)strlen(colon)); /* Flawfinder: ignore */
265 snprintf(tbuf, sizeof(tbuf), "%i", number); /* Flawfinder: ignore */
266 update((const unsigned char *) tbuf, (U32)strlen(tbuf)); /* Flawfinder: ignore */
267 finalize();
268}
269
270// Digest a string
271LLMD5::LLMD5(const unsigned char *s)
272{
273 init();
274 update(s, (U32)strlen((const char *) s)); /* Flawfinder: ignore */
275 finalize();
276}
277
278void LLMD5::raw_digest(unsigned char *s)
279{
280 if (!finalized)
281 {
282 std::cerr << "LLMD5::raw_digest: Can't get digest if you haven't "<<
283 "finalized the digest!" << std::endl;
284 s[0] = '\0';
285 return;
286 }
287
288 memcpy(s, digest, 16); /* Flawfinder: ignore */
289 return;
290}
291
292
293
294void LLMD5::hex_digest(char *s)
295{
296 int i;
297
298 if (!finalized)
299 {
300 std::cerr << "LLMD5::hex_digest: Can't get digest if you haven't "<<
301 "finalized the digest!" <<std::endl;
302 s[0] = '\0';
303 return;
304 }
305
306 for (i=0; i<16; i++)
307 {
308 sprintf(s+i*2, "%02x", digest[i]); /* Flawfinder: ignore */
309 }
310
311 s[32]='\0';
312
313 return;
314}
315
316
317
318
319
320std::ostream& operator<<(std::ostream &stream, LLMD5 context)
321{
322 char s[33]; /* Flawfinder: ignore */
323 context.hex_digest(s);
324 stream << s;
325 return stream;
326}
327
328
329
330
331// PRIVATE METHODS:
332
333
334
335void LLMD5::init(){
336 finalized=0; // we just started!
337
338 // Nothing counted, so count=0
339 count[0] = 0;
340 count[1] = 0;
341
342 // Load magic initialization constants.
343 state[0] = 0x67452301;
344 state[1] = 0xefcdab89;
345 state[2] = 0x98badcfe;
346 state[3] = 0x10325476;
347}
348
349
350
351// Constants for MD5Transform routine.
352// Although we could use C++ style constants, defines are actually better,
353// since they let us easily evade scope clashes.
354
355#define S11 7
356#define S12 12
357#define S13 17
358#define S14 22
359#define S21 5
360#define S22 9
361#define S23 14
362#define S24 20
363#define S31 4
364#define S32 11
365#define S33 16
366#define S34 23
367#define S41 6
368#define S42 10
369#define S43 15
370#define S44 21
371
372// #defines are faster then inline, etc because the compiler is not required to inline.
373// Timing tests prove that this works ~40% faster on win with msvc++2k3 over using static inline.
374
375/* F, G, H and I are basic MD5 functions.
376 */
377#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
378#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
379#define H(x, y, z) ((x) ^ (y) ^ (z))
380#define I(x, y, z) ((y) ^ ((x) | (~z)))
381
382/* ROTATE_LEFT rotates x left n bits.
383 */
384#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
385
386/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
387Rotation is separate from addition to prevent recomputation.
388 */
389#define FF(a, b, c, d, x, s, ac) { \
390 (a) += F ((b), (c), (d)) + (x) + (U32)(ac); \
391 (a) = ROTATE_LEFT ((a), (s)); \
392 (a) += (b); \
393 }
394#define GG(a, b, c, d, x, s, ac) { \
395 (a) += G ((b), (c), (d)) + (x) + (U32)(ac); \
396 (a) = ROTATE_LEFT ((a), (s)); \
397 (a) += (b); \
398 }
399#define HH(a, b, c, d, x, s, ac) { \
400 (a) += H ((b), (c), (d)) + (x) + (U32)(ac); \
401 (a) = ROTATE_LEFT ((a), (s)); \
402 (a) += (b); \
403 }
404#define II(a, b, c, d, x, s, ac) { \
405 (a) += I ((b), (c), (d)) + (x) + (U32)(ac); \
406 (a) = ROTATE_LEFT ((a), (s)); \
407 (a) += (b); \
408 }
409
410
411
412// LLMD5 basic transformation. Transforms state based on block.
413void LLMD5::transform (const U8 block[64]){
414
415 uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
416
417 decode (x, block, 64);
418
419 assert(!finalized); // not just a user error, since the method is private
420
421 /* Round 1 */
422 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
423 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
424 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
425 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
426 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
427 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
428 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
429 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
430 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
431 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
432 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
433 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
434 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
435 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
436 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
437 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
438
439 /* Round 2 */
440 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
441 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
442 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
443 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
444 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
445 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
446 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
447 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
448 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
449 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
450 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
451 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
452 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
453 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
454 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
455 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
456
457 /* Round 3 */
458 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
459 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
460 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
461 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
462 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
463 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
464 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
465 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
466 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
467 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
468 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
469 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
470 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
471 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
472 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
473 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
474
475 /* Round 4 */
476 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
477 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
478 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
479 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
480 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
481 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
482 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
483 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
484 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
485 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
486 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
487 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
488 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
489 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
490 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
491 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
492
493 state[0] += a;
494 state[1] += b;
495 state[2] += c;
496 state[3] += d;
497
498 // Zeroize sensitive information.
499 memset ( (uint1 *) x, 0, sizeof(x));
500
501}
502
503
504
505// Encodes input (UINT4) into output (unsigned char). Assumes len is
506// a multiple of 4.
507void LLMD5::encode (uint1 *output, const uint4 *input, const uint4 len) {
508
509 unsigned int i, j;
510
511 for (i = 0, j = 0; j < len; i++, j += 4) {
512 output[j] = (uint1) (input[i] & 0xff);
513 output[j+1] = (uint1) ((input[i] >> 8) & 0xff);
514 output[j+2] = (uint1) ((input[i] >> 16) & 0xff);
515 output[j+3] = (uint1) ((input[i] >> 24) & 0xff);
516 }
517}
518
519
520
521
522// Decodes input (unsigned char) into output (UINT4). Assumes len is
523// a multiple of 4.
524void LLMD5::decode (uint4 *output, const uint1 *input, const uint4 len){
525
526 unsigned int i, j;
527
528 for (i = 0, j = 0; j < len; i++, j += 4)
529 output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) |
530 (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24);
531}
diff --git a/linden/indra/llmath/llmd5.h b/linden/indra/llmath/llmd5.h
deleted file mode 100644
index 9ba0a9f..0000000
--- a/linden/indra/llmath/llmd5.h
+++ /dev/null
@@ -1,133 +0,0 @@
1/**
2 * @file llmd5.h
3 *
4 * $LicenseInfo:firstyear=2001&license=viewergpl$
5 *
6 * Copyright (c) 2001-2008, Linden Research, Inc.
7 *
8 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 * $/LicenseInfo$
29 */
30
31#ifndef LL_LLMD5_H
32#define LL_LLMD5_H
33
34// LLMD5.CC - source code for the C++/object oriented translation and
35// modification of MD5.
36
37// Translation and modification (c) 1995 by Mordechai T. Abzug
38
39// This translation/ modification is provided "as is," without express or
40// implied warranty of any kind.
41
42// The translator/ modifier does not claim (1) that MD5 will do what you think
43// it does; (2) that this translation/ modification is accurate; or (3) that
44// this software is "merchantible." (Language for this disclaimer partially
45// copied from the disclaimer below).
46
47/* based on:
48
49 MD5.H - header file for MD5C.C
50 MDDRIVER.C - test driver for MD2, MD4 and MD5
51
52 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
53rights reserved.
54
55License to copy and use this software is granted provided that it
56is identified as the "RSA Data Security, Inc. MD5 Message-Digest
57Algorithm" in all material mentioning or referencing this software
58or this function.
59
60License is also granted to make and use derivative works provided
61that such works are identified as "derived from the RSA Data
62Security, Inc. MD5 Message-Digest Algorithm" in all material
63mentioning or referencing the derived work.
64
65RSA Data Security, Inc. makes no representations concerning either
66the merchantability of this software or the suitability of this
67software for any particular purpose. It is provided "as is"
68without express or implied warranty of any kind.
69
70These notices must be retained in any copies of any part of this
71documentation and/or software.
72
73*/
74
75// use for the raw digest output
76const int MD5RAW_BYTES = 16;
77
78// use for outputting hex digests
79const int MD5HEX_STR_SIZE = 33; // char hex[MD5HEX_STR_SIZE]; with null
80const int MD5HEX_STR_BYTES = 32; // message system fixed size
81
82class LLMD5 {
83// first, some types:
84 typedef unsigned int uint4; // assumes integer is 4 words long
85 typedef unsigned short int uint2; // assumes short integer is 2 words long
86 typedef unsigned char uint1; // assumes char is 1 word long
87
88// how many bytes to grab at a time when checking files
89 static const int BLOCK_LEN;
90
91public:
92// methods for controlled operation:
93 LLMD5 (); // simple initializer
94 void update (const uint1 *input, const uint4 input_length);
95 void update (std::istream& stream);
96 void update (LLFILE *file);
97 void finalize ();
98
99// constructors for special circumstances. All these constructors finalize
100// the MD5 context.
101 LLMD5 (const unsigned char *string); // digest string, finalize
102 LLMD5 (std::istream& stream); // digest stream, finalize
103 LLMD5 (LLFILE *file); // digest file, close, finalize
104 LLMD5 (const unsigned char *string, const unsigned int number);
105
106// methods to acquire finalized result
107 void raw_digest(unsigned char *array); // provide 16-byte array for binary data
108 void hex_digest(char *string); // provide 33-byte array for ascii-hex string
109 friend std::ostream& operator<< (std::ostream&, LLMD5 context);
110
111
112
113private:
114
115
116// next, the private data:
117 uint4 state[4];
118 uint4 count[2]; // number of *bits*, mod 2^64
119 uint1 buffer[64]; // input buffer
120 uint1 digest[16];
121 uint1 finalized;
122
123// last, the private methods, mostly static:
124 void init (); // called by all constructors
125 void transform (const uint1 *buffer); // does the real update work. Note
126 // that length is implied to be 64.
127
128 static void encode (uint1 *dest, const uint4 *src, const uint4 length);
129 static void decode (uint4 *dest, const uint1 *src, const uint4 length);
130
131};
132
133#endif // LL_LLMD5_H
diff --git a/linden/indra/llmath/lloctree.h b/linden/indra/llmath/lloctree.h
index e26bae5..57b359f 100644
--- a/linden/indra/llmath/lloctree.h
+++ b/linden/indra/llmath/lloctree.h
@@ -37,7 +37,7 @@
37#include <vector> 37#include <vector>
38#include <set> 38#include <set>
39 39
40#ifdef LL_RELEASE_FOR_DOWNLOAD 40#if LL_RELEASE_WITH_DEBUG_INFO || LL_DEBUG
41#define OCT_ERRS LL_WARNS("OctreeErrors") 41#define OCT_ERRS LL_WARNS("OctreeErrors")
42#else 42#else
43#define OCT_ERRS LL_ERRS("OctreeErrors") 43#define OCT_ERRS LL_ERRS("OctreeErrors")
diff --git a/linden/indra/llmath/llquaternion.cpp b/linden/indra/llmath/llquaternion.cpp
index ab4855b..9eab8ed 100644
--- a/linden/indra/llmath/llquaternion.cpp
+++ b/linden/indra/llmath/llquaternion.cpp
@@ -791,7 +791,7 @@ LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order)
791 791
792const char *OrderToString( const LLQuaternion::Order order ) 792const char *OrderToString( const LLQuaternion::Order order )
793{ 793{
794 char *p = NULL; 794 const char *p = NULL;
795 switch( order ) 795 switch( order )
796 { 796 {
797 default: 797 default:
@@ -937,15 +937,15 @@ void LLQuaternion::unpackFromVector3( const LLVector3& vec )
937 } 937 }
938} 938}
939 939
940BOOL LLQuaternion::parseQuat(const char* buf, LLQuaternion* value) 940BOOL LLQuaternion::parseQuat(const std::string& buf, LLQuaternion* value)
941{ 941{
942 if( buf == NULL || buf[0] == '\0' || value == NULL) 942 if( buf.empty() || value == NULL)
943 { 943 {
944 return FALSE; 944 return FALSE;
945 } 945 }
946 946
947 LLQuaternion quat; 947 LLQuaternion quat;
948 S32 count = sscanf( buf, "%f %f %f %f", quat.mQ + 0, quat.mQ + 1, quat.mQ + 2, quat.mQ + 3 ); 948 S32 count = sscanf( buf.c_str(), "%f %f %f %f", quat.mQ + 0, quat.mQ + 1, quat.mQ + 2, quat.mQ + 3 );
949 if( 4 == count ) 949 if( 4 == count )
950 { 950 {
951 value->set( quat ); 951 value->set( quat );
diff --git a/linden/indra/llmath/llquaternion.h b/linden/indra/llmath/llquaternion.h
index 048db2d..1eb982e 100644
--- a/linden/indra/llmath/llquaternion.h
+++ b/linden/indra/llmath/llquaternion.h
@@ -158,7 +158,7 @@ public:
158 friend const char *OrderToString( const Order order ); 158 friend const char *OrderToString( const Order order );
159 friend Order StringToOrder( const char *str ); 159 friend Order StringToOrder( const char *str );
160 160
161 static BOOL parseQuat(const char* buf, LLQuaternion* value); 161 static BOOL parseQuat(const std::string& buf, LLQuaternion* value);
162 162
163 // For debugging, only 163 // For debugging, only
164 //static U32 mMultCount; 164 //static U32 mMultCount;
diff --git a/linden/indra/llmath/llrand.cpp b/linden/indra/llmath/llrand.cpp
deleted file mode 100644
index bc8c867..0000000
--- a/linden/indra/llmath/llrand.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
1/**
2 * @file llrand.cpp
3 * @brief Global random generator.
4 *
5 * $LicenseInfo:firstyear=2000&license=viewergpl$
6 *
7 * Copyright (c) 2000-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "linden_common.h"
33
34#include "llrand.h"
35#include "lluuid.h"
36
37/**
38 * Through analysis, we have decided that we want to take values which
39 * are close enough to 1.0 to map back to 0.0. We came to this
40 * conclusion from noting that:
41 *
42 * [0.0, 1.0)
43 *
44 * when scaled to the integer set:
45 *
46 * [0, 4)
47 *
48 * there is some value close enough to 1.0 that when multiplying by 4,
49 * gets truncated to 4. Therefore:
50 *
51 * [0,1-eps] => 0
52 * [1,2-eps] => 1
53 * [2,3-eps] => 2
54 * [3,4-eps] => 3
55 *
56 * So 0 gets uneven distribution if we simply clamp. The actual
57 * clamp utilized in this file is to map values out of range back
58 * to 0 to restore uniform distribution.
59 *
60 * Also, for clamping floats when asking for a distribution from
61 * [0.0,g) we have determined that for values of g < 0.5, then
62 * rand*g=g, which is not the desired result. As above, we clamp to 0
63 * to restore uniform distribution.
64 */
65
66// *NOTE: The system rand implementation is probably not correct.
67#define LL_USE_SYSTEM_RAND 0
68
69#if LL_USE_SYSTEM_RAND
70#include <cstdlib>
71#endif
72
73#if LL_USE_SYSTEM_RAND
74class LLSeedRand
75{
76public:
77 LLSeedRand()
78 {
79#if LL_WINDOWS
80 srand(LLUUID::getRandomSeed());
81#else
82 srand48(LLUUID::getRandomSeed());
83#endif
84 }
85};
86static LLSeedRand sRandomSeeder;
87inline F64 ll_internal_random_double()
88{
89#if LL_WINDOWS
90 return (F64)rand() / (F64)RAND_MAX;
91#else
92 return drand48();
93#endif
94}
95inline F32 ll_internal_random_float()
96{
97#if LL_WINDOWS
98 return (F32)rand() / (F32)RAND_MAX;
99#else
100 return (F32)drand48();
101#endif
102}
103#else
104static LLRandLagFib2281 gRandomGenerator(LLUUID::getRandomSeed());
105inline F64 ll_internal_random_double()
106{
107 // *HACK: Through experimentation, we have found that dual core
108 // CPUs (or at least multi-threaded processes) seem to
109 // occasionally give an obviously incorrect random number -- like
110 // 5^15 or something. Sooooo, clamp it as described above.
111 F64 rv = gRandomGenerator();
112 if(!((rv >= 0.0) && (rv < 1.0))) return fmod(rv, 1.0);
113 return rv;
114}
115
116inline F32 ll_internal_random_float()
117{
118 // The clamping rules are described above.
119 F32 rv = (F32)gRandomGenerator();
120 if(!((rv >= 0.0f) && (rv < 1.0f))) return fmod(rv, 1.f);
121 return rv;
122}
123#endif
124
125S32 ll_rand()
126{
127 return ll_rand(RAND_MAX);
128}
129
130S32 ll_rand(S32 val)
131{
132 // The clamping rules are described above.
133 S32 rv = (S32)(ll_internal_random_double() * val);
134 if(rv == val) return 0;
135 return rv;
136}
137
138F32 ll_frand()
139{
140 return ll_internal_random_float();
141}
142
143F32 ll_frand(F32 val)
144{
145 // The clamping rules are described above.
146 F32 rv = ll_internal_random_float() * val;
147 if(val > 0)
148 {
149 if(rv >= val) return 0.0f;
150 }
151 else
152 {
153 if(rv <= val) return 0.0f;
154 }
155 return rv;
156}
157
158F64 ll_drand()
159{
160 return ll_internal_random_double();
161}
162
163F64 ll_drand(F64 val)
164{
165 // The clamping rules are described above.
166 F64 rv = ll_internal_random_double() * val;
167 if(val > 0)
168 {
169 if(rv >= val) return 0.0;
170 }
171 else
172 {
173 if(rv <= val) return 0.0;
174 }
175 return rv;
176}
diff --git a/linden/indra/llmath/llrand.h b/linden/indra/llmath/llrand.h
deleted file mode 100644
index 0a28213..0000000
--- a/linden/indra/llmath/llrand.h
+++ /dev/null
@@ -1,132 +0,0 @@
1/**
2 * @file llrand.h
3 * @brief Information, functions, and typedefs for randomness.
4 *
5 * $LicenseInfo:firstyear=2000&license=viewergpl$
6 *
7 * Copyright (c) 2000-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#ifndef LL_LLRAND_H
33#define LL_LLRAND_H
34
35#include <boost/random/lagged_fibonacci.hpp>
36#include <boost/random/mersenne_twister.hpp>
37
38/**
39 * Use the boost random number generators if you want a stateful
40 * random numbers. If you want more random numbers, use the
41 * c-functions since they will generate faster/better randomness
42 * across the process.
43 *
44 * I tested some of the boost random engines, and picked a good double
45 * generator and a good integer generator. I also took some timings
46 * for them on linux using gcc 3.3.5. The harness also did some other
47 * fairly trivial operations to try to limit compiler optimizations,
48 * so these numbers are only good for relative comparisons.
49 *
50 * usec/inter algorithm
51 * 0.21 boost::minstd_rand0
52 * 0.039 boost:lagged_fibonacci19937
53 * 0.036 boost:lagged_fibonacci607
54 * 0.44 boost::hellekalek1995
55 * 0.44 boost::ecuyer1988
56 * 0.042 boost::rand48
57 * 0.043 boost::mt11213b
58 * 0.028 stdlib random()
59 * 0.05 stdlib lrand48()
60 * 0.034 stdlib rand()
61 * 0.020 the old & lame LLRand
62 */
63
64/**
65 *@brief Generate a float from [0, RAND_MAX).
66 */
67S32 ll_rand();
68
69/**
70 *@brief Generate a float from [0, val) or (val, 0].
71 */
72S32 ll_rand(S32 val);
73
74/**
75 *@brief Generate a float from [0, 1.0).
76 */
77F32 ll_frand();
78
79/**
80 *@brief Generate a float from [0, val) or (val, 0].
81 */
82F32 ll_frand(F32 val);
83
84/**
85 *@brief Generate a double from [0, 1.0).
86 */
87F64 ll_drand();
88
89/**
90 *@brief Generate a double from [0, val) or (val, 0].
91 */
92F64 ll_drand(F64 val);
93
94/**
95 * @brief typedefs for good boost lagged fibonacci.
96 * @see boost::lagged_fibonacci
97 *
98 * These generators will quickly generate doubles. Note the memory
99 * requirements, because they are somewhat high. I chose the smallest
100 * one, and one comparable in speed but higher periodicity without
101 * outrageous memory requirements.
102 * To use:
103 * LLRandLagFib607 foo((U32)time(NULL));
104 * double bar = foo();
105 */
106
107typedef boost::lagged_fibonacci607 LLRandLagFib607;
108/**<
109 * lengh of cycle: 2^32,000
110 * memory: 607*sizeof(double) (about 5K)
111 */
112
113typedef boost::lagged_fibonacci2281 LLRandLagFib2281;
114/**<
115 * lengh of cycle: 2^120,000
116 * memory: 2281*sizeof(double) (about 17K)
117 */
118
119/**
120 * @breif typedefs for a good boost mersenne twister implementation.
121 * @see boost::mersenne_twister
122 *
123 * This fairly quickly generates U32 values
124 * To use:
125 * LLRandMT19937 foo((U32)time(NULL));
126 * U32 bar = foo();
127 *
128 * lengh of cycle: 2^19,937-1
129 * memory: about 2496 bytes
130 */
131typedef boost::mt11213b LLRandMT19937;
132#endif
diff --git a/linden/indra/llmath/llrect.h b/linden/indra/llmath/llrect.h
index f2a5d75..ebe5d83 100644
--- a/linden/indra/llmath/llrect.h
+++ b/linden/indra/llmath/llrect.h
@@ -183,10 +183,11 @@ public:
183 183
184 LLRectBase& setCenterAndSize(Type x, Type y, Type width, Type height) 184 LLRectBase& setCenterAndSize(Type x, Type y, Type width, Type height)
185 { 185 {
186 // width and height could be odd, so favor top, right with extra pixel
186 mLeft = x - width/2; 187 mLeft = x - width/2;
187 mTop = y + height/2;
188 mRight = x + width/2;
189 mBottom = y - height/2; 188 mBottom = y - height/2;
189 mTop = mBottom + height;
190 mRight = mLeft + width;
190 return *this; 191 return *this;
191 } 192 }
192 193
diff --git a/linden/indra/llmath/llsdutil_math.cpp b/linden/indra/llmath/llsdutil_math.cpp
new file mode 100644
index 0000000..5b72875
--- /dev/null
+++ b/linden/indra/llmath/llsdutil_math.cpp
@@ -0,0 +1,172 @@
1/**
2 * @file llsdutil_math.cpp
3 * @author Phoenix
4 * @date 2006-05-24
5 * @brief Implementation of classes, functions, etc, for using structured data.
6 *
7 * $LicenseInfo:firstyear=2006&license=viewergpl$
8 *
9 * Copyright (c) 2006-2008, Linden Research, Inc.
10 *
11 * Second Life Viewer Source Code
12 * The source code in this file ("Source Code") is provided by Linden Lab
13 * to you under the terms of the GNU General Public License, version 2.0
14 * ("GPL"), unless you have obtained a separate licensing agreement
15 * ("Other License"), formally executed by you and Linden Lab. Terms of
16 * the GPL can be found in doc/GPL-license.txt in this distribution, or
17 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
18 *
19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 *
24 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above,
26 * and agree to abide by those obligations.
27 *
28 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
29 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
30 * COMPLETENESS OR PERFORMANCE.
31 * $/LicenseInfo$
32 */
33
34#include "linden_common.h"
35
36#include "llsdutil.h"
37
38#include "v3math.h"
39#include "v4math.h"
40#include "v3dmath.h"
41#include "v2math.h"
42#include "llquaternion.h"
43#include "v4color.h"
44
45#if LL_WINDOWS
46# define WIN32_LEAN_AND_MEAN
47# include <winsock2.h> // for htonl
48#elif LL_LINUX || LL_SOLARIS
49# include <netinet/in.h>
50#elif LL_DARWIN
51# include <arpa/inet.h>
52#endif
53
54#include "llsdserialize.h"
55
56// vector3
57LLSD ll_sd_from_vector3(const LLVector3& vec)
58{
59 LLSD rv;
60 rv.append((F64)vec.mV[VX]);
61 rv.append((F64)vec.mV[VY]);
62 rv.append((F64)vec.mV[VZ]);
63 return rv;
64}
65
66LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index)
67{
68 LLVector3 rv;
69 rv.mV[VX] = (F32)sd[start_index].asReal();
70 rv.mV[VY] = (F32)sd[++start_index].asReal();
71 rv.mV[VZ] = (F32)sd[++start_index].asReal();
72 return rv;
73}
74
75// vector4
76LLSD ll_sd_from_vector4(const LLVector4& vec)
77{
78 LLSD rv;
79 rv.append((F64)vec.mV[VX]);
80 rv.append((F64)vec.mV[VY]);
81 rv.append((F64)vec.mV[VZ]);
82 rv.append((F64)vec.mV[VW]);
83 return rv;
84}
85
86LLVector4 ll_vector4_from_sd(const LLSD& sd, S32 start_index)
87{
88 LLVector4 rv;
89 rv.mV[VX] = (F32)sd[start_index].asReal();
90 rv.mV[VY] = (F32)sd[++start_index].asReal();
91 rv.mV[VZ] = (F32)sd[++start_index].asReal();
92 rv.mV[VW] = (F32)sd[++start_index].asReal();
93 return rv;
94}
95
96// vector3d
97LLSD ll_sd_from_vector3d(const LLVector3d& vec)
98{
99 LLSD rv;
100 rv.append(vec.mdV[VX]);
101 rv.append(vec.mdV[VY]);
102 rv.append(vec.mdV[VZ]);
103 return rv;
104}
105
106LLVector3d ll_vector3d_from_sd(const LLSD& sd, S32 start_index)
107{
108 LLVector3d rv;
109 rv.mdV[VX] = sd[start_index].asReal();
110 rv.mdV[VY] = sd[++start_index].asReal();
111 rv.mdV[VZ] = sd[++start_index].asReal();
112 return rv;
113}
114
115//vector2
116LLSD ll_sd_from_vector2(const LLVector2& vec)
117{
118 LLSD rv;
119 rv.append((F64)vec.mV[VX]);
120 rv.append((F64)vec.mV[VY]);
121 return rv;
122}
123
124LLVector2 ll_vector2_from_sd(const LLSD& sd)
125{
126 LLVector2 rv;
127 rv.mV[VX] = (F32)sd[0].asReal();
128 rv.mV[VY] = (F32)sd[1].asReal();
129 return rv;
130}
131
132// Quaternion
133LLSD ll_sd_from_quaternion(const LLQuaternion& quat)
134{
135 LLSD rv;
136 rv.append((F64)quat.mQ[VX]);
137 rv.append((F64)quat.mQ[VY]);
138 rv.append((F64)quat.mQ[VZ]);
139 rv.append((F64)quat.mQ[VW]);
140 return rv;
141}
142
143LLQuaternion ll_quaternion_from_sd(const LLSD& sd)
144{
145 LLQuaternion quat;
146 quat.mQ[VX] = (F32)sd[0].asReal();
147 quat.mQ[VY] = (F32)sd[1].asReal();
148 quat.mQ[VZ] = (F32)sd[2].asReal();
149 quat.mQ[VW] = (F32)sd[3].asReal();
150 return quat;
151}
152
153// color4
154LLSD ll_sd_from_color4(const LLColor4& c)
155{
156 LLSD rv;
157 rv.append(c.mV[0]);
158 rv.append(c.mV[1]);
159 rv.append(c.mV[2]);
160 rv.append(c.mV[3]);
161 return rv;
162}
163
164LLColor4 ll_color4_from_sd(const LLSD& sd)
165{
166 LLColor4 c;
167 c.mV[0] = (F32)sd[0].asReal();
168 c.mV[1] = (F32)sd[1].asReal();
169 c.mV[2] = (F32)sd[2].asReal();
170 c.mV[3] = (F32)sd[3].asReal();
171 return c;
172}
diff --git a/linden/indra/llmath/llsphere.cpp b/linden/indra/llmath/llsphere.cpp
index 62f6e27..f253b6c 100644
--- a/linden/indra/llmath/llsphere.cpp
+++ b/linden/indra/llmath/llsphere.cpp
@@ -20,6 +20,8 @@
20 * $/LicenseInfo$ 20 * $/LicenseInfo$
21 */ 21 */
22 22
23#include "linden_common.h"
24
23#include "llsphere.h" 25#include "llsphere.h"
24 26
25LLSphere::LLSphere() 27LLSphere::LLSphere()
diff --git a/linden/indra/llmath/lluuid.cpp b/linden/indra/llmath/lluuid.cpp
deleted file mode 100644
index d835cbc..0000000
--- a/linden/indra/llmath/lluuid.cpp
+++ /dev/null
@@ -1,923 +0,0 @@
1/**
2 * @file lluuid.cpp
3 *
4 * $LicenseInfo:firstyear=2000&license=viewergpl$
5 *
6 * Copyright (c) 2000-2008, Linden Research, Inc.
7 *
8 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 * $/LicenseInfo$
29 */
30
31#include "linden_common.h"
32
33// We can't use WIN32_LEAN_AND_MEAN here, needs lots of includes.
34#if LL_WINDOWS
35# undef WIN32_LEAN_AND_MEAN
36# include <winsock2.h>
37# include <windows.h>
38#endif
39
40#include "lldefs.h"
41#include "llerror.h"
42
43#include "lluuid.h"
44#include "llerror.h"
45#include "llrand.h"
46#include "llmd5.h"
47#include "llstring.h"
48#include "lltimer.h"
49
50const LLUUID LLUUID::null;
51const LLTransactionID LLTransactionID::tnull;
52
53/*
54
55NOT DONE YET!!!
56
57static char BASE85_TABLE[] = {
58 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
59 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
60 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
61 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
62 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
63 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
64 'y', 'z', '!', '#', '$', '%', '&', '(', ')', '*',
65 '+', '-', ';', '[', '=', '>', '?', '@', '^', '_',
66 '`', '{', '|', '}', '~', '\0'
67};
68
69
70void encode( char * fiveChars, unsigned int word ) throw( )
71{
72for( int ix = 0; ix < 5; ++ix ) {
73fiveChars[4-ix] = encodeTable[ word % 85];
74word /= 85;
75}
76}
77
78To decode:
79unsigned int decode( char const * fiveChars ) throw( bad_input_data )
80{
81unsigned int ret = 0;
82for( int ix = 0; ix < 5; ++ix ) {
83char * s = strchr( encodeTable, fiveChars[ ix ] );
84if( s == 0 ) throw bad_input_data();
85ret = ret * 85 + (s-encodeTable);
86}
87return ret;
88}
89
90void LLUUID::toBase85(char* out)
91{
92 U32* me = (U32*)&(mData[0]);
93 for(S32 i = 0; i < 4; ++i)
94 {
95 char* o = &out[i*i];
96 for(S32 j = 0; j < 5; ++j)
97 {
98 o[4-j] = BASE85_TABLE[ me[i] % 85];
99 word /= 85;
100 }
101 }
102}
103
104unsigned int decode( char const * fiveChars ) throw( bad_input_data )
105{
106 unsigned int ret = 0;
107 for( S32 ix = 0; ix < 5; ++ix )
108 {
109 char * s = strchr( encodeTable, fiveChars[ ix ] );
110 ret = ret * 85 + (s-encodeTable);
111 }
112 return ret;
113}
114*/
115
116#define LL_USE_JANKY_RANDOM_NUMBER_GENERATOR 0
117#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
118/**
119 * @brief a global for
120 */
121static U64 sJankyRandomSeed(LLUUID::getRandomSeed());
122
123/**
124 * @brief generate a random U32.
125 */
126U32 janky_fast_random_bytes()
127{
128 sJankyRandomSeed = U64L(1664525) * sJankyRandomSeed + U64L(1013904223);
129 return (U32)sJankyRandomSeed;
130}
131
132/**
133 * @brief generate a random U32 from [0, val)
134 */
135U32 janky_fast_random_byes_range(U32 val)
136{
137 sJankyRandomSeed = U64L(1664525) * sJankyRandomSeed + U64L(1013904223);
138 return (U32)(sJankyRandomSeed) % val;
139}
140
141/**
142 * @brief generate a random U32 from [0, val)
143 */
144U32 janky_fast_random_seeded_bytes(U32 seed, U32 val)
145{
146 seed = U64L(1664525) * (U64)(seed) + U64L(1013904223);
147 return (U32)(seed) % val;
148}
149#endif
150
151// Common to all UUID implementations
152void LLUUID::toString(char *out) const
153{
154 sprintf(out,
155 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
156 (U8)(mData[0]),
157 (U8)(mData[1]),
158 (U8)(mData[2]),
159 (U8)(mData[3]),
160 (U8)(mData[4]),
161 (U8)(mData[5]),
162 (U8)(mData[6]),
163 (U8)(mData[7]),
164 (U8)(mData[8]),
165 (U8)(mData[9]),
166 (U8)(mData[10]),
167 (U8)(mData[11]),
168 (U8)(mData[12]),
169 (U8)(mData[13]),
170 (U8)(mData[14]),
171 (U8)(mData[15]));
172}
173
174void LLUUID::toCompressedString(char *out) const
175{
176 memcpy(out, mData, UUID_BYTES); /* Flawfinder: ignore */
177 out[UUID_BYTES] = '\0';
178}
179
180std::string LLUUID::getString() const
181{
182 return asString();
183}
184
185std::string LLUUID::asString() const
186{
187 char str[UUID_STR_SIZE]; /* Flawfinder: ignore */
188 toString(str);
189 return std::string(str);
190}
191
192BOOL LLUUID::set(const std::string& in_string, BOOL emit)
193{
194 return set(in_string.c_str(), emit);
195}
196
197BOOL LLUUID::set(const char *in_string, BOOL emit)
198{
199 BOOL broken_format = FALSE;
200 if (!in_string)
201 {
202 llerrs << "No string pointer in LLUUID::set!" << llendl;
203 setNull();
204 return FALSE;
205 }
206
207 // empty strings should make NULL uuid
208 if (!in_string[0])
209 {
210 setNull();
211 return TRUE;
212 }
213
214 if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */
215 {
216 // I'm a moron. First implementation didn't have the right UUID format.
217 // Shouldn't see any of these any more
218 if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */
219 {
220 if(emit)
221 {
222 llinfos << "Warning! Using broken UUID string format" << llendl;
223 }
224 broken_format = TRUE;
225 }
226 else
227 {
228 // Bad UUID string. Spam as INFO, as most cases we don't care.
229 if(emit)
230 {
231 llinfos << "Bad UUID string: " << in_string << llendl;
232 }
233 setNull();
234 return FALSE;
235 }
236 }
237
238 U8 cur_pos = 0;
239 S32 i;
240 for (i = 0; i < UUID_BYTES; i++)
241 {
242 if ((i == 4) || (i == 6) || (i == 8) || (i == 10))
243 {
244 cur_pos++;
245 if (broken_format && (i==10))
246 {
247 // Missing - in the broken format
248 cur_pos--;
249 }
250 }
251
252 mData[i] = 0;
253
254 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9'))
255 {
256 mData[i] += (U8)(*(in_string + cur_pos) - '0');
257 }
258 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f'))
259 {
260 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a');
261 }
262 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F'))
263 {
264 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A');
265 }
266 else
267 {
268 if(emit)
269 {
270 llwarns << "Invalid UUID string character" << llendl;
271 }
272 setNull();
273 return FALSE;
274 }
275
276 mData[i] = mData[i] << 4;
277 cur_pos++;
278
279 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9'))
280 {
281 mData[i] += (U8)(*(in_string + cur_pos) - '0');
282 }
283 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f'))
284 {
285 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'a');
286 }
287 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F'))
288 {
289 mData[i] += (U8)(10 + *(in_string + cur_pos) - 'A');
290 }
291 else
292 {
293 if(emit)
294 {
295 llwarns << "Invalid UUID string character" << llendl;
296 }
297 setNull();
298 return FALSE;
299 }
300 cur_pos++;
301 }
302
303 return TRUE;
304}
305
306BOOL LLUUID::validate(const std::string& in_string)
307{
308 return validate(in_string.c_str());
309}
310
311BOOL LLUUID::validate(const char *in_string)
312{
313 BOOL broken_format = FALSE;
314 if (!in_string)
315 {
316 return FALSE;
317 }
318 if (strlen(in_string) != (UUID_STR_LENGTH - 1)) /* Flawfinder: ignore */
319 {
320 // I'm a moron. First implementation didn't have the right UUID format.
321 if (strlen(in_string) == (UUID_STR_LENGTH - 2)) /* Flawfinder: ignore */
322 {
323 broken_format = TRUE;
324 }
325 else
326 {
327 return FALSE;
328 }
329 }
330
331 U8 cur_pos = 0;
332 U32 i;
333 for (i = 0; i < 16; i++)
334 {
335 if ((i == 4) || (i == 6) || (i == 8) || (i == 10))
336 {
337 cur_pos++;
338 if (broken_format && (i==10))
339 {
340 // Missing - in the broken format
341 cur_pos--;
342 }
343 }
344
345 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9'))
346 {
347 }
348 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f'))
349 {
350 }
351 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F'))
352 {
353 }
354 else
355 {
356 return FALSE;
357 }
358
359 cur_pos++;
360
361 if ((*(in_string + cur_pos) >= '0') && (*(in_string+cur_pos) <= '9'))
362 {
363 }
364 else if ((*(in_string + cur_pos) >= 'a') && (*(in_string+cur_pos) <='f'))
365 {
366 }
367 else if ((*(in_string + cur_pos) >= 'A') && (*(in_string+cur_pos) <='F'))
368 {
369 }
370 else
371 {
372 return FALSE;
373 }
374 cur_pos++;
375 }
376 return TRUE;
377}
378
379const LLUUID& LLUUID::operator^=(const LLUUID& rhs)
380{
381 U32* me = (U32*)&(mData[0]);
382 const U32* other = (U32*)&(rhs.mData[0]);
383 for(S32 i = 0; i < 4; ++i)
384 {
385 me[i] = me[i] ^ other[i];
386 }
387 return *this;
388}
389
390LLUUID LLUUID::operator^(const LLUUID& rhs) const
391{
392 LLUUID id(*this);
393 id ^= rhs;
394 return id;
395}
396
397void LLUUID::combine(const LLUUID& other, LLUUID& result) const
398{
399 LLMD5 md5_uuid;
400 md5_uuid.update((unsigned char*)mData, 16);
401 md5_uuid.update((unsigned char*)other.mData, 16);
402 md5_uuid.finalize();
403 md5_uuid.raw_digest(result.mData);
404}
405
406LLUUID LLUUID::combine(const LLUUID &other) const
407{
408 LLUUID combination;
409 combine(other, combination);
410 return combination;
411}
412
413std::ostream& operator<<(std::ostream& s, const LLUUID &uuid)
414{
415 char uuid_str[UUID_STR_LENGTH];
416
417 uuid.toString(uuid_str);
418 s << uuid_str;
419 return s;
420}
421
422std::istream& operator>>(std::istream &s, LLUUID &uuid)
423{
424 U32 i;
425 char uuid_str[UUID_STR_LENGTH]; /* Flawfinder: ignore */
426 for (i = 0; i < UUID_STR_LENGTH-1; i++)
427 {
428 s >> uuid_str[i];
429 }
430 uuid_str[i] = '\0';
431 uuid.set(uuid_str);
432 return s;
433}
434
435static void get_random_bytes(void *buf, int nbytes)
436{
437 int i;
438 char *cp = (char *) buf;
439
440 // *NOTE: If we are not using the janky generator ll_rand()
441 // generates at least 3 good bytes of data since it is 0 to
442 // RAND_MAX. This could be made more efficient by copying all the
443 // bytes.
444 for (i=0; i < nbytes; i++)
445#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
446 *cp++ = janky_fast_random_bytes() & 0xFF;
447#else
448 *cp++ = ll_rand() & 0xFF;
449#endif
450 return;
451}
452
453#if LL_WINDOWS
454typedef struct _ASTAT_
455{
456 ADAPTER_STATUS adapt;
457 NAME_BUFFER NameBuff [30];
458}ASTAT, * PASTAT;
459
460// static
461S32 LLUUID::getNodeID(unsigned char * node_id)
462{
463 ASTAT Adapter;
464 NCB Ncb;
465 UCHAR uRetCode;
466 LANA_ENUM lenum;
467 int i;
468 int retval = 0;
469
470 memset( &Ncb, 0, sizeof(Ncb) );
471 Ncb.ncb_command = NCBENUM;
472 Ncb.ncb_buffer = (UCHAR *)&lenum;
473 Ncb.ncb_length = sizeof(lenum);
474 uRetCode = Netbios( &Ncb );
475 // printf( "The NCBENUM return code is: 0x%x \n", uRetCode );
476
477 for(i=0; i < lenum.length ;i++)
478 {
479 memset( &Ncb, 0, sizeof(Ncb) );
480 Ncb.ncb_command = NCBRESET;
481 Ncb.ncb_lana_num = lenum.lana[i];
482
483 uRetCode = Netbios( &Ncb );
484 // printf( "The NCBRESET on LANA %d return code is: 0x%x \n",
485 // lenum.lana[i], uRetCode );
486
487 memset( &Ncb, 0, sizeof (Ncb) );
488 Ncb.ncb_command = NCBASTAT;
489 Ncb.ncb_lana_num = lenum.lana[i];
490
491 strcpy( (char *)Ncb.ncb_callname, "* " ); /* Flawfinder: ignore */
492 Ncb.ncb_buffer = (unsigned char *)&Adapter;
493 Ncb.ncb_length = sizeof(Adapter);
494
495 uRetCode = Netbios( &Ncb );
496// printf( "The NCBASTAT on LANA %d return code is: 0x%x \n",
497// lenum.lana[i], uRetCode );
498 if ( uRetCode == 0 )
499 {
500// printf( "The Ethernet Number on LANA %d is: %02x%02x%02x%02x%02x%02x\n",
501// lenum.lana[i],
502// Adapter.adapt.adapter_address[0],
503// Adapter.adapt.adapter_address[1],
504// Adapter.adapt.adapter_address[2],
505// Adapter.adapt.adapter_address[3],
506// Adapter.adapt.adapter_address[4],
507// Adapter.adapt.adapter_address[5] );
508 memcpy(node_id,Adapter.adapt.adapter_address,6); /* Flawfinder: ignore */
509 retval = 1;
510
511 }
512 }
513 return retval;
514}
515
516#elif LL_DARWIN
517// Mac OS X version of the UUID generation code...
518/*
519 * Get an ethernet hardware address, if we can find it...
520 */
521#include <unistd.h>
522#include <sys/types.h>
523#include <sys/time.h>
524#include <sys/socket.h>
525#include <sys/ioctl.h>
526#include <net/if.h>
527#include <net/if_types.h>
528#include <net/if_dl.h>
529#include <net/route.h>
530#include <ifaddrs.h>
531
532// static
533S32 LLUUID::getNodeID(unsigned char *node_id)
534{
535 int i;
536 unsigned char *a = NULL;
537 struct ifaddrs *ifap, *ifa;
538 int rv;
539 S32 result = 0;
540
541 if ((rv=getifaddrs(&ifap))==-1)
542 {
543 return -1;
544 }
545 if (ifap == NULL)
546 {
547 return -1;
548 }
549
550 for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next)
551 {
552// printf("Interface %s, address family %d, ", ifa->ifa_name, ifa->ifa_addr->sa_family);
553 for(i=0; i< ifa->ifa_addr->sa_len; i++)
554 {
555// printf("%02X ", (unsigned char)ifa->ifa_addr->sa_data[i]);
556 }
557// printf("\n");
558
559 if(ifa->ifa_addr->sa_family == AF_LINK)
560 {
561 // This is a link-level address
562 struct sockaddr_dl *lla = (struct sockaddr_dl *)ifa->ifa_addr;
563
564// printf("\tLink level address, type %02X\n", lla->sdl_type);
565
566 if(lla->sdl_type == IFT_ETHER)
567 {
568 // Use the first ethernet MAC in the list.
569 // For some reason, the macro LLADDR() defined in net/if_dl.h doesn't expand correctly. This is what it would do.
570 a = (unsigned char *)&((lla)->sdl_data);
571 a += (lla)->sdl_nlen;
572
573 if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
574 {
575 continue;
576 }
577
578 if (node_id)
579 {
580 memcpy(node_id, a, 6);
581 result = 1;
582 }
583
584 // We found one.
585 break;
586 }
587 }
588 }
589 freeifaddrs(ifap);
590
591 return result;
592}
593
594#else
595
596// Linux version of the UUID generation code...
597/*
598 * Get the ethernet hardware address, if we can find it...
599 */
600#include <unistd.h>
601#include <fcntl.h>
602#include <errno.h>
603#include <sys/types.h>
604#include <sys/time.h>
605#include <sys/stat.h>
606#include <sys/file.h>
607#include <sys/ioctl.h>
608#include <sys/socket.h>
609#include <net/if.h>
610#define HAVE_NETINET_IN_H
611#ifdef HAVE_NETINET_IN_H
612#include <netinet/in.h>
613#if LL_SOLARIS
614#include <sys/sockio.h>
615#elif !LL_DARWIN
616#include <linux/sockios.h>
617#endif
618#endif
619
620// static
621S32 LLUUID::getNodeID(unsigned char *node_id)
622{
623 int sd;
624 struct ifreq ifr, *ifrp;
625 struct ifconf ifc;
626 char buf[1024];
627 int n, i;
628 unsigned char *a;
629
630/*
631 * BSD 4.4 defines the size of an ifreq to be
632 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
633 * However, under earlier systems, sa_len isn't present, so the size is
634 * just sizeof(struct ifreq)
635 */
636#ifdef HAVE_SA_LEN
637#ifndef max
638#define max(a,b) ((a) > (b) ? (a) : (b))
639#endif
640#define ifreq_size(i) max(sizeof(struct ifreq),\
641 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
642#else
643#define ifreq_size(i) sizeof(struct ifreq)
644#endif /* HAVE_SA_LEN*/
645
646 sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
647 if (sd < 0) {
648 return -1;
649 }
650 memset(buf, 0, sizeof(buf));
651 ifc.ifc_len = sizeof(buf);
652 ifc.ifc_buf = buf;
653 if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
654 close(sd);
655 return -1;
656 }
657 n = ifc.ifc_len;
658 for (i = 0; i < n; i+= ifreq_size(*ifr) ) {
659 ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
660 strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ); /* Flawfinder: ignore */
661#ifdef SIOCGIFHWADDR
662 if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
663 continue;
664 a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
665#else
666#ifdef SIOCGENADDR
667 if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
668 continue;
669 a = (unsigned char *) ifr.ifr_enaddr;
670#else
671 /*
672 * XXX we don't have a way of getting the hardware
673 * address
674 */
675 close(sd);
676 return 0;
677#endif /* SIOCGENADDR */
678#endif /* SIOCGIFHWADDR */
679 if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
680 continue;
681 if (node_id) {
682 memcpy(node_id, a, 6); /* Flawfinder: ignore */
683 close(sd);
684 return 1;
685 }
686 }
687 close(sd);
688 return 0;
689}
690
691#endif
692
693S32 LLUUID::cmpTime(uuid_time_t *t1, uuid_time_t *t2)
694{
695 // Compare two time values.
696
697 if (t1->high < t2->high) return -1;
698 if (t1->high > t2->high) return 1;
699 if (t1->low < t2->low) return -1;
700 if (t1->low > t2->low) return 1;
701 return 0;
702}
703
704void LLUUID::getSystemTime(uuid_time_t *timestamp)
705{
706 // Get system time with 100ns precision. Time is since Oct 15, 1582.
707#if LL_WINDOWS
708 ULARGE_INTEGER time;
709 GetSystemTimeAsFileTime((FILETIME *)&time);
710 // NT keeps time in FILETIME format which is 100ns ticks since
711 // Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
712 // The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec)
713 // + 18 years and 5 leap days.
714 time.QuadPart +=
715 (unsigned __int64) (1000*1000*10) // seconds
716 * (unsigned __int64) (60 * 60 * 24) // days
717 * (unsigned __int64) (17+30+31+365*18+5); // # of days
718
719 timestamp->high = time.HighPart;
720 timestamp->low = time.LowPart;
721#else
722 struct timeval tp;
723 gettimeofday(&tp, 0);
724
725 // Offset between UUID formatted times and Unix formatted times.
726 // UUID UTC base time is October 15, 1582.
727 // Unix base time is January 1, 1970.
728 U64 uuid_time = ((U64)tp.tv_sec * 10000000) + (tp.tv_usec * 10) +
729 U64L(0x01B21DD213814000);
730 timestamp->high = (U32) (uuid_time >> 32);
731 timestamp->low = (U32) (uuid_time & 0xFFFFFFFF);
732#endif
733}
734
735void LLUUID::getCurrentTime(uuid_time_t *timestamp)
736{
737 // Get current time as 60 bit 100ns ticks since whenever.
738 // Compensate for the fact that real clock resolution is less
739 // than 100ns.
740
741 const U32 uuids_per_tick = 1024;
742
743 static uuid_time_t time_last;
744 static U32 uuids_this_tick;
745 static BOOL init = FALSE;
746
747 if (!init) {
748 getSystemTime(&time_last);
749 uuids_this_tick = uuids_per_tick;
750 init = TRUE;
751 }
752
753 uuid_time_t time_now = {0,0};
754
755 while (1) {
756 getSystemTime(&time_now);
757
758 // if clock reading changed since last UUID generated
759 if (cmpTime(&time_last, &time_now)) {
760 // reset count of uuid's generated with this clock reading
761 uuids_this_tick = 0;
762 break;
763 }
764 if (uuids_this_tick < uuids_per_tick) {
765 uuids_this_tick++;
766 break;
767 }
768 // going too fast for our clock; spin
769 }
770
771 time_last = time_now;
772
773 if (uuids_this_tick != 0) {
774 if (time_now.low & 0x80000000) {
775 time_now.low += uuids_this_tick;
776 if (!(time_now.low & 0x80000000))
777 time_now.high++;
778 } else
779 time_now.low += uuids_this_tick;
780 }
781
782 timestamp->high = time_now.high;
783 timestamp->low = time_now.low;
784}
785
786void LLUUID::generate()
787{
788 // Create a UUID.
789 uuid_time_t timestamp;
790
791 static unsigned char node_id[6]; /* Flawfinder: ignore */
792 static int has_init = 0;
793
794 // Create a UUID.
795 static uuid_time_t time_last = {0,0};
796 static U16 clock_seq = 0;
797#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
798 static U32 seed = 0L; // dummy seed. reset it below
799#endif
800 if (!has_init)
801 {
802 if (getNodeID(node_id) <= 0)
803 {
804 get_random_bytes(node_id, 6);
805 /*
806 * Set multicast bit, to prevent conflicts
807 * with IEEE 802 addresses obtained from
808 * network cards
809 */
810 node_id[0] |= 0x80;
811 }
812
813 getCurrentTime(&time_last);
814#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
815 seed = time_last.low;
816#endif
817
818#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
819 clock_seq = (U16)janky_fast_random_seeded_bytes(seed, 65536);
820#else
821 clock_seq = (U16)ll_rand(65536);
822#endif
823 has_init = 1;
824 }
825
826 // get current time
827 getCurrentTime(&timestamp);
828
829 // if clock went backward change clockseq
830 if (cmpTime(&timestamp, &time_last) == -1) {
831 clock_seq = (clock_seq + 1) & 0x3FFF;
832 if (clock_seq == 0) clock_seq++;
833 }
834
835 memcpy(mData+10, node_id, 6); /* Flawfinder: ignore */
836 U32 tmp;
837 tmp = timestamp.low;
838 mData[3] = (unsigned char) tmp;
839 tmp >>= 8;
840 mData[2] = (unsigned char) tmp;
841 tmp >>= 8;
842 mData[1] = (unsigned char) tmp;
843 tmp >>= 8;
844 mData[0] = (unsigned char) tmp;
845
846 tmp = (U16) timestamp.high;
847 mData[5] = (unsigned char) tmp;
848 tmp >>= 8;
849 mData[4] = (unsigned char) tmp;
850
851 tmp = (timestamp.high >> 16) | 0x1000;
852 mData[7] = (unsigned char) tmp;
853 tmp >>= 8;
854 mData[6] = (unsigned char) tmp;
855
856 tmp = clock_seq;
857 mData[9] = (unsigned char) tmp;
858 tmp >>= 8;
859 mData[8] = (unsigned char) tmp;
860
861 LLMD5 md5_uuid;
862
863 md5_uuid.update(mData,16);
864 md5_uuid.finalize();
865 md5_uuid.raw_digest(mData);
866
867 time_last = timestamp;
868}
869
870void LLUUID::generate(std::string hash_string)
871{
872 LLMD5 md5_uuid((U8*)hash_string.c_str());
873 md5_uuid.raw_digest(mData);
874}
875
876U32 LLUUID::getRandomSeed()
877{
878 static unsigned char seed[16]; /* Flawfinder: ignore */
879
880 getNodeID(&seed[0]);
881 seed[6]='\0';
882 seed[7]='\0';
883 getSystemTime((uuid_time_t *)(&seed[8]));
884
885 LLMD5 md5_seed;
886
887 md5_seed.update(seed,16);
888 md5_seed.finalize();
889 md5_seed.raw_digest(seed);
890
891 return(*(U32 *)seed);
892}
893
894BOOL LLUUID::parseUUID(const char* buf, LLUUID* value)
895{
896 if( buf == NULL || buf[0] == '\0' || value == NULL)
897 {
898 return FALSE;
899 }
900
901 LLString temp( buf );
902 LLString::trim(temp);
903 if( LLUUID::validate( temp ) )
904 {
905 value->set( temp );
906 return TRUE;
907 }
908 return FALSE;
909}
910
911LLAssetID LLTransactionID::makeAssetID(const LLUUID& session) const
912{
913 LLAssetID result;
914 if (isNull())
915 {
916 result.setNull();
917 }
918 else
919 {
920 combine(session, result);
921 }
922 return result;
923}
diff --git a/linden/indra/llmath/lluuid.h b/linden/indra/llmath/lluuid.h
deleted file mode 100644
index 48308f2..0000000
--- a/linden/indra/llmath/lluuid.h
+++ /dev/null
@@ -1,330 +0,0 @@
1/**
2 * @file lluuid.h
3 *
4 * $LicenseInfo:firstyear=2000&license=viewergpl$
5 *
6 * Copyright (c) 2000-2008, Linden Research, Inc.
7 *
8 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 * $/LicenseInfo$
29 */
30
31#ifndef LL_LLUUID_H
32#define LL_LLUUID_H
33
34#include <iostream>
35#include <set>
36#include "stdtypes.h"
37
38const S32 UUID_BYTES = 16;
39const S32 UUID_WORDS = 4;
40const S32 UUID_STR_LENGTH = 37; // actually wrong, should be 36 and use size below
41const S32 UUID_STR_SIZE = 37;
42const S32 UUID_BASE85_LENGTH = 21; // including the trailing NULL.
43
44struct uuid_time_t {
45 U32 high;
46 U32 low;
47 };
48
49class LLUUID
50{
51public:
52 //
53 // CREATORS
54 //
55 LLUUID();
56 explicit LLUUID(const char *in_string); // Convert from string.
57 explicit LLUUID(const std::string& in_string); // Convert from string.
58 LLUUID(const LLUUID &in);
59 LLUUID &operator=(const LLUUID &rhs);
60
61 ~LLUUID();
62
63 //
64 // MANIPULATORS
65 //
66 void generate(); // Generate a new UUID
67 void generate(std::string stream); //Generate a new UUID based on hash of input stream
68 BOOL set(const char *in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings
69 BOOL set(const std::string& in_string, BOOL emit = TRUE); // Convert from string, if emit is FALSE, do not emit warnings
70 void setNull(); // Faster than setting to LLUUID::null.
71
72 S32 cmpTime(uuid_time_t *t1, uuid_time_t *t2);
73 static void getSystemTime(uuid_time_t *timestamp);
74 void getCurrentTime(uuid_time_t *timestamp);
75
76 //
77 // ACCESSORS
78 //
79 BOOL isNull() const; // Faster than comparing to LLUUID::null.
80 BOOL notNull() const; // Faster than comparing to LLUUID::null.
81 // JC: This is dangerous. It allows UUIDs to be cast automatically
82 // to integers, among other things. Use isNull() or notNull().
83 // operator bool() const;
84
85 // JC: These must return real bool's (not BOOLs) or else use of the STL
86 // will generate bool-to-int performance warnings.
87 bool operator==(const LLUUID &rhs) const;
88 bool operator!=(const LLUUID &rhs) const;
89 bool operator<(const LLUUID &rhs) const;
90 bool operator>(const LLUUID &rhs) const;
91
92 // xor functions. Useful since any two random uuids xored together
93 // will yield a determinate third random unique id that can be
94 // used as a key in a single uuid that represents 2.
95 const LLUUID& operator^=(const LLUUID& rhs);
96 LLUUID operator^(const LLUUID& rhs) const;
97
98 // similar to functions above, but not invertible
99 // yields a third random UUID that can be reproduced from the two inputs
100 // but which, given the result and one of the inputs can't be used to
101 // deduce the other input
102 LLUUID combine(const LLUUID& other) const;
103 void combine(const LLUUID& other, LLUUID& result) const;
104
105 friend std::ostream& operator<<(std::ostream& s, const LLUUID &uuid);
106 friend std::istream& operator>>(std::istream& s, LLUUID &uuid);
107
108 void toString(char *out) const; // Does not allocate memory, needs 36 characters (including \0)
109 void toCompressedString(char *out) const; // Does not allocate memory, needs 17 characters (including \0)
110
111 std::string asString() const;
112 std::string getString() const;
113
114 U16 getCRC16() const;
115 U32 getCRC32() const;
116
117 static BOOL validate(const std::string& in_string); // Validate that the UUID string is legal.
118 static BOOL validate(const char *in_string); // Validate that the UUID string is legal.
119
120 static const LLUUID null;
121
122 static U32 getRandomSeed();
123 static S32 getNodeID(unsigned char * node_id);
124
125 static BOOL parseUUID(const char* buf, LLUUID* value);
126
127 U8 mData[UUID_BYTES];
128};
129
130
131// Construct
132inline LLUUID::LLUUID()
133{
134 setNull();
135}
136
137
138// Faster than copying from memory
139inline void LLUUID::setNull()
140{
141 U32 *word = (U32 *)mData;
142 word[0] = 0;
143 word[1] = 0;
144 word[2] = 0;
145 word[3] = 0;
146}
147
148
149// Compare
150inline bool LLUUID::operator==(const LLUUID& rhs) const
151{
152 U32 *tmp = (U32 *)mData;
153 U32 *rhstmp = (U32 *)rhs.mData;
154 // Note: binary & to avoid branching
155 return
156 (tmp[0] == rhstmp[0]) &
157 (tmp[1] == rhstmp[1]) &
158 (tmp[2] == rhstmp[2]) &
159 (tmp[3] == rhstmp[3]);
160}
161
162
163inline bool LLUUID::operator!=(const LLUUID& rhs) const
164{
165 U32 *tmp = (U32 *)mData;
166 U32 *rhstmp = (U32 *)rhs.mData;
167 // Note: binary | to avoid branching
168 return
169 (tmp[0] != rhstmp[0]) |
170 (tmp[1] != rhstmp[1]) |
171 (tmp[2] != rhstmp[2]) |
172 (tmp[3] != rhstmp[3]);
173}
174
175/*
176// JC: This is dangerous. It allows UUIDs to be cast automatically
177// to integers, among other things. Use isNull() or notNull().
178inline LLUUID::operator bool() const
179{
180 U32 *word = (U32 *)mData;
181 return (word[0] | word[1] | word[2] | word[3]) > 0;
182}
183*/
184
185inline BOOL LLUUID::notNull() const
186{
187 U32 *word = (U32 *)mData;
188 return (word[0] | word[1] | word[2] | word[3]) > 0;
189}
190
191// Faster than == LLUUID::null because doesn't require
192// as much memory access.
193inline BOOL LLUUID::isNull() const
194{
195 U32 *word = (U32 *)mData;
196 // If all bits are zero, return !0 == TRUE
197 return !(word[0] | word[1] | word[2] | word[3]);
198}
199
200// Copy constructor
201inline LLUUID::LLUUID(const LLUUID& rhs)
202{
203 U32 *tmp = (U32 *)mData;
204 U32 *rhstmp = (U32 *)rhs.mData;
205 tmp[0] = rhstmp[0];
206 tmp[1] = rhstmp[1];
207 tmp[2] = rhstmp[2];
208 tmp[3] = rhstmp[3];
209}
210
211inline LLUUID::~LLUUID()
212{
213}
214
215// Assignment
216inline LLUUID& LLUUID::operator=(const LLUUID& rhs)
217{
218 // No need to check the case where this==&rhs. The branch is slower than the write.
219 U32 *tmp = (U32 *)mData;
220 U32 *rhstmp = (U32 *)rhs.mData;
221 tmp[0] = rhstmp[0];
222 tmp[1] = rhstmp[1];
223 tmp[2] = rhstmp[2];
224 tmp[3] = rhstmp[3];
225
226 return *this;
227}
228
229
230inline LLUUID::LLUUID(const char *in_string)
231{
232 if (!in_string || in_string[0] == 0)
233 {
234 setNull();
235 return;
236 }
237
238 set(in_string);
239}
240
241inline LLUUID::LLUUID(const std::string& in_string)
242{
243 if (in_string.empty())
244 {
245 setNull();
246 return;
247 }
248
249 set(in_string);
250}
251
252// IW: DON'T "optimize" these w/ U32s or you'll scoogie the sort order
253// IW: this will make me very sad
254inline bool LLUUID::operator<(const LLUUID &rhs) const
255{
256 U32 i;
257 for( i = 0; i < (UUID_BYTES - 1); i++ )
258 {
259 if( mData[i] != rhs.mData[i] )
260 {
261 return (mData[i] < rhs.mData[i]);
262 }
263 }
264 return (mData[UUID_BYTES - 1] < rhs.mData[UUID_BYTES - 1]);
265}
266
267inline bool LLUUID::operator>(const LLUUID &rhs) const
268{
269 U32 i;
270 for( i = 0; i < (UUID_BYTES - 1); i++ )
271 {
272 if( mData[i] != rhs.mData[i] )
273 {
274 return (mData[i] > rhs.mData[i]);
275 }
276 }
277 return (mData[UUID_BYTES - 1] > rhs.mData[UUID_BYTES - 1]);
278}
279
280inline U16 LLUUID::getCRC16() const
281{
282 // A UUID is 16 bytes, or 8 shorts.
283 U16 *short_data = (U16*)mData;
284 U16 out = 0;
285 out += short_data[0];
286 out += short_data[1];
287 out += short_data[2];
288 out += short_data[3];
289 out += short_data[4];
290 out += short_data[5];
291 out += short_data[6];
292 out += short_data[7];
293 return out;
294}
295
296inline U32 LLUUID::getCRC32() const
297{
298 U32 *tmp = (U32*)mData;
299 return tmp[0] + tmp[1] + tmp[2] + tmp[3];
300}
301
302
303// Helper structure for ordering lluuids in stl containers.
304// eg: std::map<LLUUID, LLWidget*, lluuid_less> widget_map;
305struct lluuid_less
306{
307 bool operator()(const LLUUID& lhs, const LLUUID& rhs) const
308 {
309 return (lhs < rhs) ? true : false;
310 }
311};
312
313typedef std::set<LLUUID, lluuid_less> uuid_list_t;
314
315/*
316 * Sub-classes for keeping transaction IDs and asset IDs
317 * straight.
318 */
319typedef LLUUID LLAssetID;
320
321class LLTransactionID : public LLUUID
322{
323public:
324 LLTransactionID() : LLUUID() { }
325
326 static const LLTransactionID tnull;
327 LLAssetID makeAssetID(const LLUUID& session) const;
328};
329
330#endif
diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp
index f7c9286..7b6c6a9 100644
--- a/linden/indra/llmath/llvolume.cpp
+++ b/linden/indra/llmath/llvolume.cpp
@@ -82,11 +82,6 @@ const F32 TAPER_MAX = 1.f;
82const F32 SKEW_MIN = -0.95f; 82const F32 SKEW_MIN = -0.95f;
83const F32 SKEW_MAX = 0.95f; 83const F32 SKEW_MAX = 0.95f;
84 84
85const S32 SCULPT_REZ_1 = 6; // changed from 4 to 6 - 6 looks round whereas 4 looks square
86const S32 SCULPT_REZ_2 = 8;
87const S32 SCULPT_REZ_3 = 16;
88const S32 SCULPT_REZ_4 = 32;
89
90const F32 SCULPT_MIN_AREA = 0.002f; 85const F32 SCULPT_MIN_AREA = 0.002f;
91 86
92BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm) 87BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm)
@@ -104,46 +99,128 @@ BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLV
104 } 99 }
105} 100}
106 101
107// intersect test between triangle pt1,pt2,pt3 and line from linept to linept+vect 102BOOL LLLineSegmentBoxIntersect(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size)
108//returns TRUE if intersecting and moves linept to the point of intersection 103{
109BOOL LLTriangleLineSegmentIntersect( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, LLVector3& linept, const LLVector3& vect) 104 float fAWdU[3];
105 LLVector3 dir;
106 LLVector3 diff;
107
108 for (U32 i = 0; i < 3; i++)
109 {
110 dir.mV[i] = 0.5f * (end.mV[i] - start.mV[i]);
111 diff.mV[i] = (0.5f * (end.mV[i] + start.mV[i])) - center.mV[i];
112 fAWdU[i] = fabsf(dir.mV[i]);
113 if(fabsf(diff.mV[i])>size.mV[i] + fAWdU[i]) return false;
114 }
115
116 float f;
117 f = dir.mV[1] * diff.mV[2] - dir.mV[2] * diff.mV[1]; if(fabsf(f)>size.mV[1]*fAWdU[2] + size.mV[2]*fAWdU[1]) return false;
118 f = dir.mV[2] * diff.mV[0] - dir.mV[0] * diff.mV[2]; if(fabsf(f)>size.mV[0]*fAWdU[2] + size.mV[2]*fAWdU[0]) return false;
119 f = dir.mV[0] * diff.mV[1] - dir.mV[1] * diff.mV[0]; if(fabsf(f)>size.mV[0]*fAWdU[1] + size.mV[1]*fAWdU[0]) return false;
120
121 return true;
122}
123
124
125// intersect test between triangle vert0, vert1, vert2 and a ray from orig in direction dir.
126// returns TRUE if intersecting and returns barycentric coordinates in intersection_a, intersection_b,
127// and returns the intersection point along dir in intersection_t.
128
129// Moller-Trumbore algorithm
130BOOL LLTriangleRayIntersect(const LLVector3& vert0, const LLVector3& vert1, const LLVector3& vert2, const LLVector3& orig, const LLVector3& dir,
131 F32* intersection_a, F32* intersection_b, F32* intersection_t, BOOL two_sided)
110{ 132{
111 LLVector3 V1 = pt2-pt1; 133 F32 u, v, t;
112 LLVector3 V2 = pt3-pt2;
113 134
114 LLVector3 norm = V1 % V2; 135 /* find vectors for two edges sharing vert0 */
136 LLVector3 edge1 = vert1 - vert0;
115 137
116 F32 dotprod = norm * vect; 138 LLVector3 edge2 = vert2 - vert0;;
117 139
118 if(dotprod < 0) 140 /* begin calculating determinant - also used to calculate U parameter */
141 LLVector3 pvec = dir % edge2;
142
143 /* if determinant is near zero, ray lies in plane of triangle */
144 F32 det = edge1 * pvec;
145
146 if (!two_sided)
119 { 147 {
120 //Find point of intersect to triangle plane. 148 if (det < F_APPROXIMATELY_ZERO)
121 //find t to intersect point 149 {
122 F32 t = -(norm * (linept-pt1))/dotprod; 150 return FALSE;
151 }
152
153 /* calculate distance from vert0 to ray origin */
154 LLVector3 tvec = orig - vert0;
123 155
124 // if ds is neg line started past triangle so can't hit triangle. 156 /* calculate U parameter and test bounds */
125 if (t > 0) 157 u = tvec * pvec;
158
159 if (u < 0.f || u > det)
126 { 160 {
127 return FALSE; 161 return FALSE;
128 } 162 }
129 163
130 LLVector3 pt_int = linept + (vect*t); 164 /* prepare to test V parameter */
165 LLVector3 qvec = tvec % edge1;
131 166
132 if(check_same_clock_dir(pt1, pt2, pt_int, norm)) 167 /* calculate V parameter and test bounds */
168 v = dir * qvec;
169 if (v < 0.f || u + v > det)
133 { 170 {
134 if(check_same_clock_dir(pt2, pt3, pt_int, norm)) 171 return FALSE;
172 }
173
174 /* calculate t, scale parameters, ray intersects triangle */
175 t = edge2 * qvec;
176 F32 inv_det = 1.0 / det;
177 t *= inv_det;
178 u *= inv_det;
179 v *= inv_det;
180 }
181
182 else // two sided
135 { 183 {
136 if(check_same_clock_dir(pt3, pt1, pt_int, norm)) 184 if (det > -F_APPROXIMATELY_ZERO && det < F_APPROXIMATELY_ZERO)
137 { 185 {
138 // answer in pt_int is insde triangle 186 return FALSE;
139 linept.setVec(pt_int);
140 return TRUE;
141 } 187 }
188 F32 inv_det = 1.0 / det;
189
190 /* calculate distance from vert0 to ray origin */
191 LLVector3 tvec = orig - vert0;
192
193 /* calculate U parameter and test bounds */
194 u = (tvec * pvec) * inv_det;
195 if (u < 0.f || u > 1.f)
196 {
197 return FALSE;
142 } 198 }
199
200 /* prepare to test V parameter */
201 LLVector3 qvec = tvec - edge1;
202
203 /* calculate V parameter and test bounds */
204 v = (dir * qvec) * inv_det;
205
206 if (v < 0.f || u + v > 1.f)
207 {
208 return FALSE;
143 } 209 }
210
211 /* calculate t, ray intersects triangle */
212 t = (edge2 * qvec) * inv_det;
144 } 213 }
145 214
146 return FALSE; 215 if (intersection_a != NULL)
216 *intersection_a = u;
217 if (intersection_b != NULL)
218 *intersection_b = v;
219 if (intersection_t != NULL)
220 *intersection_t = t;
221
222
223 return TRUE;
147} 224}
148 225
149 226
@@ -198,9 +275,6 @@ void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F3
198 F32 t, t_step, t_first, t_fraction, ang, ang_step; 275 F32 t, t_step, t_first, t_fraction, ang, ang_step;
199 LLVector3 pt1,pt2; 276 LLVector3 pt1,pt2;
200 277
201 mMaxX = 0.f;
202 mMinX = 0.f;
203
204 F32 begin = params.getBegin(); 278 F32 begin = params.getBegin();
205 F32 end = params.getEnd(); 279 F32 end = params.getEnd();
206 280
@@ -236,15 +310,6 @@ void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F3
236 if (t_fraction < 0.9999f) 310 if (t_fraction < 0.9999f)
237 { 311 {
238 LLVector3 new_pt = lerp(pt1, pt2, t_fraction); 312 LLVector3 new_pt = lerp(pt1, pt2, t_fraction);
239 F32 pt_x = new_pt.mV[VX];
240 if (pt_x < mMinX)
241 {
242 mMinX = pt_x;
243 }
244 else if (pt_x > mMaxX)
245 {
246 mMaxX = pt_x;
247 }
248 mProfile.push_back(new_pt); 313 mProfile.push_back(new_pt);
249 } 314 }
250 315
@@ -254,16 +319,6 @@ void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F3
254 // Iterate through all the integer steps of t. 319 // Iterate through all the integer steps of t.
255 pt1.setVec(cos(ang)*scale,sin(ang)*scale,t); 320 pt1.setVec(cos(ang)*scale,sin(ang)*scale,t);
256 321
257 F32 pt_x = pt1.mV[VX];
258 if (pt_x < mMinX)
259 {
260 mMinX = pt_x;
261 }
262 else if (pt_x > mMaxX)
263 {
264 mMaxX = pt_x;
265 }
266
267 if (mProfile.size() > 0) { 322 if (mProfile.size() > 0) {
268 LLVector3 p = mProfile[mProfile.size()-1]; 323 LLVector3 p = mProfile[mProfile.size()-1];
269 for (S32 i = 0; i < split && mProfile.size() > 0; i++) { 324 for (S32 i = 0; i < split && mProfile.size() > 0; i++) {
@@ -287,15 +342,6 @@ void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F3
287 if (t_fraction > 0.0001f) 342 if (t_fraction > 0.0001f)
288 { 343 {
289 LLVector3 new_pt = lerp(pt1, pt2, t_fraction); 344 LLVector3 new_pt = lerp(pt1, pt2, t_fraction);
290 F32 pt_x = new_pt.mV[VX];
291 if (pt_x < mMinX)
292 {
293 mMinX = pt_x;
294 }
295 else if (pt_x > mMaxX)
296 {
297 mMaxX = pt_x;
298 }
299 345
300 if (mProfile.size() > 0) { 346 if (mProfile.size() > 0) {
301 LLVector3 p = mProfile[mProfile.size()-1]; 347 LLVector3 p = mProfile[mProfile.size()-1];
@@ -472,31 +518,9 @@ LLProfile::Face* LLProfile::addHole(const LLProfileParams& params, BOOL flat, F3
472} 518}
473 519
474 520
475S32 sculpt_sides(F32 detail)
476{
477
478 // detail is usually one of: 1, 1.5, 2.5, 4.0.
479
480 if (detail <= 1.0)
481 {
482 return SCULPT_REZ_1;
483 }
484 if (detail <= 2.0)
485 {
486 return SCULPT_REZ_2;
487 }
488 if (detail <= 3.0)
489 {
490 return SCULPT_REZ_3;
491 }
492 else
493 {
494 return SCULPT_REZ_4;
495 }
496}
497
498 521
499BOOL LLProfile::generate(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split, BOOL is_sculpted) 522BOOL LLProfile::generate(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split,
523 BOOL is_sculpted, S32 sculpt_size)
500{ 524{
501 LLMemType m1(LLMemType::MTYPE_VOLUME); 525 LLMemType m1(LLMemType::MTYPE_VOLUME);
502 526
@@ -640,7 +664,7 @@ BOOL LLProfile::generate(const LLProfileParams& params, BOOL path_open,F32 detai
640 S32 sides = (S32)circle_detail; 664 S32 sides = (S32)circle_detail;
641 665
642 if (is_sculpted) 666 if (is_sculpted)
643 sides = sculpt_sides(detail); 667 sides = sculpt_size;
644 668
645 genNGon(params, sides); 669 genNGon(params, sides);
646 670
@@ -1131,7 +1155,8 @@ const LLVector2 LLPathParams::getEndScale() const
1131 return end_scale; 1155 return end_scale;
1132} 1156}
1133 1157
1134BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split, BOOL is_sculpted) 1158BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split,
1159 BOOL is_sculpted, S32 sculpt_size)
1135{ 1160{
1136 LLMemType m1(LLMemType::MTYPE_VOLUME); 1161 LLMemType m1(LLMemType::MTYPE_VOLUME);
1137 1162
@@ -1194,7 +1219,7 @@ BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split, BOOL is
1194 S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions()); 1219 S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions());
1195 1220
1196 if (is_sculpted) 1221 if (is_sculpted)
1197 sides = sculpt_sides(detail); 1222 sides = sculpt_size;
1198 1223
1199 genNGon(params, sides); 1224 genNGon(params, sides);
1200 } 1225 }
@@ -1259,7 +1284,8 @@ BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split, BOOL is
1259 return TRUE; 1284 return TRUE;
1260} 1285}
1261 1286
1262BOOL LLDynamicPath::generate(const LLPathParams& params, F32 detail, S32 split, BOOL is_sculpted) 1287BOOL LLDynamicPath::generate(const LLPathParams& params, F32 detail, S32 split,
1288 BOOL is_sculpted, S32 sculpt_size)
1263{ 1289{
1264 LLMemType m1(LLMemType::MTYPE_VOLUME); 1290 LLMemType m1(LLMemType::MTYPE_VOLUME);
1265 1291
@@ -1979,6 +2005,12 @@ void LLVolume::sculptGeneratePlaceholder()
1979// create the vertices from the map 2005// create the vertices from the map
1980void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type) 2006void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type)
1981{ 2007{
2008 U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
2009 BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
2010 BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
2011 BOOL reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror); // XOR
2012
2013
1982 LLMemType m1(LLMemType::MTYPE_VOLUME); 2014 LLMemType m1(LLMemType::MTYPE_VOLUME);
1983 2015
1984 S32 sizeS = mPathp->mPath.size(); 2016 S32 sizeS = mPathp->mPath.size();
@@ -1993,13 +2025,21 @@ void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8
1993 S32 i = t + line; 2025 S32 i = t + line;
1994 Point& pt = mMesh[i]; 2026 Point& pt = mMesh[i];
1995 2027
1996 U32 x = (U32) ((F32)t/(sizeT-1) * (F32) sculpt_width); 2028 S32 reversed_t = t;
2029
2030 if (reverse_horizontal)
2031 {
2032 reversed_t = sizeT - t - 1;
2033 }
2034
2035 U32 x = (U32) ((F32)reversed_t/(sizeT-1) * (F32) sculpt_width);
1997 U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height); 2036 U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height);
1998 2037
2038
1999 if (y == 0) // top row stitching 2039 if (y == 0) // top row stitching
2000 { 2040 {
2001 // pinch? 2041 // pinch?
2002 if (sculpt_type == LL_SCULPT_TYPE_SPHERE) 2042 if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
2003 { 2043 {
2004 x = sculpt_width / 2; 2044 x = sculpt_width / 2;
2005 } 2045 }
@@ -2008,7 +2048,7 @@ void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8
2008 if (y == sculpt_height) // bottom row stitching 2048 if (y == sculpt_height) // bottom row stitching
2009 { 2049 {
2010 // wrap? 2050 // wrap?
2011 if (sculpt_type == LL_SCULPT_TYPE_TORUS) 2051 if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
2012 { 2052 {
2013 y = 0; 2053 y = 0;
2014 } 2054 }
@@ -2018,7 +2058,7 @@ void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8
2018 } 2058 }
2019 2059
2020 // pinch? 2060 // pinch?
2021 if (sculpt_type == LL_SCULPT_TYPE_SPHERE) 2061 if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
2022 { 2062 {
2023 x = sculpt_width / 2; 2063 x = sculpt_width / 2;
2024 } 2064 }
@@ -2027,9 +2067,9 @@ void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8
2027 if (x == sculpt_width) // side stitching 2067 if (x == sculpt_width) // side stitching
2028 { 2068 {
2029 // wrap? 2069 // wrap?
2030 if ((sculpt_type == LL_SCULPT_TYPE_SPHERE) || 2070 if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
2031 (sculpt_type == LL_SCULPT_TYPE_TORUS) || 2071 (sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
2032 (sculpt_type == LL_SCULPT_TYPE_CYLINDER)) 2072 (sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
2033 { 2073 {
2034 x = 0; 2074 x = 0;
2035 } 2075 }
@@ -2041,12 +2081,69 @@ void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8
2041 } 2081 }
2042 2082
2043 pt.mPos = sculpt_xy_to_vector(x, y, sculpt_width, sculpt_height, sculpt_components, sculpt_data); 2083 pt.mPos = sculpt_xy_to_vector(x, y, sculpt_width, sculpt_height, sculpt_components, sculpt_data);
2084
2085 if (sculpt_mirror)
2086 {
2087 pt.mPos.mV[VX] *= -1.f;
2088 }
2044 } 2089 }
2090
2045 line += sizeT; 2091 line += sizeT;
2046 } 2092 }
2047} 2093}
2048 2094
2049 2095
2096const S32 SCULPT_REZ_1 = 6; // changed from 4 to 6 - 6 looks round whereas 4 looks square
2097const S32 SCULPT_REZ_2 = 8;
2098const S32 SCULPT_REZ_3 = 16;
2099const S32 SCULPT_REZ_4 = 32;
2100
2101S32 sculpt_sides(F32 detail)
2102{
2103
2104 // detail is usually one of: 1, 1.5, 2.5, 4.0.
2105
2106 if (detail <= 1.0)
2107 {
2108 return SCULPT_REZ_1;
2109 }
2110 if (detail <= 2.0)
2111 {
2112 return SCULPT_REZ_2;
2113 }
2114 if (detail <= 3.0)
2115 {
2116 return SCULPT_REZ_3;
2117 }
2118 else
2119 {
2120 return SCULPT_REZ_4;
2121 }
2122}
2123
2124
2125
2126// determine the number of vertices in both s and t direction for this sculpt
2127void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32& s, S32& t)
2128{
2129 S32 vertices = sculpt_sides(detail);
2130
2131 F32 ratio;
2132 if ((width == 0) || (height == 0))
2133 ratio = 1.f;
2134 else
2135 ratio = (F32) width / (F32) height;
2136
2137
2138 s = (S32)(vertices / fsqrtf(ratio));
2139
2140 s = llmax(s, 3); // no degenerate sizes, please
2141 t = vertices * vertices / s;
2142
2143 t = llmax(t, 3); // no degenerate sizes, please
2144 s = vertices * vertices / t;
2145}
2146
2050// sculpt replaces generate() for sculpted surfaces 2147// sculpt replaces generate() for sculpted surfaces
2051void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level) 2148void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level)
2052{ 2149{
@@ -2061,11 +2158,16 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components,
2061 data_is_empty = TRUE; 2158 data_is_empty = TRUE;
2062 } 2159 }
2063 2160
2064 mPathp->generate(mParams.getPathParams(), mDetail, 0, TRUE); 2161 S32 requested_sizeS = 0;
2065 mProfilep->generate(mParams.getProfileParams(), mPathp->isOpen(), mDetail, 0, TRUE); 2162 S32 requested_sizeT = 0;
2066 2163
2067 S32 sizeS = mPathp->mPath.size(); 2164 sculpt_calc_mesh_resolution(sculpt_width, sculpt_height, sculpt_type, mDetail, requested_sizeS, requested_sizeT);
2068 S32 sizeT = mProfilep->mProfile.size(); 2165
2166 mPathp->generate(mParams.getPathParams(), mDetail, 0, TRUE, requested_sizeS);
2167 mProfilep->generate(mParams.getProfileParams(), mPathp->isOpen(), mDetail, 0, TRUE, requested_sizeT);
2168
2169 S32 sizeS = mPathp->mPath.size(); // we requested a specific size, now see what we really got
2170 S32 sizeT = mProfilep->mProfile.size(); // we requested a specific size, now see what we really got
2069 2171
2070 // weird crash bug - DEV-11158 - trying to collect more data: 2172 // weird crash bug - DEV-11158 - trying to collect more data:
2071 if ((sizeS == 0) || (sizeT == 0)) 2173 if ((sizeS == 0) || (sizeT == 0))
@@ -3405,47 +3507,99 @@ void LLVolume::generateSilhouetteVertices(std::vector<LLVector3> &vertices,
3405 } 3507 }
3406} 3508}
3407 3509
3408S32 LLVolume::lineSegmentIntersect(const LLVector3& start, LLVector3& end) const 3510S32 LLVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
3511 S32 face,
3512 LLVector3* intersection,LLVector2* tex_coord, LLVector3* normal, LLVector3* bi_normal)
3409{ 3513{
3410 S32 ret = -1; 3514 S32 hit_face = -1;
3411 3515
3412 LLVector3 vec = end - start; 3516 S32 start_face;
3517 S32 end_face;
3413 3518
3414 for (S32 i = 0; i < getNumFaces(); i++) 3519 if (face == -1) // ALL_SIDES
3415 { 3520 {
3416 const LLVolumeFace& face = getVolumeFace(i); 3521 start_face = 0;
3522 end_face = getNumFaces() - 1;
3523 }
3524 else
3525 {
3526 start_face = face;
3527 end_face = face;
3528 }
3529
3530 LLVector3 dir = end - start;
3531
3532 F32 closest_t = 2.f; // must be larger than 1
3533
3534 for (S32 i = start_face; i <= end_face; i++)
3535 {
3536 const LLVolumeFace &face = getVolumeFace((U32)i);
3537
3538 LLVector3 box_center = (face.mExtents[0] + face.mExtents[1]) / 2.f;
3539 LLVector3 box_size = face.mExtents[1] - face.mExtents[0];
3540
3541 if (LLLineSegmentBoxIntersect(start, end, box_center, box_size))
3542 {
3543 if (bi_normal != NULL) // if the caller wants binormals, we may need to generate them
3544 {
3545 genBinormals(i);
3546 }
3547
3548 for (U32 tri = 0; tri < face.mIndices.size()/3; tri++)
3549 {
3550 S32 index1 = face.mIndices[tri*3+0];
3551 S32 index2 = face.mIndices[tri*3+1];
3552 S32 index3 = face.mIndices[tri*3+2];
3417 3553
3418 for (U32 j = 0; j < face.mIndices.size()/3; j++) 3554 F32 a, b, t;
3555
3556 if (LLTriangleRayIntersect(face.mVertices[index1].mPosition,
3557 face.mVertices[index2].mPosition,
3558 face.mVertices[index3].mPosition,
3559 start, dir, &a, &b, &t, FALSE))
3560 {
3561 if ((t >= 0.f) && // if hit is after start
3562 (t <= 1.f) && // and before end
3563 (t < closest_t)) // and this hit is closer
3419 { 3564 {
3420 //approximate normal 3565 closest_t = t;
3421 S32 v1 = face.mIndices[j*3+0]; 3566 hit_face = i;
3422 S32 v2 = face.mIndices[j*3+1];
3423 S32 v3 = face.mIndices[j*3+2];
3424 3567
3425 LLVector3 norm = (face.mVertices[v2].mPosition - face.mVertices[v1].mPosition) % 3568 if (intersection != NULL)
3426 (face.mVertices[v3].mPosition - face.mVertices[v2].mPosition); 3569 {
3570 *intersection = start + dir * closest_t;
3571 }
3427 3572
3428 if (norm.magVecSquared() >= 0.00000001f) 3573 if (tex_coord != NULL)
3429 { 3574 {
3430 //get view vector 3575 *tex_coord = ((1.f - a - b) * face.mVertices[index1].mTexCoord +
3431 //LLVector3 view = (start-face.mVertices[v1].mPosition); 3576 a * face.mVertices[index2].mTexCoord +
3432 //if (view * norm < 0.0f) 3577 b * face.mVertices[index3].mTexCoord);
3578
3579 }
3580
3581 if (normal != NULL)
3433 { 3582 {
3434 if (LLTriangleLineSegmentIntersect( face.mVertices[v1].mPosition, 3583 *normal = ((1.f - a - b) * face.mVertices[index1].mNormal +
3435 face.mVertices[v2].mPosition, 3584 a * face.mVertices[index2].mNormal +
3436 face.mVertices[v3].mPosition, 3585 b * face.mVertices[index3].mNormal);
3437 end, 3586 }
3438 vec)) 3587
3588 if (bi_normal != NULL)
3439 { 3589 {
3440 vec = end-start; 3590 *bi_normal = ((1.f - a - b) * face.mVertices[index1].mBinormal +
3441 ret = (S32) i; 3591 a * face.mVertices[index2].mBinormal +
3592 b * face.mVertices[index3].mBinormal);
3593 }
3594
3442 } 3595 }
3443 } 3596 }
3444 } 3597 }
3445 } 3598 }
3446 } 3599 }
3447 3600
3448 return ret; 3601
3602 return hit_face;
3449} 3603}
3450 3604
3451class LLVertexIndexPair 3605class LLVertexIndexPair
@@ -4768,6 +4922,13 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
4768 LLMemType m1(LLMemType::MTYPE_VOLUME); 4922 LLMemType m1(LLMemType::MTYPE_VOLUME);
4769 4923
4770 BOOL flat = mTypeMask & FLAT_MASK; 4924 BOOL flat = mTypeMask & FLAT_MASK;
4925
4926 U8 sculpt_type = volume->getParams().getSculptType();
4927 U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
4928 BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
4929 BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
4930 BOOL sculpt_reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror); // XOR
4931
4771 S32 num_vertices, num_indices; 4932 S32 num_vertices, num_indices;
4772 4933
4773 const std::vector<LLVolume::Point>& mesh = volume->getMesh(); 4934 const std::vector<LLVolume::Point>& mesh = volume->getMesh();
@@ -4834,6 +4995,11 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
4834 } 4995 }
4835 } 4996 }
4836 4997
4998 if (sculpt_reverse_horizontal)
4999 {
5000 ss = 1.f - ss;
5001 }
5002
4837 // Check to see if this triangle wraps around the array. 5003 // Check to see if this triangle wraps around the array.
4838 if (mBeginS + s >= max_s) 5004 if (mBeginS + s >= max_s)
4839 { 5005 {
@@ -4995,9 +5161,7 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
4995 5161
4996 BOOL s_bottom_converges = ((mVertices[0].mPosition - mVertices[mNumS*(mNumT-2)].mPosition).magVecSquared() < 0.000001f); 5162 BOOL s_bottom_converges = ((mVertices[0].mPosition - mVertices[mNumS*(mNumT-2)].mPosition).magVecSquared() < 0.000001f);
4997 BOOL s_top_converges = ((mVertices[mNumS-1].mPosition - mVertices[mNumS*(mNumT-2)+mNumS-1].mPosition).magVecSquared() < 0.000001f); 5163 BOOL s_top_converges = ((mVertices[mNumS-1].mPosition - mVertices[mNumS*(mNumT-2)+mNumS-1].mPosition).magVecSquared() < 0.000001f);
4998 U8 sculpt_type = volume->getParams().getSculptType(); 5164 if (sculpt_stitching == LL_SCULPT_TYPE_NONE) // logic for non-sculpt volumes
4999
5000 if (sculpt_type == LL_SCULPT_TYPE_NONE) // logic for non-sculpt volumes
5001 { 5165 {
5002 if (volume->getPath().isOpen() == FALSE) 5166 if (volume->getPath().isOpen() == FALSE)
5003 { //wrap normals on T 5167 { //wrap normals on T
@@ -5046,15 +5210,15 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
5046 BOOL wrap_s = FALSE; 5210 BOOL wrap_s = FALSE;
5047 BOOL wrap_t = FALSE; 5211 BOOL wrap_t = FALSE;
5048 5212
5049 if (sculpt_type == LL_SCULPT_TYPE_SPHERE) 5213 if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
5050 average_poles = TRUE; 5214 average_poles = TRUE;
5051 5215
5052 if ((sculpt_type == LL_SCULPT_TYPE_SPHERE) || 5216 if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
5053 (sculpt_type == LL_SCULPT_TYPE_TORUS) || 5217 (sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
5054 (sculpt_type == LL_SCULPT_TYPE_CYLINDER)) 5218 (sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
5055 wrap_s = TRUE; 5219 wrap_s = TRUE;
5056 5220
5057 if (sculpt_type == LL_SCULPT_TYPE_TORUS) 5221 if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
5058 wrap_t = TRUE; 5222 wrap_t = TRUE;
5059 5223
5060 5224
diff --git a/linden/indra/llmath/llvolume.h b/linden/indra/llmath/llvolume.h
index 5b48cfc..8ac0e71 100644
--- a/linden/indra/llmath/llvolume.h
+++ b/linden/indra/llmath/llvolume.h
@@ -175,7 +175,7 @@ const LLFaceID LL_FACE_OUTER_SIDE_3 = 0x1 << 8;
175 175
176//============================================================================ 176//============================================================================
177 177
178// sculpt types 178// sculpt types + flags
179 179
180const U8 LL_SCULPT_TYPE_NONE = 0; 180const U8 LL_SCULPT_TYPE_NONE = 0;
181const U8 LL_SCULPT_TYPE_SPHERE = 1; 181const U8 LL_SCULPT_TYPE_SPHERE = 1;
@@ -183,21 +183,30 @@ const U8 LL_SCULPT_TYPE_TORUS = 2;
183const U8 LL_SCULPT_TYPE_PLANE = 3; 183const U8 LL_SCULPT_TYPE_PLANE = 3;
184const U8 LL_SCULPT_TYPE_CYLINDER = 4; 184const U8 LL_SCULPT_TYPE_CYLINDER = 4;
185 185
186const U8 LL_SCULPT_TYPE_MASK = LL_SCULPT_TYPE_SPHERE | LL_SCULPT_TYPE_TORUS | LL_SCULPT_TYPE_PLANE | LL_SCULPT_TYPE_CYLINDER;
187
188const U8 LL_SCULPT_FLAG_INVERT = 64;
189const U8 LL_SCULPT_FLAG_MIRROR = 128;
186 190
187 191
188class LLProfileParams 192class LLProfileParams
189{ 193{
190public: 194public:
191 LLProfileParams() 195 LLProfileParams()
196 : mCurveType(LL_PCODE_PROFILE_SQUARE),
197 mBegin(0.f),
198 mEnd(1.f),
199 mHollow(0.f),
200 mCRC(0)
192 { 201 {
193 mCurveType = LL_PCODE_PROFILE_SQUARE;
194 mBegin = 0.f;
195 mEnd = 1.f;
196 mHollow = 0.f;
197 } 202 }
198 203
199 LLProfileParams(U8 curve, F32 begin, F32 end, F32 hollow) 204 LLProfileParams(U8 curve, F32 begin, F32 end, F32 hollow)
200 : mCurveType(curve), mBegin(begin), mEnd(end), mHollow(hollow) 205 : mCurveType(curve),
206 mBegin(begin),
207 mEnd(end),
208 mHollow(hollow),
209 mCRC(0)
201 { 210 {
202 } 211 }
203 212
@@ -222,6 +231,7 @@ public:
222 temp_f32 = 1.f; 231 temp_f32 = 1.f;
223 } 232 }
224 mHollow = temp_f32; 233 mHollow = temp_f32;
234 mCRC = 0;
225 } 235 }
226 236
227 bool operator==(const LLProfileParams &params) const; 237 bool operator==(const LLProfileParams &params) const;
@@ -309,27 +319,36 @@ class LLPathParams
309{ 319{
310public: 320public:
311 LLPathParams() 321 LLPathParams()
322 :
323 mCurveType(LL_PCODE_PATH_LINE),
324 mBegin(0.f),
325 mEnd(1.f),
326 mScale(1.f,1.f),
327 mShear(0.f,0.f),
328 mTwistBegin(0.f),
329 mTwistEnd(0.f),
330 mRadiusOffset(0.f),
331 mTaper(0.f,0.f),
332 mRevolutions(1.f),
333 mSkew(0.f),
334 mCRC(0)
312 { 335 {
313 mBegin = 0.f;
314 mEnd = 1.f;
315 mScale.setVec(1.f,1.f);
316 mShear.setVec(0.f,0.f);
317 mCurveType = LL_PCODE_PATH_LINE;
318 mTwistBegin = 0.f;
319 mTwistEnd = 0.f;
320 mRadiusOffset = 0.f;
321 mTaper.setVec(0.f,0.f);
322 mRevolutions = 1.f;
323 mSkew = 0.f;
324 } 336 }
325 337
326 LLPathParams(U8 curve, F32 begin, F32 end, F32 scx, F32 scy, F32 shx, F32 shy, F32 twistend, F32 twistbegin, F32 radiusoffset, F32 tx, F32 ty, F32 revolutions, F32 skew) 338 LLPathParams(U8 curve, F32 begin, F32 end, F32 scx, F32 scy, F32 shx, F32 shy, F32 twistend, F32 twistbegin, F32 radiusoffset, F32 tx, F32 ty, F32 revolutions, F32 skew)
327 : mCurveType(curve), mBegin(begin), mEnd(end), mTwistBegin(twistbegin), mTwistEnd(twistend), 339 : mCurveType(curve),
328 mRadiusOffset(radiusoffset), mRevolutions(revolutions), mSkew(skew) 340 mBegin(begin),
341 mEnd(end),
342 mScale(scx,scy),
343 mShear(shx,shy),
344 mTwistBegin(twistbegin),
345 mTwistEnd(twistend),
346 mRadiusOffset(radiusoffset),
347 mTaper(tx,ty),
348 mRevolutions(revolutions),
349 mSkew(skew),
350 mCRC(0)
329 { 351 {
330 mScale.setVec(scx,scy);
331 mShear.setVec(shx,shy);
332 mTaper.setVec(tx,ty);
333 } 352 }
334 353
335 LLPathParams(U8 curve, U16 begin, U16 end, U8 scx, U8 scy, U8 shx, U8 shy, U8 twistend, U8 twistbegin, U8 radiusoffset, U8 tx, U8 ty, U8 revolutions, U8 skew) 354 LLPathParams(U8 curve, U16 begin, U16 end, U8 scx, U8 scy, U8 shx, U8 shy, U8 twistend, U8 twistbegin, U8 radiusoffset, U8 tx, U8 ty, U8 revolutions, U8 skew)
@@ -347,6 +366,8 @@ public:
347 mTaper.setVec(U8_TO_F32(tx) * TAPER_QUANTA,U8_TO_F32(ty) * TAPER_QUANTA); 366 mTaper.setVec(U8_TO_F32(tx) * TAPER_QUANTA,U8_TO_F32(ty) * TAPER_QUANTA);
348 mRevolutions = ((F32)revolutions) * REV_QUANTA + 1.0f; 367 mRevolutions = ((F32)revolutions) * REV_QUANTA + 1.0f;
349 mSkew = U8_TO_F32(skew) * SCALE_QUANTA; 368 mSkew = U8_TO_F32(skew) * SCALE_QUANTA;
369
370 mCRC = 0;
350 } 371 }
351 372
352 bool operator==(const LLPathParams &params) const; 373 bool operator==(const LLPathParams &params) const;
@@ -525,6 +546,7 @@ class LLVolumeParams
525{ 546{
526public: 547public:
527 LLVolumeParams() 548 LLVolumeParams()
549 : mSculptType(LL_SCULPT_TYPE_NONE)
528 { 550 {
529 } 551 }
530 552
@@ -649,7 +671,9 @@ public:
649 mConcave(FALSE), 671 mConcave(FALSE),
650 mDirty(TRUE), 672 mDirty(TRUE),
651 mTotalOut(0), 673 mTotalOut(0),
652 mTotal(2) 674 mTotal(2),
675 mMinX(0.f),
676 mMaxX(0.f)
653 { 677 {
654 } 678 }
655 679
@@ -660,7 +684,8 @@ public:
660 BOOL isFlat(S32 face) const { return (mFaces[face].mCount == 2); } 684 BOOL isFlat(S32 face) const { return (mFaces[face].mCount == 2); }
661 BOOL isOpen() const { return mOpen; } 685 BOOL isOpen() const { return mOpen; }
662 void setDirty() { mDirty = TRUE; } 686 void setDirty() { mDirty = TRUE; }
663 BOOL generate(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0, BOOL is_sculpted = FALSE); 687 BOOL generate(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0,
688 BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
664 BOOL isConcave() const { return mConcave; } 689 BOOL isConcave() const { return mConcave; }
665public: 690public:
666 struct Face 691 struct Face
@@ -678,8 +703,6 @@ public:
678 std::vector<Face> mFaces; 703 std::vector<Face> mFaces;
679 std::vector<LLVector3> mEdgeNormals; 704 std::vector<LLVector3> mEdgeNormals;
680 std::vector<LLVector3> mEdgeCenters; 705 std::vector<LLVector3> mEdgeCenters;
681 F32 mMaxX;
682 F32 mMinX;
683 706
684 friend std::ostream& operator<<(std::ostream &s, const LLProfile &profile); 707 friend std::ostream& operator<<(std::ostream &s, const LLProfile &profile);
685 708
@@ -698,6 +721,9 @@ protected:
698 721
699 S32 mTotalOut; 722 S32 mTotalOut;
700 S32 mTotal; 723 S32 mTotal;
724
725 F32 mMaxX;
726 F32 mMinX;
701}; 727};
702 728
703//------------------------------------------------------------------- 729//-------------------------------------------------------------------
@@ -728,7 +754,8 @@ public:
728 virtual ~LLPath(); 754 virtual ~LLPath();
729 755
730 void genNGon(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f); 756 void genNGon(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f);
731 virtual BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0, BOOL is_sculpted = FALSE); 757 virtual BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
758 BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
732 759
733 BOOL isOpen() const { return mOpen; } 760 BOOL isOpen() const { return mOpen; }
734 F32 getStep() const { return mStep; } 761 F32 getStep() const { return mStep; }
@@ -754,7 +781,8 @@ class LLDynamicPath : public LLPath
754{ 781{
755public: 782public:
756 LLDynamicPath() : LLPath() { } 783 LLDynamicPath() : LLPath() { }
757 /*virtual*/ BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0, BOOL is_sculpted = FALSE); 784 /*virtual*/ BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
785 BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
758}; 786};
759 787
760// Yet another "face" class - caches volume-specific, but not instance-specific data for faces) 788// Yet another "face" class - caches volume-specific, but not instance-specific data for faces)
@@ -885,7 +913,13 @@ public:
885 //get the face index of the face that intersects with the given line segment at the point 913 //get the face index of the face that intersects with the given line segment at the point
886 //closest to start. Moves end to the point of intersection. Returns -1 if no intersection. 914 //closest to start. Moves end to the point of intersection. Returns -1 if no intersection.
887 //Line segment must be in volume space. 915 //Line segment must be in volume space.
888 S32 lineSegmentIntersect(const LLVector3& start, LLVector3& end) const; 916 S32 lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
917 S32 face = -1, // which face to check, -1 = ALL_SIDES
918 LLVector3* intersection = NULL, // return the intersection point
919 LLVector2* tex_coord = NULL, // return the texture coordinates of the intersection point
920 LLVector3* normal = NULL, // return the surface normal at the intersection point
921 LLVector3* bi_normal = NULL // return the surface bi-normal at the intersection point
922 );
889 923
890 // The following cleans up vertices and triangles, 924 // The following cleans up vertices and triangles,
891 // getting rid of degenerate triangles and duplicate vertices, 925 // getting rid of degenerate triangles and duplicate vertices,
@@ -916,6 +950,8 @@ private:
916 F32 sculptGetSurfaceArea(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data); 950 F32 sculptGetSurfaceArea(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data);
917 void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type); 951 void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type);
918 void sculptGeneratePlaceholder(); 952 void sculptGeneratePlaceholder();
953 void sculptCalcMeshResolution(U16 width, U16 height, U8 type, S32& s, S32& t);
954
919 955
920protected: 956protected:
921 BOOL generate(); 957 BOOL generate();
@@ -946,4 +982,10 @@ LLVector3 calc_binormal_from_triangle(
946 const LLVector3& pos2, 982 const LLVector3& pos2,
947 const LLVector2& tex2); 983 const LLVector2& tex2);
948 984
985BOOL LLLineSegmentBoxIntersect(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size);
986BOOL LLTriangleRayIntersect(const LLVector3& vert0, const LLVector3& vert1, const LLVector3& vert2, const LLVector3& orig, const LLVector3& dir,
987 F32* intersection_a, F32* intersection_b, F32* intersection_t, BOOL two_sided);
988
989
990
949#endif 991#endif
diff --git a/linden/indra/llmath/llvolumemgr.cpp b/linden/indra/llmath/llvolumemgr.cpp
index 0b5464c..a3cd6b5 100644
--- a/linden/indra/llmath/llvolumemgr.cpp
+++ b/linden/indra/llmath/llvolumemgr.cpp
@@ -115,7 +115,7 @@ LLVolume* LLVolumeMgr::refVolume(const LLVolumeParams &volume_params, const S32
115 { 115 {
116 mDataMutex->unlock(); 116 mDataMutex->unlock();
117 } 117 }
118 return volgroupp->getLODVolume(detail); 118 return volgroupp->refLOD(detail);
119} 119}
120 120
121// virtual 121// virtual
@@ -294,7 +294,7 @@ bool LLVolumeLODGroup::cleanupRefs()
294 return res; 294 return res;
295} 295}
296 296
297LLVolume* LLVolumeLODGroup::getLODVolume(const S32 detail) 297LLVolume* LLVolumeLODGroup::refLOD(const S32 detail)
298{ 298{
299 llassert(detail >=0 && detail < NUM_LODS); 299 llassert(detail >=0 && detail < NUM_LODS);
300 mAccessCount[detail]++; 300 mAccessCount[detail]++;
@@ -376,7 +376,6 @@ F32 LLVolumeLODGroup::getVolumeScaleFromDetail(const S32 detail)
376 376
377F32 LLVolumeLODGroup::dump() 377F32 LLVolumeLODGroup::dump()
378{ 378{
379 char dump_str[255]; /* Flawfinder: ignore */
380 F32 usage = 0.f; 379 F32 usage = 0.f;
381 for (S32 i = 0; i < NUM_LODS; i++) 380 for (S32 i = 0; i < NUM_LODS; i++)
382 { 381 {
@@ -387,7 +386,7 @@ F32 LLVolumeLODGroup::dump()
387 } 386 }
388 usage = usage / (F32)NUM_LODS; 387 usage = usage / (F32)NUM_LODS;
389 388
390 snprintf(dump_str, sizeof(dump_str), "%.3f %d %d %d %d", usage, mAccessCount[0], mAccessCount[1], mAccessCount[2], mAccessCount[3]); /* Flawfinder: ignore */ 389 std::string dump_str = llformat("%.3f %d %d %d %d", usage, mAccessCount[0], mAccessCount[1], mAccessCount[2], mAccessCount[3]);
391 390
392 llinfos << dump_str << llendl; 391 llinfos << dump_str << llendl;
393 return usage; 392 return usage;
diff --git a/linden/indra/llmath/llvolumemgr.h b/linden/indra/llmath/llvolumemgr.h
index dcaca01..d579fed 100644
--- a/linden/indra/llmath/llvolumemgr.h
+++ b/linden/indra/llmath/llvolumemgr.h
@@ -59,7 +59,7 @@ public:
59 static void getDetailProximity(const F32 tan_angle, F32 &to_lower, F32& to_higher); 59 static void getDetailProximity(const F32 tan_angle, F32 &to_lower, F32& to_higher);
60 static F32 getVolumeScaleFromDetail(const S32 detail); 60 static F32 getVolumeScaleFromDetail(const S32 detail);
61 61
62 LLVolume* getLODVolume(const S32 detail); 62 LLVolume* refLOD(const S32 detail);
63 BOOL derefLOD(LLVolume *volumep); 63 BOOL derefLOD(LLVolume *volumep);
64 S32 getNumRefs() const { return mRefs; } 64 S32 getNumRefs() const { return mRefs; }
65 65
diff --git a/linden/indra/llmath/v2math.cpp b/linden/indra/llmath/v2math.cpp
index 76fa60f..c3bb093 100644
--- a/linden/indra/llmath/v2math.cpp
+++ b/linden/indra/llmath/v2math.cpp
@@ -33,6 +33,7 @@
33 33
34//#include "vmath.h" 34//#include "vmath.h"
35#include "v2math.h" 35#include "v2math.h"
36#include "v3math.h"
36#include "v4math.h" 37#include "v4math.h"
37#include "m4math.h" 38#include "m4math.h"
38#include "m3math.h" 39#include "m3math.h"
diff --git a/linden/indra/llmath/v2math.h b/linden/indra/llmath/v2math.h
index 5a520d2..350079d 100644
--- a/linden/indra/llmath/v2math.h
+++ b/linden/indra/llmath/v2math.h
@@ -33,6 +33,7 @@
33#define LL_V2MATH_H 33#define LL_V2MATH_H
34 34
35#include "llmath.h" 35#include "llmath.h"
36#include "v3math.h"
36 37
37class LLVector4; 38class LLVector4;
38class LLMatrix3; 39class LLMatrix3;
@@ -49,9 +50,10 @@ class LLVector2
49 50
50 static LLVector2 zero; 51 static LLVector2 zero;
51 52
52 LLVector2(); // Initializes LLVector2 to (0, 0) 53 LLVector2(); // Initializes LLVector2 to (0, 0)
53 LLVector2(F32 x, F32 y); // Initializes LLVector2 to (x. y) 54 LLVector2(F32 x, F32 y); // Initializes LLVector2 to (x. y)
54 LLVector2(const F32 *vec); // Initializes LLVector2 to (vec[0]. vec[1]) 55 LLVector2(const F32 *vec); // Initializes LLVector2 to (vec[0]. vec[1])
56 explicit LLVector2(const LLVector3 &vec); // Initializes LLVector2 to (vec[0]. vec[1])
55 57
56 // Clears LLVector2 to (0, 0). DEPRECATED - prefer zeroVec. 58 // Clears LLVector2 to (0, 0). DEPRECATED - prefer zeroVec.
57 void clear(); 59 void clear();
@@ -137,6 +139,12 @@ inline LLVector2::LLVector2(const F32 *vec)
137 mV[VY] = vec[VY]; 139 mV[VY] = vec[VY];
138} 140}
139 141
142inline LLVector2::LLVector2(const LLVector3 &vec)
143{
144 mV[VX] = vec.mV[VX];
145 mV[VY] = vec.mV[VY];
146}
147
140 148
141// Clear and Assignment Functions 149// Clear and Assignment Functions
142 150
diff --git a/linden/indra/llmath/v3color.h b/linden/indra/llmath/v3color.h
index a3bf385..b9bc641 100644
--- a/linden/indra/llmath/v3color.h
+++ b/linden/indra/llmath/v3color.h
@@ -174,6 +174,10 @@ inline LLColor3::LLColor3(const F32 *vec)
174 mV[VZ] = vec[VZ]; 174 mV[VZ] = vec[VZ];
175} 175}
176 176
177#if LL_WINDOWS
178# pragma warning( disable : 4996 ) // strncpy teh sux0r
179#endif
180
177inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGBB" where RR is hex 00..FF 181inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGBB" where RR is hex 00..FF
178{ 182{
179 if (strlen(color_string) < 6) /* Flawfinder: ignore */ 183 if (strlen(color_string) < 6) /* Flawfinder: ignore */
diff --git a/linden/indra/llmath/v3dmath.cpp b/linden/indra/llmath/v3dmath.cpp
index b59f519..5a3246c 100644
--- a/linden/indra/llmath/v3dmath.cpp
+++ b/linden/indra/llmath/v3dmath.cpp
@@ -132,15 +132,15 @@ const LLVector3d& LLVector3d::rotVec(F64 angle, F64 x, F64 y, F64 z)
132} 132}
133 133
134 134
135BOOL LLVector3d::parseVector3d(const char* buf, LLVector3d* value) 135BOOL LLVector3d::parseVector3d(const std::string& buf, LLVector3d* value)
136{ 136{
137 if( buf == NULL || buf[0] == '\0' || value == NULL) 137 if( buf.empty() || value == NULL)
138 { 138 {
139 return FALSE; 139 return FALSE;
140 } 140 }
141 141
142 LLVector3d v; 142 LLVector3d v;
143 S32 count = sscanf( buf, "%lf %lf %lf", v.mdV + 0, v.mdV + 1, v.mdV + 2 ); 143 S32 count = sscanf( buf.c_str(), "%lf %lf %lf", v.mdV + 0, v.mdV + 1, v.mdV + 2 );
144 if( 3 == count ) 144 if( 3 == count )
145 { 145 {
146 value->setVec( v ); 146 value->setVec( v );
diff --git a/linden/indra/llmath/v3dmath.h b/linden/indra/llmath/v3dmath.h
index 9bd80b8..ecb333a 100644
--- a/linden/indra/llmath/v3dmath.h
+++ b/linden/indra/llmath/v3dmath.h
@@ -95,6 +95,10 @@ class LLVector3d
95 F64 magVecSquared() const; // Returns magnitude squared of LLVector3d 95 F64 magVecSquared() const; // Returns magnitude squared of LLVector3d
96 inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d 96 inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d
97 97
98 F64 length() const; // Returns magnitude of LLVector3d
99 F64 lengthSquared() const; // Returns magnitude squared of LLVector3d
100 inline F64 normalize(); // Normalizes and returns the magnitude of LLVector3d
101
98 const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians 102 const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians
99 const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians 103 const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians
100 const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat 104 const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat
@@ -128,7 +132,7 @@ class LLVector3d
128 132
129 friend std::ostream& operator<<(std::ostream& s, const LLVector3d &a); // Stream a 133 friend std::ostream& operator<<(std::ostream& s, const LLVector3d &a); // Stream a
130 134
131 static BOOL parseVector3d(const char* buf, LLVector3d* value); 135 static BOOL parseVector3d(const std::string& buf, LLVector3d* value);
132 136
133}; 137};
134 138
@@ -261,6 +265,28 @@ inline F64 LLVector3d::normVec(void)
261 return (mag); 265 return (mag);
262} 266}
263 267
268inline F64 LLVector3d::normalize(void)
269{
270 F64 mag = fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
271 F64 oomag;
272
273 if (mag > FP_MAG_THRESHOLD)
274 {
275 oomag = 1.f/mag;
276 mdV[0] *= oomag;
277 mdV[1] *= oomag;
278 mdV[2] *= oomag;
279 }
280 else
281 {
282 mdV[0] = 0.f;
283 mdV[1] = 0.f;
284 mdV[2] = 0.f;
285 mag = 0;
286 }
287 return (mag);
288}
289
264// LLVector3d Magnitude and Normalization Functions 290// LLVector3d Magnitude and Normalization Functions
265 291
266inline F64 LLVector3d::magVec(void) const 292inline F64 LLVector3d::magVec(void) const
@@ -273,6 +299,16 @@ inline F64 LLVector3d::magVecSquared(void) const
273 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; 299 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
274} 300}
275 301
302inline F64 LLVector3d::length(void) const
303{
304 return fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
305}
306
307inline F64 LLVector3d::lengthSquared(void) const
308{
309 return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
310}
311
276inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b) 312inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b)
277{ 313{
278 LLVector3d c(a); 314 LLVector3d c(a);
@@ -416,8 +452,8 @@ inline F64 angle_between(const LLVector3d& a, const LLVector3d& b)
416{ 452{
417 LLVector3d an = a; 453 LLVector3d an = a;
418 LLVector3d bn = b; 454 LLVector3d bn = b;
419 an.normVec(); 455 an.normalize();
420 bn.normVec(); 456 bn.normalize();
421 F64 cosine = an * bn; 457 F64 cosine = an * bn;
422 F64 angle = (cosine >= 1.0f) ? 0.0f : 458 F64 angle = (cosine >= 1.0f) ? 0.0f :
423 (cosine <= -1.0f) ? F_PI : 459 (cosine <= -1.0f) ? F_PI :
@@ -429,8 +465,8 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
429{ 465{
430 LLVector3d an = a; 466 LLVector3d an = a;
431 LLVector3d bn = b; 467 LLVector3d bn = b;
432 an.normVec(); 468 an.normalize();
433 bn.normVec(); 469 bn.normalize();
434 F64 dot = an * bn; 470 F64 dot = an * bn;
435 if ( (1.0f - fabs(dot)) < epsilon) 471 if ( (1.0f - fabs(dot)) < epsilon)
436 { 472 {
@@ -443,7 +479,7 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
443inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b) 479inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b)
444{ 480{
445 LLVector3d project_axis = b; 481 LLVector3d project_axis = b;
446 project_axis.normVec(); 482 project_axis.normalize();
447 return project_axis * (a * project_axis); 483 return project_axis * (a * project_axis);
448} 484}
449 485
diff --git a/linden/indra/llmath/v3math.cpp b/linden/indra/llmath/v3math.cpp
index bbe460f..cb87836 100644
--- a/linden/indra/llmath/v3math.cpp
+++ b/linden/indra/llmath/v3math.cpp
@@ -34,6 +34,7 @@
34#include "v3math.h" 34#include "v3math.h"
35 35
36//#include "vmath.h" 36//#include "vmath.h"
37#include "v2math.h"
37#include "v4math.h" 38#include "v4math.h"
38#include "m4math.h" 39#include "m4math.h"
39#include "m3math.h" 40#include "m3math.h"
@@ -73,6 +74,72 @@ BOOL LLVector3::clamp(F32 min, F32 max)
73 return ret; 74 return ret;
74} 75}
75 76
77// Clamps length to an upper limit.
78// Returns TRUE if the data changed
79BOOL LLVector3::clampLength( F32 length_limit )
80{
81 BOOL changed = FALSE;
82
83 F32 len = length();
84 if (llfinite(len))
85 {
86 if ( len > length_limit)
87 {
88 normalize();
89 if (length_limit < 0.f)
90 {
91 length_limit = 0.f;
92 }
93 mV[0] *= length_limit;
94 mV[1] *= length_limit;
95 mV[2] *= length_limit;
96 changed = TRUE;
97 }
98 }
99 else
100 { // this vector may still be salvagable
101 F32 max_abs_component = 0.f;
102 for (S32 i = 0; i < 3; ++i)
103 {
104 F32 abs_component = fabs(mV[i]);
105 if (llfinite(abs_component))
106 {
107 if (abs_component > max_abs_component)
108 {
109 max_abs_component = abs_component;
110 }
111 }
112 else
113 {
114 // no it can't be salvaged --> clear it
115 clear();
116 changed = TRUE;
117 break;
118 }
119 }
120 if (!changed)
121 {
122 // yes it can be salvaged -->
123 // bring the components down before we normalize
124 mV[0] /= max_abs_component;
125 mV[1] /= max_abs_component;
126 mV[2] /= max_abs_component;
127 normalize();
128
129 if (length_limit < 0.f)
130 {
131 length_limit = 0.f;
132 }
133 mV[0] *= length_limit;
134 mV[1] *= length_limit;
135 mV[2] *= length_limit;
136 }
137 }
138
139 return changed;
140}
141
142
76// Sets all values to absolute value of their original values 143// Sets all values to absolute value of their original values
77// Returns TRUE if data changed 144// Returns TRUE if data changed
78BOOL LLVector3::abs() 145BOOL LLVector3::abs()
@@ -204,6 +271,13 @@ const LLVector3& LLVector3::setVec(const LLVector4 &vec)
204 return (*this); 271 return (*this);
205} 272}
206 273
274LLVector3::LLVector3(const LLVector2 &vec)
275{
276 mV[VX] = (F32)vec.mV[VX];
277 mV[VY] = (F32)vec.mV[VY];
278 mV[VZ] = 0;
279}
280
207LLVector3::LLVector3(const LLVector3d &vec) 281LLVector3::LLVector3(const LLVector3d &vec)
208{ 282{
209 mV[VX] = (F32)vec.mdV[VX]; 283 mV[VX] = (F32)vec.mdV[VX];
@@ -260,15 +334,15 @@ const LLVector3& operator*=(LLVector3 &a, const LLQuaternion &rot)
260} 334}
261 335
262// static 336// static
263BOOL LLVector3::parseVector3(const char* buf, LLVector3* value) 337BOOL LLVector3::parseVector3(const std::string& buf, LLVector3* value)
264{ 338{
265 if( buf == NULL || buf[0] == '\0' || value == NULL) 339 if( buf.empty() || value == NULL)
266 { 340 {
267 return FALSE; 341 return FALSE;
268 } 342 }
269 343
270 LLVector3 v; 344 LLVector3 v;
271 S32 count = sscanf( buf, "%f %f %f", v.mV + 0, v.mV + 1, v.mV + 2 ); 345 S32 count = sscanf( buf.c_str(), "%f %f %f", v.mV + 0, v.mV + 1, v.mV + 2 );
272 if( 3 == count ) 346 if( 3 == count )
273 { 347 {
274 value->setVec( v ); 348 value->setVec( v );
diff --git a/linden/indra/llmath/v3math.h b/linden/indra/llmath/v3math.h
index ddb5e1f..65932cd 100644
--- a/linden/indra/llmath/v3math.h
+++ b/linden/indra/llmath/v3math.h
@@ -36,6 +36,7 @@
36#include "llmath.h" 36#include "llmath.h"
37 37
38#include "llsd.h" 38#include "llsd.h"
39class LLVector2;
39class LLVector4; 40class LLVector4;
40class LLMatrix3; 41class LLMatrix3;
41class LLVector3d; 42class LLVector3d;
@@ -62,6 +63,7 @@ class LLVector3
62 inline LLVector3(); // Initializes LLVector3 to (0, 0, 0) 63 inline LLVector3(); // Initializes LLVector3 to (0, 0, 0)
63 inline LLVector3(const F32 x, const F32 y, const F32 z); // Initializes LLVector3 to (x. y, z) 64 inline LLVector3(const F32 x, const F32 y, const F32 z); // Initializes LLVector3 to (x. y, z)
64 inline explicit LLVector3(const F32 *vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) 65 inline explicit LLVector3(const F32 *vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2])
66 explicit LLVector3(const LLVector2 &vec); // Initializes LLVector3 to (vec[0]. vec[1], 0)
65 explicit LLVector3(const LLVector3d &vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2]) 67 explicit LLVector3(const LLVector3d &vec); // Initializes LLVector3 to (vec[0]. vec[1], vec[2])
66 explicit LLVector3(const LLVector4 &vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2]) 68 explicit LLVector3(const LLVector4 &vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2])
67 LLVector3(const LLSD& sd); 69 LLVector3(const LLSD& sd);
@@ -74,6 +76,7 @@ class LLVector3
74 76
75 inline BOOL isFinite() const; // checks to see if all values of LLVector3 are finite 77 inline BOOL isFinite() const; // checks to see if all values of LLVector3 are finite
76 BOOL clamp(F32 min, F32 max); // Clamps all values to (min,max), returns TRUE if data changed 78 BOOL clamp(F32 min, F32 max); // Clamps all values to (min,max), returns TRUE if data changed
79 BOOL clampLength( F32 length_limit ); // Scales vector to limit length to a value
77 80
78 void quantize16(F32 lowerxy, F32 upperxy, F32 lowerz, F32 upperz); // changes the vector to reflect quatization 81 void quantize16(F32 lowerxy, F32 upperxy, F32 lowerz, F32 upperz); // changes the vector to reflect quatization
79 void quantize8(F32 lowerxy, F32 upperxy, F32 lowerz, F32 upperz); // changes the vector to reflect quatization 82 void quantize8(F32 lowerxy, F32 upperxy, F32 lowerz, F32 upperz); // changes the vector to reflect quatization
@@ -147,7 +150,7 @@ class LLVector3
147 150
148 friend std::ostream& operator<<(std::ostream& s, const LLVector3 &a); // Stream a 151 friend std::ostream& operator<<(std::ostream& s, const LLVector3 &a); // Stream a
149 152
150 static BOOL parseVector3(const char* buf, LLVector3* value); 153 static BOOL parseVector3(const std::string& buf, LLVector3* value);
151}; 154};
152 155
153typedef LLVector3 LLSimLocalVec; 156typedef LLVector3 LLSimLocalVec;
diff --git a/linden/indra/llmath/v4color.cpp b/linden/indra/llmath/v4color.cpp
index 8e6907e..88237a0 100644
--- a/linden/indra/llmath/v4color.cpp
+++ b/linden/indra/llmath/v4color.cpp
@@ -286,16 +286,14 @@ void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const
286} 286}
287 287
288// static 288// static
289BOOL LLColor4::parseColor(const char* buf, LLColor4* color) 289BOOL LLColor4::parseColor(const std::string& buf, LLColor4* color)
290{ 290{
291 if( buf == NULL || buf[0] == '\0' || color == NULL) 291 if( buf.empty() || color == NULL)
292 { 292 {
293 return FALSE; 293 return FALSE;
294 } 294 }
295 295
296 LLString full_string(buf); 296 boost_tokenizer tokens(buf, boost::char_separator<char>(", "));
297
298 boost_tokenizer tokens(full_string, boost::char_separator<char>(", "));
299 boost_tokenizer::iterator token_iter = tokens.begin(); 297 boost_tokenizer::iterator token_iter = tokens.begin();
300 if (token_iter == tokens.end()) 298 if (token_iter == tokens.end())
301 { 299 {
@@ -304,15 +302,15 @@ BOOL LLColor4::parseColor(const char* buf, LLColor4* color)
304 302
305 // Grab the first token into a string, since we don't know 303 // Grab the first token into a string, since we don't know
306 // if this is a float or a color name. 304 // if this is a float or a color name.
307 LLString color_name( (*token_iter) ); 305 std::string color_name( (*token_iter) );
308 ++token_iter; 306 ++token_iter;
309 307
310 if (token_iter != tokens.end()) 308 if (token_iter != tokens.end())
311 { 309 {
312 // There are more tokens to read. This must be a vector. 310 // There are more tokens to read. This must be a vector.
313 LLColor4 v; 311 LLColor4 v;
314 LLString::convertToF32( color_name, v.mV[VX] ); 312 LLStringUtil::convertToF32( color_name, v.mV[VX] );
315 LLString::convertToF32( *token_iter, v.mV[VY] ); 313 LLStringUtil::convertToF32( *token_iter, v.mV[VY] );
316 v.mV[VZ] = 0.0f; 314 v.mV[VZ] = 0.0f;
317 v.mV[VW] = 1.0f; 315 v.mV[VW] = 1.0f;
318 316
@@ -320,18 +318,18 @@ BOOL LLColor4::parseColor(const char* buf, LLColor4* color)
320 if (token_iter == tokens.end()) 318 if (token_iter == tokens.end())
321 { 319 {
322 // This is a malformed vector. 320 // This is a malformed vector.
323 llwarns << "LLColor4::parseColor() malformed color " << full_string << llendl; 321 llwarns << "LLColor4::parseColor() malformed color " << buf << llendl;
324 } 322 }
325 else 323 else
326 { 324 {
327 // There is a z-component. 325 // There is a z-component.
328 LLString::convertToF32( *token_iter, v.mV[VZ] ); 326 LLStringUtil::convertToF32( *token_iter, v.mV[VZ] );
329 327
330 ++token_iter; 328 ++token_iter;
331 if (token_iter != tokens.end()) 329 if (token_iter != tokens.end())
332 { 330 {
333 // There is an alpha component. 331 // There is an alpha component.
334 LLString::convertToF32( *token_iter, v.mV[VW] ); 332 LLStringUtil::convertToF32( *token_iter, v.mV[VW] );
335 } 333 }
336 } 334 }
337 335
@@ -615,19 +613,19 @@ BOOL LLColor4::parseColor(const char* buf, LLColor4* color)
615} 613}
616 614
617// static 615// static
618BOOL LLColor4::parseColor4(const char* buf, LLColor4* value) 616BOOL LLColor4::parseColor4(const std::string& buf, LLColor4* value)
619{ 617{
620 if( buf == NULL || buf[0] == '\0' || value == NULL) 618 if( buf.empty() || value == NULL)
621 { 619 {
622 return FALSE; 620 return FALSE;
623 } 621 }
624 622
625 LLColor4 v; 623 LLColor4 v;
626 S32 count = sscanf( buf, "%f, %f, %f, %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 ); 624 S32 count = sscanf( buf.c_str(), "%f, %f, %f, %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 );
627 if (1 == count ) 625 if (1 == count )
628 { 626 {
629 // try this format 627 // try this format
630 count = sscanf( buf, "%f %f %f %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 ); 628 count = sscanf( buf.c_str(), "%f %f %f %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 );
631 } 629 }
632 if( 4 == count ) 630 if( 4 == count )
633 { 631 {
diff --git a/linden/indra/llmath/v4color.h b/linden/indra/llmath/v4color.h
index a2c0fb6..53e4407 100644
--- a/linden/indra/llmath/v4color.h
+++ b/linden/indra/llmath/v4color.h
@@ -211,8 +211,8 @@ class LLColor4
211 static LLColor4 cyan5; 211 static LLColor4 cyan5;
212 static LLColor4 cyan6; 212 static LLColor4 cyan6;
213 213
214 static BOOL parseColor(const char* buf, LLColor4* color); 214 static BOOL parseColor(const std::string& buf, LLColor4* color);
215 static BOOL parseColor4(const char* buf, LLColor4* color); 215 static BOOL parseColor4(const std::string& buf, LLColor4* color);
216 216
217 inline void clamp(); 217 inline void clamp();
218}; 218};
diff --git a/linden/indra/llmath/v4coloru.cpp b/linden/indra/llmath/v4coloru.cpp
index 56a8413..7ad7eb2 100644
--- a/linden/indra/llmath/v4coloru.cpp
+++ b/linden/indra/llmath/v4coloru.cpp
@@ -93,19 +93,19 @@ std::ostream& operator<<(std::ostream& s, const LLColor4U &a)
93} 93}
94 94
95// static 95// static
96BOOL LLColor4U::parseColor4U(const char* buf, LLColor4U* value) 96BOOL LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
97{ 97{
98 if( buf == NULL || buf[0] == '\0' || value == NULL) 98 if( buf.empty() || value == NULL)
99 { 99 {
100 return FALSE; 100 return FALSE;
101 } 101 }
102 102
103 U32 v[4]; 103 U32 v[4];
104 S32 count = sscanf( buf, "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 ); 104 S32 count = sscanf( buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 );
105 if (1 == count ) 105 if (1 == count )
106 { 106 {
107 // try this format 107 // try this format
108 count = sscanf( buf, "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 ); 108 count = sscanf( buf.c_str(), "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 );
109 } 109 }
110 if( 4 != count ) 110 if( 4 != count )
111 { 111 {
diff --git a/linden/indra/llmath/v4coloru.h b/linden/indra/llmath/v4coloru.h
index c9c5418..910a081 100644
--- a/linden/indra/llmath/v4coloru.h
+++ b/linden/indra/llmath/v4coloru.h
@@ -127,7 +127,7 @@ public:
127 inline void setVecScaleClamp(const LLColor3 &color); 127 inline void setVecScaleClamp(const LLColor3 &color);
128 inline void setVecScaleClamp(const LLColor4 &color); 128 inline void setVecScaleClamp(const LLColor4 &color);
129 129
130 static BOOL parseColor4U(const char* buf, LLColor4U* value); 130 static BOOL parseColor4U(const std::string& buf, LLColor4U* value);
131 131
132 static LLColor4U white; 132 static LLColor4U white;
133 static LLColor4U black; 133 static LLColor4U black;