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/llcharacter/llmultigesture.cpp | |
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/llcharacter/llmultigesture.cpp')
-rw-r--r-- | linden/indra/llcharacter/llmultigesture.cpp | 489 |
1 files changed, 489 insertions, 0 deletions
diff --git a/linden/indra/llcharacter/llmultigesture.cpp b/linden/indra/llcharacter/llmultigesture.cpp new file mode 100644 index 0000000..80cbacb --- /dev/null +++ b/linden/indra/llcharacter/llmultigesture.cpp | |||
@@ -0,0 +1,489 @@ | |||
1 | /** | ||
2 | * @file llmultigesture.cpp | ||
3 | * @brief Gestures that are asset-based and can have multiple steps. | ||
4 | * | ||
5 | * Copyright (c) 2004-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 | #include "linden_common.h" | ||
29 | |||
30 | #include <algorithm> | ||
31 | |||
32 | #include "stdio.h" | ||
33 | |||
34 | #include "llmultigesture.h" | ||
35 | |||
36 | #include "llerror.h" | ||
37 | #include "lldatapacker.h" | ||
38 | #include "llstl.h" | ||
39 | |||
40 | const S32 GESTURE_VERSION = 2; | ||
41 | |||
42 | //--------------------------------------------------------------------------- | ||
43 | // LLMultiGesture | ||
44 | //--------------------------------------------------------------------------- | ||
45 | LLMultiGesture::LLMultiGesture() | ||
46 | : mKey(), | ||
47 | mMask(), | ||
48 | mTrigger(), | ||
49 | mReplaceText(), | ||
50 | mSteps(), | ||
51 | mPlaying(FALSE), | ||
52 | mCurrentStep(0), | ||
53 | mDoneCallback(NULL), | ||
54 | mCallbackData(NULL) | ||
55 | { | ||
56 | reset(); | ||
57 | } | ||
58 | |||
59 | LLMultiGesture::~LLMultiGesture() | ||
60 | { | ||
61 | std::for_each(mSteps.begin(), mSteps.end(), DeletePointer()); | ||
62 | } | ||
63 | |||
64 | void LLMultiGesture::reset() | ||
65 | { | ||
66 | mPlaying = FALSE; | ||
67 | mCurrentStep = 0; | ||
68 | mWaitTimer.reset(); | ||
69 | mWaitingTimer = FALSE; | ||
70 | mWaitingAnimations = FALSE; | ||
71 | mWaitingAtEnd = FALSE; | ||
72 | mRequestedAnimIDs.clear(); | ||
73 | mPlayingAnimIDs.clear(); | ||
74 | } | ||
75 | |||
76 | S32 LLMultiGesture::getMaxSerialSize() const | ||
77 | { | ||
78 | S32 max_size = 0; | ||
79 | |||
80 | // ascii format, being very conservative about possible | ||
81 | // label lengths. | ||
82 | max_size += 64; // version S32 | ||
83 | max_size += 64; // key U8 | ||
84 | max_size += 64; // mask U32 | ||
85 | max_size += 256; // trigger string | ||
86 | max_size += 256; // replace string | ||
87 | |||
88 | max_size += 64; // step count S32 | ||
89 | |||
90 | std::vector<LLGestureStep*>::const_iterator it; | ||
91 | for (it = mSteps.begin(); it != mSteps.end(); ++it) | ||
92 | { | ||
93 | LLGestureStep* step = *it; | ||
94 | max_size += 64; // type S32 | ||
95 | max_size += step->getMaxSerialSize(); | ||
96 | } | ||
97 | |||
98 | /* binary format | ||
99 | max_size += sizeof(S32); // version | ||
100 | max_size += sizeof(mKey); | ||
101 | max_size += sizeof(mMask); | ||
102 | max_size += mTrigger.length() + 1; // for null | ||
103 | |||
104 | max_size += sizeof(S32); // step count | ||
105 | |||
106 | std::vector<LLGestureStep*>::const_iterator it; | ||
107 | for (it = mSteps.begin(); it != mSteps.end(); ++it) | ||
108 | { | ||
109 | LLGestureStep* step = *it; | ||
110 | max_size += sizeof(S32); // type | ||
111 | max_size += step->getMaxSerialSize(); | ||
112 | } | ||
113 | */ | ||
114 | |||
115 | return max_size; | ||
116 | } | ||
117 | |||
118 | BOOL LLMultiGesture::serialize(LLDataPacker& dp) const | ||
119 | { | ||
120 | dp.packS32(GESTURE_VERSION, "version"); | ||
121 | dp.packU8(mKey, "key"); | ||
122 | dp.packU32(mMask, "mask"); | ||
123 | dp.packString(mTrigger.c_str(), "trigger"); | ||
124 | dp.packString(mReplaceText.c_str(), "replace"); | ||
125 | |||
126 | S32 count = (S32)mSteps.size(); | ||
127 | dp.packS32(count, "step_count"); | ||
128 | S32 i; | ||
129 | for (i = 0; i < count; ++i) | ||
130 | { | ||
131 | LLGestureStep* step = mSteps[i]; | ||
132 | |||
133 | dp.packS32(step->getType(), "step_type"); | ||
134 | BOOL ok = step->serialize(dp); | ||
135 | if (!ok) | ||
136 | { | ||
137 | return FALSE; | ||
138 | } | ||
139 | } | ||
140 | return TRUE; | ||
141 | } | ||
142 | |||
143 | BOOL LLMultiGesture::deserialize(LLDataPacker& dp) | ||
144 | { | ||
145 | S32 version; | ||
146 | dp.unpackS32(version, "version"); | ||
147 | if (version != GESTURE_VERSION) | ||
148 | { | ||
149 | llwarns << "Bad LLMultiGesture version " << version | ||
150 | << " should be " << GESTURE_VERSION | ||
151 | << llendl; | ||
152 | return FALSE; | ||
153 | } | ||
154 | |||
155 | dp.unpackU8(mKey, "key"); | ||
156 | dp.unpackU32(mMask, "mask"); | ||
157 | |||
158 | |||
159 | dp.unpackString(mTrigger, "trigger"); | ||
160 | |||
161 | dp.unpackString(mReplaceText, "replace"); | ||
162 | |||
163 | S32 count; | ||
164 | dp.unpackS32(count, "step_count"); | ||
165 | if (count < 0) | ||
166 | { | ||
167 | llwarns << "Bad LLMultiGesture step count " << count << llendl; | ||
168 | return FALSE; | ||
169 | } | ||
170 | |||
171 | S32 i; | ||
172 | for (i = 0; i < count; ++i) | ||
173 | { | ||
174 | S32 type; | ||
175 | dp.unpackS32(type, "step_type"); | ||
176 | |||
177 | EStepType step_type = (EStepType)type; | ||
178 | switch(step_type) | ||
179 | { | ||
180 | case STEP_ANIMATION: | ||
181 | { | ||
182 | LLGestureStepAnimation* step = new LLGestureStepAnimation(); | ||
183 | BOOL ok = step->deserialize(dp); | ||
184 | if (!ok) return FALSE; | ||
185 | mSteps.push_back(step); | ||
186 | break; | ||
187 | } | ||
188 | case STEP_SOUND: | ||
189 | { | ||
190 | LLGestureStepSound* step = new LLGestureStepSound(); | ||
191 | BOOL ok = step->deserialize(dp); | ||
192 | if (!ok) return FALSE; | ||
193 | mSteps.push_back(step); | ||
194 | break; | ||
195 | } | ||
196 | case STEP_CHAT: | ||
197 | { | ||
198 | LLGestureStepChat* step = new LLGestureStepChat(); | ||
199 | BOOL ok = step->deserialize(dp); | ||
200 | if (!ok) return FALSE; | ||
201 | mSteps.push_back(step); | ||
202 | break; | ||
203 | } | ||
204 | case STEP_WAIT: | ||
205 | { | ||
206 | LLGestureStepWait* step = new LLGestureStepWait(); | ||
207 | BOOL ok = step->deserialize(dp); | ||
208 | if (!ok) return FALSE; | ||
209 | mSteps.push_back(step); | ||
210 | break; | ||
211 | } | ||
212 | default: | ||
213 | { | ||
214 | llwarns << "Bad LLMultiGesture step type " << type << llendl; | ||
215 | return FALSE; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | return TRUE; | ||
220 | } | ||
221 | |||
222 | void LLMultiGesture::dump() | ||
223 | { | ||
224 | llinfos << "key " << S32(mKey) << " mask " << U32(mMask) | ||
225 | << " trigger " << mTrigger | ||
226 | << " replace " << mReplaceText | ||
227 | << llendl; | ||
228 | U32 i; | ||
229 | for (i = 0; i < mSteps.size(); ++i) | ||
230 | { | ||
231 | LLGestureStep* step = mSteps[i]; | ||
232 | step->dump(); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | //--------------------------------------------------------------------------- | ||
237 | // LLGestureStepAnimation | ||
238 | //--------------------------------------------------------------------------- | ||
239 | LLGestureStepAnimation::LLGestureStepAnimation() | ||
240 | : LLGestureStep(), | ||
241 | mAnimName("None"), | ||
242 | mAnimAssetID(), | ||
243 | mFlags(0x0) | ||
244 | { } | ||
245 | |||
246 | LLGestureStepAnimation::~LLGestureStepAnimation() | ||
247 | { } | ||
248 | |||
249 | S32 LLGestureStepAnimation::getMaxSerialSize() const | ||
250 | { | ||
251 | S32 max_size = 0; | ||
252 | |||
253 | // ascii | ||
254 | max_size += 256; // anim name | ||
255 | max_size += 64; // anim asset id | ||
256 | max_size += 64; // flags | ||
257 | |||
258 | /* binary | ||
259 | max_size += mAnimName.length() + 1; | ||
260 | max_size += sizeof(mAnimAssetID); | ||
261 | max_size += sizeof(mFlags); | ||
262 | */ | ||
263 | return max_size; | ||
264 | } | ||
265 | |||
266 | BOOL LLGestureStepAnimation::serialize(LLDataPacker& dp) const | ||
267 | { | ||
268 | dp.packString(mAnimName.c_str(), "anim_name"); | ||
269 | dp.packUUID(mAnimAssetID, "asset_id"); | ||
270 | dp.packU32(mFlags, "flags"); | ||
271 | return TRUE; | ||
272 | } | ||
273 | |||
274 | BOOL LLGestureStepAnimation::deserialize(LLDataPacker& dp) | ||
275 | { | ||
276 | dp.unpackString(mAnimName, "anim_name"); | ||
277 | |||
278 | // Apparently an earlier version of the gesture code added \r to the end | ||
279 | // of the animation names. Get rid of it. JC | ||
280 | if (mAnimName[mAnimName.length() - 1] == '\r') | ||
281 | { | ||
282 | // chop the last character | ||
283 | mAnimName.resize(mAnimName.length() - 1); | ||
284 | } | ||
285 | |||
286 | dp.unpackUUID(mAnimAssetID, "asset_id"); | ||
287 | dp.unpackU32(mFlags, "flags"); | ||
288 | return TRUE; | ||
289 | } | ||
290 | |||
291 | std::string LLGestureStepAnimation::getLabel() const | ||
292 | { | ||
293 | std::string label; | ||
294 | if (mFlags & ANIM_FLAG_STOP) | ||
295 | { | ||
296 | label = "Stop Animation: "; | ||
297 | } | ||
298 | else | ||
299 | { | ||
300 | label = "Start Animation: "; | ||
301 | } | ||
302 | label += mAnimName; | ||
303 | return label; | ||
304 | } | ||
305 | |||
306 | void LLGestureStepAnimation::dump() | ||
307 | { | ||
308 | llinfos << "step animation " << mAnimName | ||
309 | << " id " << mAnimAssetID | ||
310 | << " flags " << mFlags | ||
311 | << llendl; | ||
312 | } | ||
313 | |||
314 | //--------------------------------------------------------------------------- | ||
315 | // LLGestureStepSound | ||
316 | //--------------------------------------------------------------------------- | ||
317 | LLGestureStepSound::LLGestureStepSound() | ||
318 | : LLGestureStep(), | ||
319 | mSoundName("None"), | ||
320 | mSoundAssetID(), | ||
321 | mFlags(0x0) | ||
322 | { } | ||
323 | |||
324 | LLGestureStepSound::~LLGestureStepSound() | ||
325 | { } | ||
326 | |||
327 | S32 LLGestureStepSound::getMaxSerialSize() const | ||
328 | { | ||
329 | S32 max_size = 0; | ||
330 | max_size += 256; // sound name | ||
331 | max_size += 64; // sound asset id | ||
332 | max_size += 64; // flags | ||
333 | /* binary | ||
334 | max_size += mSoundName.length() + 1; | ||
335 | max_size += sizeof(mSoundAssetID); | ||
336 | max_size += sizeof(mFlags); | ||
337 | */ | ||
338 | return max_size; | ||
339 | } | ||
340 | |||
341 | BOOL LLGestureStepSound::serialize(LLDataPacker& dp) const | ||
342 | { | ||
343 | dp.packString(mSoundName.c_str(), "sound_name"); | ||
344 | dp.packUUID(mSoundAssetID, "asset_id"); | ||
345 | dp.packU32(mFlags, "flags"); | ||
346 | return TRUE; | ||
347 | } | ||
348 | |||
349 | BOOL LLGestureStepSound::deserialize(LLDataPacker& dp) | ||
350 | { | ||
351 | dp.unpackString(mSoundName, "sound_name"); | ||
352 | |||
353 | dp.unpackUUID(mSoundAssetID, "asset_id"); | ||
354 | dp.unpackU32(mFlags, "flags"); | ||
355 | return TRUE; | ||
356 | } | ||
357 | |||
358 | std::string LLGestureStepSound::getLabel() const | ||
359 | { | ||
360 | std::string label("Sound: "); | ||
361 | label += mSoundName; | ||
362 | return label; | ||
363 | } | ||
364 | |||
365 | void LLGestureStepSound::dump() | ||
366 | { | ||
367 | llinfos << "step sound " << mSoundName | ||
368 | << " id " << mSoundAssetID | ||
369 | << " flags " << mFlags | ||
370 | << llendl; | ||
371 | } | ||
372 | |||
373 | |||
374 | //--------------------------------------------------------------------------- | ||
375 | // LLGestureStepChat | ||
376 | //--------------------------------------------------------------------------- | ||
377 | LLGestureStepChat::LLGestureStepChat() | ||
378 | : LLGestureStep(), | ||
379 | mChatText(), | ||
380 | mFlags(0x0) | ||
381 | { } | ||
382 | |||
383 | LLGestureStepChat::~LLGestureStepChat() | ||
384 | { } | ||
385 | |||
386 | S32 LLGestureStepChat::getMaxSerialSize() const | ||
387 | { | ||
388 | S32 max_size = 0; | ||
389 | max_size += 256; // chat text | ||
390 | max_size += 64; // flags | ||
391 | /* binary | ||
392 | max_size += mChatText.length() + 1; | ||
393 | max_size += sizeof(mFlags); | ||
394 | */ | ||
395 | return max_size; | ||
396 | } | ||
397 | |||
398 | BOOL LLGestureStepChat::serialize(LLDataPacker& dp) const | ||
399 | { | ||
400 | dp.packString(mChatText.c_str(), "chat_text"); | ||
401 | dp.packU32(mFlags, "flags"); | ||
402 | return TRUE; | ||
403 | } | ||
404 | |||
405 | BOOL LLGestureStepChat::deserialize(LLDataPacker& dp) | ||
406 | { | ||
407 | dp.unpackString(mChatText, "chat_text"); | ||
408 | |||
409 | dp.unpackU32(mFlags, "flags"); | ||
410 | return TRUE; | ||
411 | } | ||
412 | |||
413 | std::string LLGestureStepChat::getLabel() const | ||
414 | { | ||
415 | std::string label("Chat: "); | ||
416 | label += mChatText; | ||
417 | return label; | ||
418 | } | ||
419 | |||
420 | void LLGestureStepChat::dump() | ||
421 | { | ||
422 | llinfos << "step chat " << mChatText | ||
423 | << " flags " << mFlags | ||
424 | << llendl; | ||
425 | } | ||
426 | |||
427 | |||
428 | //--------------------------------------------------------------------------- | ||
429 | // LLGestureStepWait | ||
430 | //--------------------------------------------------------------------------- | ||
431 | LLGestureStepWait::LLGestureStepWait() | ||
432 | : LLGestureStep(), | ||
433 | mWaitSeconds(0.f), | ||
434 | mFlags(0x0) | ||
435 | { } | ||
436 | |||
437 | LLGestureStepWait::~LLGestureStepWait() | ||
438 | { } | ||
439 | |||
440 | S32 LLGestureStepWait::getMaxSerialSize() const | ||
441 | { | ||
442 | S32 max_size = 0; | ||
443 | max_size += 64; // wait seconds | ||
444 | max_size += 64; // flags | ||
445 | /* binary | ||
446 | max_size += sizeof(mWaitSeconds); | ||
447 | max_size += sizeof(mFlags); | ||
448 | */ | ||
449 | return max_size; | ||
450 | } | ||
451 | |||
452 | BOOL LLGestureStepWait::serialize(LLDataPacker& dp) const | ||
453 | { | ||
454 | dp.packF32(mWaitSeconds, "wait_seconds"); | ||
455 | dp.packU32(mFlags, "flags"); | ||
456 | return TRUE; | ||
457 | } | ||
458 | |||
459 | BOOL LLGestureStepWait::deserialize(LLDataPacker& dp) | ||
460 | { | ||
461 | dp.unpackF32(mWaitSeconds, "wait_seconds"); | ||
462 | dp.unpackU32(mFlags, "flags"); | ||
463 | return TRUE; | ||
464 | } | ||
465 | |||
466 | std::string LLGestureStepWait::getLabel() const | ||
467 | { | ||
468 | std::string label("--- Wait: "); | ||
469 | if (mFlags & WAIT_FLAG_TIME) | ||
470 | { | ||
471 | char buffer[64]; /* Flawfinder: ignore */ | ||
472 | snprintf(buffer, sizeof(buffer), "%.1f seconds", (double)mWaitSeconds); /* Flawfinder: ignore */ | ||
473 | label += buffer; | ||
474 | } | ||
475 | else if (mFlags & WAIT_FLAG_ALL_ANIM) | ||
476 | { | ||
477 | label += "until animations are done"; | ||
478 | } | ||
479 | |||
480 | return label; | ||
481 | } | ||
482 | |||
483 | |||
484 | void LLGestureStepWait::dump() | ||
485 | { | ||
486 | llinfos << "step wait " << mWaitSeconds | ||
487 | << " flags " << mFlags | ||
488 | << llendl; | ||
489 | } | ||