llappearancemgr.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /**
  2. * @file llappearancemgr.h
  3. * @brief Manager for initiating appearance changes on the viewer
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, 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
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLAPPEARANCEMGR_H
  33. #define LL_LLAPPEARANCEMGR_H
  34. #include "llframetimer.h"
  35. #include "llhttpretrypolicy.h"
  36. #include "llpointer.h"
  37. #include "lluuid.h"
  38. #include "llinventorymodel.h"
  39. #include "llviewerinventory.h"
  40. #include "llviewerwearable.h"
  41. class LLViewerJointAttachment;
  42. class LLWearableHoldingPattern;
  43. //-----------------------------------------------------------------------------
  44. // Misc callbacks and callback data structures
  45. //-----------------------------------------------------------------------------
  46. class LLWearOnAvatarCallback : public LLInventoryCallback
  47. {
  48. protected:
  49. LOG_CLASS(LLWearOnAvatarCallback);
  50. public:
  51. LLWearOnAvatarCallback(bool do_replace = true)
  52. : mReplace(do_replace)
  53. {
  54. // *TODO: track callbacks by (original) item UUID
  55. ++sPendingCallbackCount;
  56. mCounterGeneration = sCurrentCounterGeneration;
  57. }
  58. void fire(const LLUUID& inv_item);
  59. static bool pendingCallbacks() { return sPendingCallbackCount > 0; }
  60. static void resetPendingCallbacks() { sPendingCallbackCount = 0; ++sCurrentCounterGeneration; }
  61. protected:
  62. bool mReplace;
  63. private:
  64. U32 mCounterGeneration;
  65. static U32 sCurrentCounterGeneration;
  66. static U32 sPendingCallbackCount;
  67. };
  68. class LLRezAttachmentCallback : public LLInventoryCallback
  69. {
  70. protected:
  71. LOG_CLASS(LLRezAttachmentCallback);
  72. public:
  73. LLRezAttachmentCallback(LLViewerJointAttachment* attachmentp,
  74. bool replace = false)
  75. : mAttach(attachmentp),
  76. mReplace(replace)
  77. {
  78. // *TODO: track callbacks by (original) item UUID
  79. ++sPendingCallbackCount;
  80. mCounterGeneration = sCurrentCounterGeneration;
  81. }
  82. void fire(const LLUUID& inv_item);
  83. static bool pendingCallbacks() { return sPendingCallbackCount > 0; }
  84. static void resetPendingCallbacks() { sPendingCallbackCount = 0; ++sCurrentCounterGeneration; }
  85. protected:
  86. ~LLRezAttachmentCallback() {}
  87. private:
  88. LLViewerJointAttachment* mAttach;
  89. bool mReplace;
  90. U32 mCounterGeneration;
  91. static U32 sCurrentCounterGeneration;
  92. static U32 sPendingCallbackCount;
  93. };
  94. struct OnWearStruct
  95. {
  96. OnWearStruct(const LLUUID& uuid, bool replace = true)
  97. : mUUID(uuid),
  98. mReplace(replace)
  99. {
  100. }
  101. LLUUID mUUID;
  102. bool mReplace;
  103. };
  104. struct OnRemoveStruct
  105. {
  106. OnRemoveStruct(const LLUUID& uuid)
  107. : mUUID(uuid)
  108. {
  109. }
  110. LLUUID mUUID;
  111. };
  112. //-----------------------------------------------------------------------------
  113. class LLAppearanceMgr
  114. {
  115. protected:
  116. LOG_CLASS(LLAppearanceMgr);
  117. public:
  118. LLAppearanceMgr()
  119. : mNeedsSyncAttachments(false),
  120. mNeedsSyncWearables(false),
  121. mForceServerSideRebake(false),
  122. mRebaking(true),
  123. mIsRestoringInitialOutfit(true),
  124. mOutfitRestorationRetried(false),
  125. mBakeRequestSent(false),
  126. mRestorationRetryDelayDelta(0),
  127. mLoadingNotificationID(LLUUID::null)
  128. {
  129. }
  130. typedef std::vector<LLInventoryModel::item_array_t> wearables_by_type_t;
  131. void wearOutfitByName(const std::string& name);
  132. void wearInventoryItemOnAvatar(LLInventoryItem* item, bool replace = true);
  133. void wearInventoryCategory(LLInventoryCategory* category,
  134. bool copy, bool append);
  135. void wearInventoryCategoryOnAvatar(LLInventoryCategory* category,
  136. bool append, bool replace = false);
  137. void removeInventoryCategoryFromAvatar(LLInventoryCategory* category);
  138. bool wearItemOnAvatar(const LLUUID& item_id_to_wear, bool replace = true);
  139. #if 0 // Not used for now
  140. bool canAddWearables(const uuid_vec_t& item_ids);
  141. #endif
  142. void rezAttachment(LLViewerInventoryItem* item,
  143. LLViewerJointAttachment* attachment,
  144. bool replace = false);
  145. void checkOutfit(); // periodic outfit checking and syncing
  146. LL_INLINE bool isRestoringInitialOutfit() { return mIsRestoringInitialOutfit; }
  147. LL_INLINE void resetCOFUpdateTimer() { mUpdateCOFTimer.reset(); }
  148. static void sortItemsByActualDescription(LLInventoryModel::item_array_t& items);
  149. // Check ordering information on wearables stored in links' descriptions
  150. // and update if it is invalid
  151. void updateClothingOrderingInfo(LLUUID cat_id);
  152. static const LLUUID getCOF(bool create = false);
  153. S32 getCOFVersion() const;
  154. void updateCOF() const;
  155. void requestServerAppearanceUpdate();
  156. void incrementCofVersion();
  157. bool isAvatarFullyBaked() const;
  158. void setRebaking(bool rebaking = true);
  159. LL_INLINE bool isRebaking() { return mRebaking; }
  160. private:
  161. typedef enum e_restore_outfit_status {
  162. RETRY,
  163. FAILED,
  164. INCOMPLETE,
  165. DONE
  166. } ERestoreOutfitStatus;
  167. // Remove worn items not listed in outfit.xml
  168. void removeNonMatchingItems();
  169. // Try and restore outfit from outfit.xml
  170. ERestoreOutfitStatus restoreOutfit(bool can_retry);
  171. // Save the current outfit to outfit.xml
  172. void saveOutfit();
  173. // COF stuff...
  174. // <rant>Lindens be damned for this ugly COF concept !!!</rant>
  175. ERestoreOutfitStatus restoreOutfitFromCOF(bool can_retry);
  176. void cleanupCOF(const LLUUID& cof);
  177. void syncAttachmentLinksInCOF();
  178. void syncWearableLinksInCOF();
  179. void slamCOF();
  180. void getDescendentsOfAssetType(const LLUUID& category,
  181. LLInventoryModel::item_array_t& items,
  182. LLAssetType::EType type);
  183. void getDescendentsOfWearableTypes(const LLUUID& category,
  184. LLInventoryModel::item_array_t& items);
  185. void getUserDescendents(const LLUUID& category,
  186. LLInventoryModel::item_array_t& wear_items,
  187. LLInventoryModel::item_array_t& obj_items,
  188. LLInventoryModel::item_array_t& gest_items);
  189. void serverAppearanceUpdateSuccess(const LLSD& result);
  190. void serverAppearanceUpdateFailure(const LLSD& http_results);
  191. // Detach all attachments not in keep_these list; when erase_worn is true,
  192. // worn attachments UUIDs are removed from keep_these as well.
  193. static void detachExtraAttachments(uuid_list_t& keep_these,
  194. bool erase_worn = false);
  195. static void wearInventoryCategoryOnAvatarStep2(bool proceed, void* data);
  196. static void wearInventoryCategoryOnAvatarStep3(LLWearableHoldingPattern* holder);
  197. static void onWearableAssetFetch(LLViewerWearable* wearable, void* data);
  198. static void removeInventoryCategoryFromAvatarStep2(bool proceed, void* data);
  199. static bool onSetWearableDialog(const LLSD& notification,
  200. const LLSD& response,
  201. LLViewerWearable* old_wearable);
  202. private:
  203. U32 mRestorationRetryDelayDelta;
  204. LLUUID mLoadingNotificationID;
  205. LLPointer<LLHTTPRetryPolicy> mBakeRetryPolicy;
  206. LLFrameTimer mUpdateCOFTimer;
  207. bool mIsRestoringInitialOutfit;
  208. bool mOutfitRestorationRetried;
  209. bool mBakeRequestSent;
  210. bool mRebaking;
  211. public:
  212. bool mNeedsSyncAttachments;
  213. bool mNeedsSyncWearables;
  214. bool mForceServerSideRebake;
  215. };
  216. extern LLAppearanceMgr gAppearanceMgr;
  217. std::string build_order_string(LLWearableType::EType type, U32 i);
  218. #endif