forked from siana/SingularityViewer
/
llappearancemgr.cpp
4932 lines (4381 loc) · 155 KB
/
llappearancemgr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file llappearancemgr.cpp
* @brief Manager for initiating appearance changes on the viewer
*
* $LicenseInfo:firstyear=2004&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include <boost/lexical_cast.hpp>
#include "llagent.h"
#include "llagentcamera.h"
#include "llagentwearables.h"
#include "llappearancemgr.h"
#include "llattachmentsmgr.h"
#include "llcommandhandler.h"
#include "lleventtimer.h"
#include "llfloatercustomize.h"
#include "llgesturemgr.h"
#include "llinventorybridge.h"
#include "llinventoryfunctions.h"
#include "llinventoryobserver.h"
#include "llnotificationsutil.h"
#include "lloutfitobserver.h"
//#include "lloutfitslist.h"
#include "llselectmgr.h"
//#include "llsidepanelappearance.h"
#include "llviewerobjectlist.h"
#include "llvoavatar.h"
#include "llvoavatarself.h"
#include "llviewerregion.h"
#include "llviewerstats.h"
#include "llwearablelist.h"
#include "llsdutil.h"
#include "llhttpretrypolicy.h"
#include "llaisapi.h"
#include "llinventorypanel.h"
// [RLVa:KB] - Checked: 2011-05-22 (RLVa-1.3.1)
#include "rlvhandler.h"
#include "rlvhelper.h"
#include "rlvlocks.h"
// [/RLVa:KB]
std::string self_av_string()
{
// On logout gAgentAvatarp can already be invalid
return isAgentAvatarValid() ? gAgentAvatarp->avString() : "";
}
// RAII thingy to guarantee that a variable gets reset when the Setter
// goes out of scope. More general utility would be handy - TODO:
// check boost.
class BoolSetter
{
public:
BoolSetter(bool& var):
mVar(var)
{
mVar = true;
}
~BoolSetter()
{
mVar = false;
}
private:
bool& mVar;
};
char ORDER_NUMBER_SEPARATOR('@');
class LLOutfitUnLockTimer: public LLEventTimer
{
public:
LLOutfitUnLockTimer(F32 period) : LLEventTimer(period)
{
// restart timer on BOF changed event
LLOutfitObserver::instance().addBOFChangedCallback(boost::bind(
&LLOutfitUnLockTimer::reset, this));
stop();
}
/*virtual*/
BOOL tick()
{
if(mEventTimer.hasExpired())
{
LLAppearanceMgr::instance().setOutfitLocked(false);
}
return FALSE;
}
void stop() { mEventTimer.stop(); }
void start() { mEventTimer.start(); }
void reset() { mEventTimer.reset(); }
BOOL getStarted() { return mEventTimer.getStarted(); }
LLTimer& getEventTimer() { return mEventTimer;}
};
// support for secondlife:///app/appearance SLapps
class LLAppearanceHandler : public LLCommandHandler
{
public:
// requests will be throttled from a non-trusted browser
LLAppearanceHandler() : LLCommandHandler("appearance", UNTRUSTED_THROTTLE) {}
bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
{
/* Singu Note: Nopenopenope.
// support secondlife:///app/appearance/show, but for now we just
// make all secondlife:///app/appearance SLapps behave this way
if (!LLUI::sSettingGroups["config"]->getBOOL("EnableAppearance"))
{
LLNotificationsUtil::add("NoAppearance", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
return true;
}
*/
LLFloaterCustomize::getInstance()->open();
return true;
}
};
LLAppearanceHandler gAppearanceHandler;
LLUUID findDescendentCategoryIDByName(const LLUUID& parent_id, const std::string& name)
{
LLInventoryModel::cat_array_t cat_array;
LLInventoryModel::item_array_t item_array;
LLNameCategoryCollector has_name(name);
gInventory.collectDescendentsIf(parent_id,
cat_array,
item_array,
LLInventoryModel::EXCLUDE_TRASH,
has_name);
if (0 == cat_array.size())
return LLUUID();
else
{
LLViewerInventoryCategory *cat = cat_array.at(0);
if (cat)
return cat->getUUID();
else
{
LL_WARNS() << "null cat" << LL_ENDL;
return LLUUID();
}
}
}
// We want this to be much lower (e.g. 15.0 is usually fine), bumping
// up for now until we can diagnose some cases of very slow response
// to requests.
const F32 DEFAULT_RETRY_AFTER_INTERVAL = 300.0;
// Given the current back-end problems, retrying is causing too many
// duplicate items. Bump this back to 2 once they are resolved (or can
// leave at 0 if the operations become actually reliable).
const S32 DEFAULT_MAX_RETRIES = 0;
class LLCallAfterInventoryBatchMgr: public LLEventTimer
{
public:
LLCallAfterInventoryBatchMgr(const LLUUID& dst_cat_id,
const std::string& phase_name,
nullary_func_t on_completion_func,
nullary_func_t on_failure_func = no_op,
F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
S32 max_retries = DEFAULT_MAX_RETRIES
):
mDstCatID(dst_cat_id),
mTrackingPhase(phase_name),
mOnCompletionFunc(on_completion_func),
mOnFailureFunc(on_failure_func),
mRetryAfter(retry_after),
mMaxRetries(max_retries),
mPendingRequests(0),
mFailCount(0),
mCompletionOrFailureCalled(false),
mRetryCount(0),
LLEventTimer(5.0)
{
if (!mTrackingPhase.empty())
{
selfStartPhase(mTrackingPhase);
}
}
void addItems(LLInventoryModel::item_array_t& src_items)
{
for (LLInventoryModel::item_array_t::const_iterator it = src_items.begin();
it != src_items.end();
++it)
{
LLViewerInventoryItem* item = *it;
llassert(item);
addItem(item->getUUID());
}
}
// Request or re-request operation for specified item.
void addItem(const LLUUID& item_id)
{
LL_DEBUGS("Avatar") << "item_id " << item_id << LL_ENDL;
if (!requestOperation(item_id))
{
LL_DEBUGS("Avatar") << "item_id " << item_id << " requestOperation false, skipping" << LL_ENDL;
return;
}
mPendingRequests++;
// On a re-request, this will reset the timer.
mWaitTimes[item_id] = LLTimer();
if (mRetryCounts.find(item_id) == mRetryCounts.end())
{
mRetryCounts[item_id] = 0;
}
else
{
mRetryCounts[item_id]++;
}
}
virtual bool requestOperation(const LLUUID& item_id) = 0;
void onOp(const LLUUID& src_id, const LLUUID& dst_id, LLTimer timestamp)
{
if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateLateOpRate"))
{
LL_WARNS() << "Simulating late operation by punting handling to later" << LL_ENDL;
doAfterInterval(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,src_id,dst_id,timestamp),
mRetryAfter);
return;
}
mPendingRequests--;
F32 elapsed = timestamp.getElapsedTimeF32();
LL_DEBUGS("Avatar") << "op done, src_id " << src_id << " dst_id " << dst_id << " after " << elapsed << " seconds" << LL_ENDL;
if (mWaitTimes.find(src_id) == mWaitTimes.end())
{
// No longer waiting for this item - either serviced
// already or gave up after too many retries.
LL_WARNS() << "duplicate or late operation, src_id " << src_id << "dst_id " << dst_id
<< " elapsed " << elapsed << " after end " << (S32) mCompletionOrFailureCalled << LL_ENDL;
}
mTimeStats.push(elapsed);
mWaitTimes.erase(src_id);
if (mWaitTimes.empty() && !mCompletionOrFailureCalled)
{
onCompletionOrFailure();
}
}
void onCompletionOrFailure()
{
assert (!mCompletionOrFailureCalled);
mCompletionOrFailureCalled = true;
// Will never call onCompletion() if any item has been flagged as
// a failure - otherwise could wind up with corrupted
// outfit, involuntary nudity, etc.
reportStats();
if (!mTrackingPhase.empty())
{
selfStopPhase(mTrackingPhase);
}
if (!mFailCount)
{
onCompletion();
}
else
{
onFailure();
}
}
void onFailure()
{
LL_INFOS() << "failed" << LL_ENDL;
mOnFailureFunc();
}
void onCompletion()
{
LL_INFOS() << "done" << LL_ENDL;
mOnCompletionFunc();
}
// virtual
// Will be deleted after returning true - only safe to do this if all callbacks have fired.
BOOL tick()
{
// mPendingRequests will be zero if all requests have been
// responded to. mWaitTimes.empty() will be true if we have
// received at least one reply for each UUID. If requests
// have been dropped and retried, these will not necessarily
// be the same. Only safe to return true if all requests have
// been serviced, since it will result in this object being
// deleted.
bool all_done = (mPendingRequests==0);
if (!mWaitTimes.empty())
{
LL_WARNS() << "still waiting on " << mWaitTimes.size() << " items" << LL_ENDL;
for (std::map<LLUUID,LLTimer>::iterator it = mWaitTimes.begin();
it != mWaitTimes.end();)
{
// Use a copy of iterator because it may be erased/invalidated.
std::map<LLUUID,LLTimer>::iterator curr_it = it;
++it;
F32 time_waited = curr_it->second.getElapsedTimeF32();
S32 retries = mRetryCounts[curr_it->first];
if (time_waited > mRetryAfter)
{
if (retries < mMaxRetries)
{
LL_DEBUGS("Avatar") << "Waited " << time_waited <<
" for " << curr_it->first << ", retrying" << LL_ENDL;
mRetryCount++;
addItem(curr_it->first);
}
else
{
LL_WARNS() << "Giving up on " << curr_it->first << " after too many retries" << LL_ENDL;
mWaitTimes.erase(curr_it);
mFailCount++;
}
}
if (mWaitTimes.empty())
{
onCompletionOrFailure();
}
}
}
return all_done;
}
void reportStats()
{
LL_DEBUGS("Avatar") << "Phase: " << mTrackingPhase << LL_ENDL;
LL_DEBUGS("Avatar") << "mFailCount: " << mFailCount << LL_ENDL;
LL_DEBUGS("Avatar") << "mRetryCount: " << mRetryCount << LL_ENDL;
LL_DEBUGS("Avatar") << "Times: n " << mTimeStats.getCount() << " min " << mTimeStats.getMinValue() << " max " << mTimeStats.getMaxValue() << LL_ENDL;
LL_DEBUGS("Avatar") << "Mean " << mTimeStats.getMean() << " stddev " << mTimeStats.getStdDev() << LL_ENDL;
}
virtual ~LLCallAfterInventoryBatchMgr()
{
LL_DEBUGS("Avatar") << "deleting" << LL_ENDL;
}
protected:
std::string mTrackingPhase;
std::map<LLUUID,LLTimer> mWaitTimes;
std::map<LLUUID,S32> mRetryCounts;
LLUUID mDstCatID;
nullary_func_t mOnCompletionFunc;
nullary_func_t mOnFailureFunc;
F32 mRetryAfter;
S32 mMaxRetries;
S32 mPendingRequests;
S32 mFailCount;
S32 mRetryCount;
bool mCompletionOrFailureCalled;
LLViewerStats::StatsAccumulator mTimeStats;
};
class LLCallAfterInventoryCopyMgr: public LLCallAfterInventoryBatchMgr
{
public:
LLCallAfterInventoryCopyMgr(LLInventoryModel::item_array_t& src_items,
const LLUUID& dst_cat_id,
const std::string& phase_name,
nullary_func_t on_completion_func,
nullary_func_t on_failure_func = no_op,
F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
S32 max_retries = DEFAULT_MAX_RETRIES
):
LLCallAfterInventoryBatchMgr(dst_cat_id, phase_name, on_completion_func, on_failure_func, retry_after, max_retries)
{
addItems(src_items);
sInstanceCount++;
}
~LLCallAfterInventoryCopyMgr()
{
sInstanceCount--;
}
virtual bool requestOperation(const LLUUID& item_id)
{
LLViewerInventoryItem *item = gInventory.getItem(item_id);
llassert(item);
LL_DEBUGS("Avatar") << "copying item " << item_id << LL_ENDL;
if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateOpFailureRate"))
{
LL_DEBUGS("Avatar") << "simulating failure by not sending request for item " << item_id << LL_ENDL;
return true;
}
copy_inventory_item(
gAgent.getID(),
item->getPermissions().getOwner(),
item->getUUID(),
mDstCatID,
std::string(),
new LLBoostFuncInventoryCallback(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,item_id,_1,LLTimer()))
);
return true;
}
static S32 getInstanceCount() { return sInstanceCount; }
private:
static S32 sInstanceCount;
};
S32 LLCallAfterInventoryCopyMgr::sInstanceCount = 0;
class LLWearCategoryAfterCopy: public LLInventoryCallback
{
public:
LLWearCategoryAfterCopy(bool append):
mAppend(append)
{}
// virtual
void fire(const LLUUID& id)
{
// Wear the inventory category.
LLInventoryCategory* cat = gInventory.getCategory(id);
LLAppearanceMgr::instance().wearInventoryCategoryOnAvatar(cat, mAppend);
}
private:
bool mAppend;
};
class LLTrackPhaseWrapper : public LLInventoryCallback
{
public:
LLTrackPhaseWrapper(const std::string& phase_name, LLPointer<LLInventoryCallback> cb = nullptr):
mTrackingPhase(phase_name),
mCB(cb)
{
selfStartPhase(mTrackingPhase);
}
// virtual
void fire(const LLUUID& id)
{
if (mCB)
{
mCB->fire(id);
}
}
// virtual
~LLTrackPhaseWrapper()
{
selfStopPhase(mTrackingPhase);
}
protected:
std::string mTrackingPhase;
LLPointer<LLInventoryCallback> mCB;
};
LLUpdateAppearanceOnDestroy::LLUpdateAppearanceOnDestroy(bool enforce_item_restrictions,
bool enforce_ordering,
nullary_func_t post_update_func
):
mFireCount(0),
mEnforceItemRestrictions(enforce_item_restrictions),
mEnforceOrdering(enforce_ordering),
mPostUpdateFunc(post_update_func)
{
sActiveCallbacks++;
selfStartPhase("update_appearance_on_destroy");
}
void LLUpdateAppearanceOnDestroy::fire(const LLUUID& inv_item)
{
LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(inv_item);
const std::string item_name = item ? item->getName() : "ITEM NOT FOUND";
#ifndef LL_RELEASE_FOR_DOWNLOAD
LL_DEBUGS("Avatar") << self_av_string() << "callback fired [ name:" << item_name << " UUID:" << inv_item << " count:" << mFireCount << " ] " << LL_ENDL;
#endif
mFireCount++;
}
LLUpdateAppearanceOnDestroy::~LLUpdateAppearanceOnDestroy()
{
--sActiveCallbacks;
if (!LLApp::isExiting())
{
// speculative fix for MAINT-1150
LL_INFOS("Avatar") << self_av_string() << "done update appearance on destroy" << LL_ENDL;
selfStopPhase("update_appearance_on_destroy");
LLAppearanceMgr::instance().updateAppearanceFromCOF(mEnforceItemRestrictions,
mEnforceOrdering,
mPostUpdateFunc);
}
}
U32 LLUpdateAppearanceOnDestroy::sActiveCallbacks = 0;
LLUpdateAppearanceAndEditWearableOnDestroy::LLUpdateAppearanceAndEditWearableOnDestroy(const LLUUID& item_id):
mItemID(item_id)
{
}
LLRequestServerAppearanceUpdateOnDestroy::~LLRequestServerAppearanceUpdateOnDestroy()
{
LL_DEBUGS("Avatar") << "ATT requesting server appearance update" << LL_ENDL;
if (!LLApp::isExiting())
{
LLAppearanceMgr::instance().requestServerAppearanceUpdate();
}
}
void edit_wearable_and_customize_avatar(LLUUID item_id)
{
// Start editing the item if previously requested.
gAgentWearables.editWearableIfRequested(item_id);
// TODO: camera mode may not be changed if a debug setting is tweaked
if( LLFloaterCustomize::instanceExists() )
{
// If we're in appearance editing mode, the current tab may need to be refreshed
LLFloaterCustomize::getInstance()->switchToDefaultSubpart();
}
}
LLUpdateAppearanceAndEditWearableOnDestroy::~LLUpdateAppearanceAndEditWearableOnDestroy()
{
if (!LLApp::isExiting())
{
LLAppearanceMgr::instance().updateAppearanceFromCOF(
true,true,
boost::bind(edit_wearable_and_customize_avatar, mItemID));
}
}
struct LLFoundData
{
LLFoundData() :
mAssetType(LLAssetType::AT_NONE),
mWearableType(LLWearableType::WT_INVALID),
mWearable(NULL) {}
LLFoundData(const LLUUID& item_id,
const LLUUID& asset_id,
const std::string& name,
const LLAssetType::EType& asset_type,
const LLWearableType::EType& wearable_type,
const bool is_replacement = false
) :
mItemID(item_id),
mAssetID(asset_id),
mName(name),
mAssetType(asset_type),
mWearableType(wearable_type),
mIsReplacement(is_replacement),
mWearable( NULL ) {}
LLUUID mItemID;
LLUUID mAssetID;
std::string mName;
LLAssetType::EType mAssetType;
LLWearableType::EType mWearableType;
LLViewerWearable* mWearable;
bool mIsReplacement;
};
class LLWearableHoldingPattern
{
LOG_CLASS(LLWearableHoldingPattern);
public:
LLWearableHoldingPattern();
~LLWearableHoldingPattern();
bool pollFetchCompletion();
void onFetchCompletion();
bool isFetchCompleted();
bool isTimedOut();
void checkMissingWearables();
bool pollMissingWearables();
bool isMissingCompleted();
void recoverMissingWearable(LLWearableType::EType type);
// void clearCOFLinksForMissingWearables();
void onWearableAssetFetch(LLViewerWearable *wearable);
void onAllComplete();
// [SL:KB] - Patch: Appearance-COFCorruption | Checked: 2010-04-14 (Catznip-2.0)
bool pollStopped();
// [/SL:KB]
typedef std::list<LLFoundData> found_list_t;
found_list_t& getFoundList();
void eraseTypeToLink(LLWearableType::EType type);
void eraseTypeToRecover(LLWearableType::EType type);
// void setObjItems(const LLInventoryModel::item_array_t& items);
void setGestItems(const LLInventoryModel::item_array_t& items);
bool isMostRecent();
void handleLateArrivals();
void resetTime(F32 timeout);
static S32 countActive() { return sActiveHoldingPatterns.size(); }
S32 index() { return mIndex; }
private:
found_list_t mFoundList;
// LLInventoryModel::item_array_t mObjItems;
LLInventoryModel::item_array_t mGestItems;
typedef std::set<S32> type_set_t;
type_set_t mTypesToRecover;
type_set_t mTypesToLink;
S32 mResolved;
LLTimer mWaitTime;
bool mFired;
typedef std::set<LLWearableHoldingPattern*> type_set_hp;
static type_set_hp sActiveHoldingPatterns;
static S32 sNextIndex;
S32 mIndex;
bool mIsMostRecent;
std::set<LLViewerWearable*> mLateArrivals;
bool mIsAllComplete;
};
LLWearableHoldingPattern::type_set_hp LLWearableHoldingPattern::sActiveHoldingPatterns;
S32 LLWearableHoldingPattern::sNextIndex = 0;
LLWearableHoldingPattern::LLWearableHoldingPattern():
mResolved(0),
mFired(false),
mIsMostRecent(true),
mIsAllComplete(false)
{
if (countActive()>0)
{
LL_INFOS() << "Creating LLWearableHoldingPattern when "
<< countActive()
<< " other attempts are active."
<< " Flagging others as invalid."
<< LL_ENDL;
for (type_set_hp::iterator it = sActiveHoldingPatterns.begin();
it != sActiveHoldingPatterns.end();
++it)
{
(*it)->mIsMostRecent = false;
}
}
mIndex = sNextIndex++;
sActiveHoldingPatterns.insert(this);
LL_DEBUGS("Avatar") << "HP " << index() << " created" << LL_ENDL;
selfStartPhase("holding_pattern");
}
LLWearableHoldingPattern::~LLWearableHoldingPattern()
{
sActiveHoldingPatterns.erase(this);
if (isMostRecent())
{
selfStopPhase("holding_pattern");
}
LL_DEBUGS("Avatar") << "HP " << index() << " deleted" << LL_ENDL;
}
bool LLWearableHoldingPattern::isMostRecent()
{
return mIsMostRecent;
}
LLWearableHoldingPattern::found_list_t& LLWearableHoldingPattern::getFoundList()
{
return mFoundList;
}
void LLWearableHoldingPattern::eraseTypeToLink(LLWearableType::EType type)
{
mTypesToLink.erase(type);
}
void LLWearableHoldingPattern::eraseTypeToRecover(LLWearableType::EType type)
{
mTypesToRecover.erase(type);
}
// [SL:KB] - Patch: Appearance-SyncAttach | Checked: 2010-06-19 (Catznip-2.1)
//void LLWearableHoldingPattern::setObjItems(const LLInventoryModel::item_array_t& items)
//{
// mObjItems = items;
//}
void LLWearableHoldingPattern::setGestItems(const LLInventoryModel::item_array_t& items)
{
mGestItems = items;
}
bool LLWearableHoldingPattern::isFetchCompleted()
{
return (mResolved >= (S32)getFoundList().size()); // have everything we were waiting for?
}
bool LLWearableHoldingPattern::isTimedOut()
{
return mWaitTime.hasExpired();
}
void LLWearableHoldingPattern::checkMissingWearables()
{
if (!isMostRecent())
{
// runway why don't we actually skip here?
LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
}
std::vector<S32> found_by_type(LLWearableType::WT_COUNT,0);
std::vector<S32> requested_by_type(LLWearableType::WT_COUNT,0);
for (found_list_t::iterator it = getFoundList().begin(); it != getFoundList().end(); ++it)
{
LLFoundData &data = *it;
if (data.mWearableType < LLWearableType::WT_COUNT)
requested_by_type[data.mWearableType]++;
if (data.mWearable)
found_by_type[data.mWearableType]++;
}
for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
{
if (requested_by_type[type] > found_by_type[type])
{
LL_WARNS() << self_av_string() << "got fewer wearables than requested, type " << type << ": requested " << requested_by_type[type] << ", found " << found_by_type[type] << LL_ENDL;
}
if (found_by_type[type] > 0)
continue;
if (
// If at least one wearable of certain types (pants/shirt/skirt)
// was requested but none was found, create a default asset as a replacement.
// In all other cases, don't do anything.
// For critical types (shape/hair/skin/eyes), this will keep the avatar as a cloud
// due to logic in LLVOAvatarSelf::getIsCloud().
// For non-critical types (tatoo, socks, etc.) the wearable will just be missing.
(requested_by_type[type] > 0) &&
((type == LLWearableType::WT_PANTS) || (type == LLWearableType::WT_SHIRT) || (type == LLWearableType::WT_SKIRT)))
{
mTypesToRecover.insert(type);
mTypesToLink.insert(type);
recoverMissingWearable((LLWearableType::EType)type);
LL_WARNS() << self_av_string() << "need to replace " << type << LL_ENDL;
}
}
resetTime(60.0F);
if (isMostRecent())
{
selfStartPhase("get_missing_wearables_2");
}
if (!pollMissingWearables())
{
doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollMissingWearables,this));
}
}
void LLWearableHoldingPattern::onAllComplete()
{
if (isAgentAvatarValid())
{
gAgentAvatarp->outputRezTiming("Agent wearables fetch complete");
}
if (!isMostRecent())
{
// runway need to skip here?
LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
}
// Activate all gestures in this folder
if (mGestItems.size() > 0)
{
LL_DEBUGS("Avatar") << self_av_string() << "Activating " << mGestItems.size() << " gestures" << LL_ENDL;
LLGestureMgr::instance().activateGestures(mGestItems);
// Update the inventory item labels to reflect the fact
// they are active.
LLViewerInventoryCategory* catp =
gInventory.getCategory(LLAppearanceMgr::instance().getCOF());
if (catp)
{
gInventory.updateCategory(catp);
gInventory.notifyObservers();
}
}
if (isAgentAvatarValid())
{
// LL_DEBUGS("Avatar") << self_av_string() << "Updating " << mObjItems.size() << " attachments" << LL_ENDL;
// LLAgentWearables::llvo_vec_t objects_to_remove;
// LLAgentWearables::llvo_vec_t objects_to_retain;
// LLInventoryModel::item_array_t items_to_add;
//
// LLAgentWearables::findAttachmentsAddRemoveInfo(mObjItems,
// objects_to_remove,
// objects_to_retain,
// items_to_add);
//
// LL_DEBUGS("Avatar") << self_av_string() << "Removing " << objects_to_remove.size()
// << " attachments" << LL_ENDL;
//
// // Here we remove the attachment pos overrides for *all*
// // attachments, even those that are not being removed. This is
// // needed to get joint positions all slammed down to their
// // pre-attachment states.
// gAgentAvatarp->clearAttachmentPosOverrides();
//
// if (objects_to_remove.size() || items_to_add.size())
// {
// LL_DEBUGS("Avatar") << "ATT will remove " << objects_to_remove.size()
// << " and add " << items_to_add.size() << " items" << LL_ENDL;
// }
//
// // Take off the attachments that will no longer be in the outfit.
// LLAgentWearables::userRemoveMultipleAttachments(objects_to_remove);
// Update wearables.
LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " updating agent wearables with "
<< mResolved << " wearable items " << LL_ENDL;
LLAppearanceMgr::instance().updateAgentWearables(this);
// // Restore attachment pos overrides for the attachments that
// // are remaining in the outfit.
// for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_retain.begin();
// it != objects_to_retain.end();
// ++it)
// {
// LLViewerObject *objectp = *it;
// gAgentAvatarp->addAttachmentPosOverridesForObject(objectp);
// }
// // Add new attachments to match those requested.
// LL_DEBUGS("Avatar") << self_av_string() << "Adding " << items_to_add.size() << " attachments" << LL_ENDL;
// LLAgentWearables::userAttachMultipleAttachments(items_to_add);
}
if (isFetchCompleted() && isMissingCompleted())
{
// Only safe to delete if all wearable callbacks and all missing wearables completed.
delete this;
}
else
{
mIsAllComplete = true;
handleLateArrivals();
}
}
void LLWearableHoldingPattern::onFetchCompletion()
{
if (isMostRecent())
{
selfStopPhase("get_wearables_2");
}
if (!isMostRecent())
{
// runway skip here?
LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
}
checkMissingWearables();
}
// Runs as an idle callback until all wearables are fetched (or we time out).
bool LLWearableHoldingPattern::pollFetchCompletion()
{
if (!isMostRecent())
{
// runway skip here?
LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
// [SL:KB] - Patch: Appearance-COFCorruption | Checked: 2010-04-14 (Catznip-2.0)
// If we were signalled to stop then we shouldn't do anything else except poll for when it's safe to delete ourselves
doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollStopped, this));
return true;
// [/SL:KB]
}
bool completed = isFetchCompleted();
bool timed_out = isTimedOut();
bool done = completed || timed_out;
if (done)
{
LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " polling, done status: " << completed << " timed out " << timed_out
<< " elapsed " << mWaitTime.getElapsedTimeF32() << LL_ENDL;
mFired = true;
if (timed_out)
{
LL_WARNS() << self_av_string() << "Exceeded max wait time for wearables, updating appearance based on what has arrived" << LL_ENDL;
}
onFetchCompletion();
}
return done;
}
void recovered_item_link_cb(const LLUUID& item_id, LLWearableType::EType type, LLViewerWearable *wearable, LLWearableHoldingPattern* holder)
{
if (!holder->isMostRecent())
{
LL_WARNS() << "HP " << holder->index() << " skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
// runway skip here?
}
LL_INFOS() << "HP " << holder->index() << " recovered item link for type " << type << LL_ENDL;
holder->eraseTypeToLink(type);
// Add wearable to FoundData for actual wearing
LLViewerInventoryItem *item = gInventory.getItem(item_id);
LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
if (linked_item)
{
gInventory.addChangedMask(LLInventoryObserver::LABEL, linked_item->getUUID());
if (item)
{
LLFoundData found(linked_item->getUUID(),
linked_item->getAssetUUID(),
linked_item->getName(),
linked_item->getType(),
linked_item->isWearableType() ? linked_item->getWearableType() : LLWearableType::WT_INVALID,
true // is replacement
);
found.mWearable = wearable;
holder->getFoundList().push_front(found);
}
else
{
LL_WARNS() << self_av_string() << "inventory link not found for recovered wearable" << LL_ENDL;
}
}
else
{
LL_WARNS() << self_av_string() << "HP " << holder->index() << " inventory link not found for recovered wearable" << LL_ENDL;
}
}
void recovered_item_cb(const LLUUID& item_id, LLWearableType::EType type, LLViewerWearable *wearable, LLWearableHoldingPattern* holder)
{
if (!holder->isMostRecent())
{
// runway skip here?
LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
// [SL:KB] - Patch: Appearance-COFCorruption | Checked: 2010-04-14 (Catznip-2.0)
// If we were signalled to stop then we shouldn't do anything else except poll for when it's safe to delete ourselves
return;
// [/SL:KB]
}
LL_DEBUGS("Avatar") << self_av_string() << "Recovered item for type " << type << LL_ENDL;
LLConstPointer<LLInventoryObject> itemp = gInventory.getItem(item_id);
wearable->setItemID(item_id);
holder->eraseTypeToRecover(type);
llassert(itemp);
if (itemp)
{
LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(recovered_item_link_cb,_1,type,wearable,holder));