diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llroam.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llroam.h')
-rw-r--r-- | linden/indra/newview/llroam.h | 304 |
1 files changed, 304 insertions, 0 deletions
diff --git a/linden/indra/newview/llroam.h b/linden/indra/newview/llroam.h new file mode 100644 index 0000000..0202332 --- /dev/null +++ b/linden/indra/newview/llroam.h | |||
@@ -0,0 +1,304 @@ | |||
1 | /** | ||
2 | * @file llroam.h | ||
3 | * @brief LLRoam and related class definitions | ||
4 | * | ||
5 | * Copyright (c) 2003-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | /****************************************/ | ||
29 | /* Implementation of ROAM algorithm */ | ||
30 | /****************************************/ | ||
31 | |||
32 | #ifndef LL_ROAM_H | ||
33 | #define LL_ROAM_H | ||
34 | |||
35 | #include "stdtypes.h" | ||
36 | #include "doublelinkedlist.h" | ||
37 | |||
38 | class LLRoamPatch; | ||
39 | class LLRoam; | ||
40 | |||
41 | class LLRoamTriNode | ||
42 | { | ||
43 | protected: | ||
44 | U8 mLevel; | ||
45 | S8 mType; // -1 - left child, 1 - righ child, 0 - top vertex | ||
46 | LLRoamTriNode* mParent; | ||
47 | LLRoamTriNode* mLchild; | ||
48 | LLRoamTriNode* mRchild; | ||
49 | LLRoamTriNode* mLeft; | ||
50 | LLRoamTriNode* mRight; | ||
51 | LLRoamTriNode* mBase; | ||
52 | LLRoamPatch* mPatch; | ||
53 | BOOL mLeaf; | ||
54 | BOOL mInQueue; | ||
55 | |||
56 | public: | ||
57 | static LLRoam* sQueues; | ||
58 | |||
59 | //LLRoamTriNode(S8 level = 0, const LLRoamTriNode* left = 0 | ||
60 | // const LLRoamTriNode* right = 0, const LLRoamTriNode* base = 0): | ||
61 | // mLevel(level), mLeft(left), mRight(right), mBase(base), mLchild(0), mRchild(0) {} | ||
62 | LLRoamTriNode(U8 level = 0, S8 type = 0, LLRoamTriNode* par = 0): | ||
63 | mLevel(level), mType(type), mParent(par), mLchild(0), mRchild(0), | ||
64 | mLeft(0), mRight(0), mBase(0), mPatch(0), | ||
65 | mLeaf(TRUE), mInQueue(FALSE) {} | ||
66 | |||
67 | virtual LLRoamTriNode* newLChild() | ||
68 | { | ||
69 | return new LLRoamTriNode(mLevel+1, -1, this); | ||
70 | } | ||
71 | virtual LLRoamTriNode* newRChild() | ||
72 | { | ||
73 | return new LLRoamTriNode(mLevel+1, 1, this); | ||
74 | } | ||
75 | |||
76 | virtual ~LLRoamTriNode(); | ||
77 | LLRoamTriNode* Lchild() const { return mLchild; } | ||
78 | LLRoamTriNode* Rchild() const { return mRchild; } | ||
79 | LLRoamTriNode* left() const { return mLeft; } | ||
80 | LLRoamTriNode* right() const { return mRight; } | ||
81 | LLRoamTriNode* base() const { return mBase; } | ||
82 | LLRoamTriNode* parent() const { return mParent; } | ||
83 | void setLeft(LLRoamTriNode* left) { mLeft = left; } | ||
84 | void setRight(LLRoamTriNode* right) { mRight = right; } | ||
85 | void setBase(LLRoamTriNode* base) { mBase = base; } | ||
86 | void setParent(LLRoamTriNode* parent) { mParent = parent; } | ||
87 | U8 level() const { return mLevel; } | ||
88 | BOOL leaf() const { return mLeaf; } | ||
89 | |||
90 | void updateLink(LLRoamTriNode* old_link, LLRoamTriNode* new_link); | ||
91 | BOOL split(BOOL forceful = FALSE); | ||
92 | BOOL merge(); | ||
93 | void mergeSimple(); | ||
94 | //void refine(); | ||
95 | void update(); | ||
96 | virtual void updatePassive() {} | ||
97 | |||
98 | virtual BOOL refine();// { return patch()->refine(this); } | ||
99 | virtual void initForcefulRefine() {} | ||
100 | virtual void flushFromQueue() {} | ||
101 | LLRoamPatch* patch() const { return mPatch; } | ||
102 | void setPatch(LLRoamPatch* p) { mPatch = p; } | ||
103 | |||
104 | const LLRoamTriNode* getFirstLeaf() const; | ||
105 | const LLRoamTriNode* getNextLeaf() const; | ||
106 | |||
107 | BOOL inQueue() const { return mInQueue; } | ||
108 | void enqueue() { mInQueue = TRUE; } | ||
109 | void dequeue() { mInQueue = FALSE; } | ||
110 | |||
111 | BOOL checkConsistensy() const | ||
112 | { | ||
113 | BOOL ok = TRUE; | ||
114 | if (leaf()) | ||
115 | { | ||
116 | if (base() && !base()->leaf()) | ||
117 | ok = FALSE; | ||
118 | if (Lchild() && !Lchild()->leaf()) | ||
119 | ok = FALSE; | ||
120 | if (Rchild() && !Rchild()->leaf()) | ||
121 | ok = FALSE; | ||
122 | } else { | ||
123 | if (base() && base()->leaf()) | ||
124 | ok = FALSE; | ||
125 | } | ||
126 | return ok; | ||
127 | } | ||
128 | |||
129 | }; | ||
130 | |||
131 | |||
132 | class LLRoamPatch | ||
133 | { | ||
134 | protected: | ||
135 | BOOL mBackSlash; | ||
136 | LLRoamTriNode* mTri[2]; | ||
137 | U8 mMaxLevel; | ||
138 | U32 mNumTris; | ||
139 | public: | ||
140 | LLRoamPatch(U8 max_level, BOOL back_slash) : mBackSlash(back_slash), mMaxLevel(max_level), mNumTris(0) | ||
141 | { | ||
142 | mTri[0] = 0; | ||
143 | mTri[1] = 0; | ||
144 | } | ||
145 | |||
146 | virtual ~LLRoamPatch() { deleteTris(); } | ||
147 | void deleteTris() | ||
148 | { | ||
149 | delete mTri[0]; | ||
150 | mTri[0] = 0; | ||
151 | delete mTri[1]; | ||
152 | mTri[1] = 0; | ||
153 | } | ||
154 | |||
155 | void updatePassive() | ||
156 | { | ||
157 | mTri[0]->updatePassive(); | ||
158 | mTri[1]->updatePassive(); | ||
159 | } | ||
160 | |||
161 | void update() | ||
162 | { | ||
163 | mTri[0]->update(); | ||
164 | mTri[1]->update(); | ||
165 | |||
166 | //checkCount(); | ||
167 | } | ||
168 | |||
169 | U32 checkCount() | ||
170 | { | ||
171 | BOOL ok = TRUE; | ||
172 | U32 ntri = 0; | ||
173 | for (U8 h = 0; h < 2; h++) | ||
174 | { | ||
175 | for (const LLRoamTriNode* tri = mTri[h]->getFirstLeaf(); | ||
176 | tri != NULL; | ||
177 | tri = tri->getNextLeaf()) | ||
178 | ntri++; | ||
179 | } | ||
180 | if (ntri != mNumTris) | ||
181 | ok = FALSE; | ||
182 | return mNumTris; | ||
183 | } | ||
184 | |||
185 | LLRoamTriNode* left() const { return mTri[0]; } | ||
186 | LLRoamTriNode* right() const { return mTri[1]; } | ||
187 | LLRoamTriNode* half(U8 h) const { return mTri[h]; } | ||
188 | |||
189 | U8 maxLevel() const { return mMaxLevel; } | ||
190 | BOOL refine(const LLRoamTriNode* tri) const { return tri->level() < mMaxLevel; } | ||
191 | U32 numTris() const { return mNumTris; } | ||
192 | U32 numTrisInc() { mNumTris++; return mNumTris; } | ||
193 | U32 numTrisDec() { mNumTris--; return mNumTris; } | ||
194 | void setTris(LLRoamTriNode* left, LLRoamTriNode* right) | ||
195 | { | ||
196 | mTri[0] = left; | ||
197 | mTri[1] = right; | ||
198 | setTris(); | ||
199 | } | ||
200 | |||
201 | void setTris() | ||
202 | { | ||
203 | mTri[0]->setBase(mTri[1]); | ||
204 | mTri[1]->setBase(mTri[0]); | ||
205 | mTri[0]->setPatch(this); | ||
206 | mTri[1]->setPatch(this); | ||
207 | mNumTris = 2; | ||
208 | } | ||
209 | void checkConsistensy() const | ||
210 | { | ||
211 | for (U8 h = 0; h < 2; h++) | ||
212 | { | ||
213 | left()->checkConsistensy(); | ||
214 | right()->checkConsistensy(); | ||
215 | /* | ||
216 | for (const LLWaterTri* tri = (LLWaterTri*)mTri[h]->getFirstLeaf(); | ||
217 | tri != NULL; | ||
218 | tri = (LLWaterTri*)tri->getNextLeaf()) | ||
219 | { | ||
220 | if (!tri->upToDate()) | ||
221 | return FALSE; | ||
222 | } */ | ||
223 | } | ||
224 | } | ||
225 | }; | ||
226 | |||
227 | inline BOOL LLRoamTriNode::refine() { return patch()->refine(this); } | ||
228 | |||
229 | class LLRoam | ||
230 | { | ||
231 | protected: | ||
232 | LLDoubleLinkedList<LLRoamTriNode> mSplitQ; | ||
233 | LLDoubleLinkedList<LLRoamTriNode> mMergeQ; | ||
234 | U32 mNum; | ||
235 | public: | ||
236 | LLRoam() {} | ||
237 | ~LLRoam() { mSplitQ.removeAllNodes(); mMergeQ.removeAllNodes(); } | ||
238 | |||
239 | void pushSplit(LLRoamTriNode* t) | ||
240 | { | ||
241 | if (!t->inQueue()) | ||
242 | { | ||
243 | mSplitQ.addDataAtEnd(t); | ||
244 | t->enqueue(); | ||
245 | } | ||
246 | } | ||
247 | LLRoamTriNode* popSplit() | ||
248 | { | ||
249 | LLRoamTriNode* t = mSplitQ.getFirstData(); | ||
250 | t->dequeue(); | ||
251 | mSplitQ.removeCurrentData(); | ||
252 | return t; | ||
253 | } | ||
254 | void pushMerge(LLRoamTriNode* t) | ||
255 | { | ||
256 | if (!t->inQueue()) | ||
257 | { | ||
258 | mMergeQ.addDataAtEnd(t); | ||
259 | t->enqueue(); | ||
260 | } | ||
261 | } | ||
262 | LLRoamTriNode* popMerge() | ||
263 | { | ||
264 | LLRoamTriNode* t = mMergeQ.getFirstData(); | ||
265 | t->dequeue(); | ||
266 | mMergeQ.removeCurrentData(); | ||
267 | return t; | ||
268 | } | ||
269 | |||
270 | void queueForSplit(LLRoamTriNode* t, BOOL process_base = TRUE); | ||
271 | void queueForMerge(LLRoamTriNode* t, BOOL process_base = TRUE); | ||
272 | |||
273 | void processSplit(); | ||
274 | void processMerge(); | ||
275 | void process(); | ||
276 | |||
277 | U32 numOfProcessedTris() const { return mNum; } | ||
278 | void numOfProcessedTrisInc() { mNum++; } | ||
279 | void resetCount() { mNum = 0; } | ||
280 | // BOOL processTooLong() const { return mNum > 10000; } | ||
281 | void flushSplit(); | ||
282 | void flushMerge(); | ||
283 | /* | ||
284 | void cutProcessing() | ||
285 | { | ||
286 | flushMerge(); | ||
287 | flushSplit(); | ||
288 | resetCount(); | ||
289 | } */ | ||
290 | void checkTiming() | ||
291 | { | ||
292 | if (mNum > 1000) | ||
293 | { | ||
294 | flushMerge(); | ||
295 | flushSplit(); | ||
296 | resetCount(); | ||
297 | } | ||
298 | } | ||
299 | |||
300 | BOOL mergeQueueTooLong() const { return mMergeQ.getLength() > 1000; } | ||
301 | BOOL splitQueueTooLong() const { return mSplitQ.getLength() > 1000; } | ||
302 | }; | ||
303 | |||
304 | #endif | ||